Deleted fetch syscall (now natively supported)

pull/3/head
Zef Hemel 2022-04-21 15:29:13 +02:00
parent dad2b4e835
commit a2cb2727d2
5 changed files with 8 additions and 39 deletions

View File

@ -1,12 +0,0 @@
import { syscall } from "./syscall";
export async function json(url: RequestInfo, init: RequestInit): Promise<any> {
return syscall("fetch.json", url, init);
}
export async function text(
url: RequestInfo,
init: RequestInit = {}
): Promise<string> {
return syscall("fetch.text", url, init);
}

View File

@ -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}`);

View File

@ -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();
},
};
}

View File

@ -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<Post[]> {
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<Post[]> {
@ -117,7 +116,7 @@ class GhostAdmin {
}
async publish(what: "pages" | "posts", post: Partial<Post>): Promise<any> {
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];
}
}
}

View File

@ -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, "/_/"));