From a2cb2727d263ded5fe00b9a6a2b1aa07315ec9b2 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 21 Apr 2022 15:29:13 +0200 Subject: [PATCH] Deleted fetch syscall (now natively supported) --- packages/plugos-syscall/fetch.ts | 12 ------------ packages/plugos/bin/plugos-server.ts | 2 -- packages/plugos/syscalls/fetch.node.ts | 15 --------------- packages/plugs/ghost/ghost.ts | 16 ++++++++-------- packages/silverbullet-server/api_server.ts | 2 -- 5 files changed, 8 insertions(+), 39 deletions(-) delete mode 100644 packages/plugos-syscall/fetch.ts delete mode 100644 packages/plugos/syscalls/fetch.node.ts diff --git a/packages/plugos-syscall/fetch.ts b/packages/plugos-syscall/fetch.ts deleted file mode 100644 index ff0e14e8..00000000 --- a/packages/plugos-syscall/fetch.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { syscall } from "./syscall"; - -export async function json(url: RequestInfo, init: RequestInit): Promise { - return syscall("fetch.json", url, init); -} - -export async function text( - url: RequestInfo, - init: RequestInit = {} -): Promise { - return syscall("fetch.text", url, init); -} diff --git a/packages/plugos/bin/plugos-server.ts b/packages/plugos/bin/plugos-server.ts index f219243a..9b3fc0d6 100755 --- a/packages/plugos/bin/plugos-server.ts +++ b/packages/plugos/bin/plugos-server.ts @@ -11,7 +11,6 @@ import { EndpointHook, EndpointHookT } from "../hooks/endpoint"; import { safeRun } from "../util"; import knex from "knex"; import { ensureTable, storeSyscalls } from "../syscalls/store.knex_node"; -import { fetchSyscalls } from "../syscalls/fetch.node"; import { EventHook, EventHookT } from "../hooks/event"; import { eventSyscalls } from "../syscalls/event"; @@ -54,7 +53,6 @@ safeRun(async () => { system.registerSyscalls([], eventSyscalls(eventHook)); system.addHook(new EndpointHook(app, "")); system.registerSyscalls([], shellSyscalls(".")); - system.registerSyscalls([], fetchSyscalls()); system.registerSyscalls([], storeSyscalls(db, "item")); app.listen(args.port, () => { console.log(`Plugbox server listening on port ${args.port}`); diff --git a/packages/plugos/syscalls/fetch.node.ts b/packages/plugos/syscalls/fetch.node.ts deleted file mode 100644 index 61520e6c..00000000 --- a/packages/plugos/syscalls/fetch.node.ts +++ /dev/null @@ -1,15 +0,0 @@ -import fetch, { RequestInfo, RequestInit } from "node-fetch"; -import { SysCallMapping } from "../system"; - -export function fetchSyscalls(): SysCallMapping { - return { - "fetch.json": async (ctx, url: RequestInfo, init: RequestInit) => { - let resp = await fetch(url, init); - return resp.json(); - }, - "fetch.text": async (ctx, url: RequestInfo, init: RequestInit) => { - let resp = await fetch(url, init); - return resp.text(); - }, - }; -} diff --git a/packages/plugs/ghost/ghost.ts b/packages/plugs/ghost/ghost.ts index c5a0e308..d5946b62 100644 --- a/packages/plugs/ghost/ghost.ts +++ b/packages/plugs/ghost/ghost.ts @@ -1,5 +1,4 @@ import { readPage, writePage } from "@silverbulletmd/plugos-silverbullet-syscall/space"; -import { json } from "@silverbulletmd/plugos-syscall/fetch"; import { invokeFunction } from "@silverbulletmd/plugos-silverbullet-syscall/system"; import { getCurrentPage, getText } from "@silverbulletmd/plugos-silverbullet-syscall/editor"; import { cleanMarkdown } from "../markdown/util"; @@ -85,7 +84,7 @@ class GhostAdmin { } async listPosts(): Promise { - let result = await json( + let result = await fetch( `${this.url}/ghost/api/v3/admin/posts?order=published_at+DESC`, { headers: { @@ -94,7 +93,7 @@ class GhostAdmin { } ); - return result.posts; + return (await result.json()).posts; } async listMarkdownPosts(): Promise { @@ -117,7 +116,7 @@ class GhostAdmin { } async publish(what: "pages" | "posts", post: Partial): Promise { - let oldPostQuery = await json( + let oldPostQueryR = await fetch( `${this.url}/ghost/api/v3/admin/${what}/slug/${post.slug}`, { headers: { @@ -126,12 +125,13 @@ class GhostAdmin { }, } ); + let oldPostQuery = await oldPostQueryR.json(); if (!oldPostQuery[what]) { // New! if (!post.status) { post.status = "draft"; } - let result = await json(`${this.url}/ghost/api/v3/admin/${what}`, { + let result = await fetch(`${this.url}/ghost/api/v3/admin/${what}`, { method: "POST", headers: { Authorization: `Ghost ${this.token}`, @@ -141,11 +141,11 @@ class GhostAdmin { [what]: [post], }), }); - return result[what][0]; + return (await result.json())[what][0]; } else { let oldPost: Post = oldPostQuery[what][0]; post.updated_at = oldPost.updated_at; - let result = await json( + let result = await fetch( `${this.url}/ghost/api/v3/admin/${what}/${oldPost.id}`, { method: "PUT", @@ -158,7 +158,7 @@ class GhostAdmin { }), } ); - return result[what][0]; + return (await result.json())[what][0]; } } } diff --git a/packages/silverbullet-server/api_server.ts b/packages/silverbullet-server/api_server.ts index 925f2422..eb4a8db1 100644 --- a/packages/silverbullet-server/api_server.ts +++ b/packages/silverbullet-server/api_server.ts @@ -20,7 +20,6 @@ import { Space } from "@silverbulletmd/common/spaces/space"; import { safeRun, throttle } from "@silverbulletmd/common/util"; import { createSandbox } from "@silverbulletmd/plugos/environments/node_sandbox"; import { jwtSyscalls } from "@silverbulletmd/plugos/syscalls/jwt"; -import { fetchSyscalls } from "@silverbulletmd/plugos/syscalls/fetch.node"; import buildMarkdown from "@silverbulletmd/web/parser"; import { loadMarkdownExtensions } from "@silverbulletmd/web/markdown_ext"; @@ -69,7 +68,6 @@ export class ExpressServer { system.registerSyscalls([], spaceSyscalls(this.space)); system.registerSyscalls([], eventSyscalls(this.eventHook)); system.registerSyscalls([], markdownSyscalls(buildMarkdown([]))); - system.registerSyscalls([], fetchSyscalls()); system.registerSyscalls([], jwtSyscalls()); system.addHook(new EndpointHook(app, "/_/"));