Deleted fetch syscall (now natively supported)
parent
dad2b4e835
commit
a2cb2727d2
|
@ -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);
|
|
||||||
}
|
|
|
@ -11,7 +11,6 @@ import { EndpointHook, EndpointHookT } from "../hooks/endpoint";
|
||||||
import { safeRun } from "../util";
|
import { safeRun } from "../util";
|
||||||
import knex from "knex";
|
import knex from "knex";
|
||||||
import { ensureTable, storeSyscalls } from "../syscalls/store.knex_node";
|
import { ensureTable, storeSyscalls } from "../syscalls/store.knex_node";
|
||||||
import { fetchSyscalls } from "../syscalls/fetch.node";
|
|
||||||
import { EventHook, EventHookT } from "../hooks/event";
|
import { EventHook, EventHookT } from "../hooks/event";
|
||||||
import { eventSyscalls } from "../syscalls/event";
|
import { eventSyscalls } from "../syscalls/event";
|
||||||
|
|
||||||
|
@ -54,7 +53,6 @@ safeRun(async () => {
|
||||||
system.registerSyscalls([], eventSyscalls(eventHook));
|
system.registerSyscalls([], eventSyscalls(eventHook));
|
||||||
system.addHook(new EndpointHook(app, ""));
|
system.addHook(new EndpointHook(app, ""));
|
||||||
system.registerSyscalls([], shellSyscalls("."));
|
system.registerSyscalls([], shellSyscalls("."));
|
||||||
system.registerSyscalls([], fetchSyscalls());
|
|
||||||
system.registerSyscalls([], storeSyscalls(db, "item"));
|
system.registerSyscalls([], storeSyscalls(db, "item"));
|
||||||
app.listen(args.port, () => {
|
app.listen(args.port, () => {
|
||||||
console.log(`Plugbox server listening on port ${args.port}`);
|
console.log(`Plugbox server listening on port ${args.port}`);
|
||||||
|
|
|
@ -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();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { readPage, writePage } from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
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 { invokeFunction } from "@silverbulletmd/plugos-silverbullet-syscall/system";
|
||||||
import { getCurrentPage, getText } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
import { getCurrentPage, getText } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||||
import { cleanMarkdown } from "../markdown/util";
|
import { cleanMarkdown } from "../markdown/util";
|
||||||
|
@ -85,7 +84,7 @@ class GhostAdmin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async listPosts(): Promise<Post[]> {
|
async listPosts(): Promise<Post[]> {
|
||||||
let result = await json(
|
let result = await fetch(
|
||||||
`${this.url}/ghost/api/v3/admin/posts?order=published_at+DESC`,
|
`${this.url}/ghost/api/v3/admin/posts?order=published_at+DESC`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -94,7 +93,7 @@ class GhostAdmin {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return result.posts;
|
return (await result.json()).posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
async listMarkdownPosts(): Promise<Post[]> {
|
async listMarkdownPosts(): Promise<Post[]> {
|
||||||
|
@ -117,7 +116,7 @@ class GhostAdmin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish(what: "pages" | "posts", post: Partial<Post>): Promise<any> {
|
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}`,
|
`${this.url}/ghost/api/v3/admin/${what}/slug/${post.slug}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -126,12 +125,13 @@ class GhostAdmin {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
let oldPostQuery = await oldPostQueryR.json();
|
||||||
if (!oldPostQuery[what]) {
|
if (!oldPostQuery[what]) {
|
||||||
// New!
|
// New!
|
||||||
if (!post.status) {
|
if (!post.status) {
|
||||||
post.status = "draft";
|
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",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Ghost ${this.token}`,
|
Authorization: `Ghost ${this.token}`,
|
||||||
|
@ -141,11 +141,11 @@ class GhostAdmin {
|
||||||
[what]: [post],
|
[what]: [post],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
return result[what][0];
|
return (await result.json())[what][0];
|
||||||
} else {
|
} else {
|
||||||
let oldPost: Post = oldPostQuery[what][0];
|
let oldPost: Post = oldPostQuery[what][0];
|
||||||
post.updated_at = oldPost.updated_at;
|
post.updated_at = oldPost.updated_at;
|
||||||
let result = await json(
|
let result = await fetch(
|
||||||
`${this.url}/ghost/api/v3/admin/${what}/${oldPost.id}`,
|
`${this.url}/ghost/api/v3/admin/${what}/${oldPost.id}`,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -158,7 +158,7 @@ class GhostAdmin {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return result[what][0];
|
return (await result.json())[what][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import { Space } from "@silverbulletmd/common/spaces/space";
|
||||||
import { safeRun, throttle } from "@silverbulletmd/common/util";
|
import { safeRun, throttle } from "@silverbulletmd/common/util";
|
||||||
import { createSandbox } from "@silverbulletmd/plugos/environments/node_sandbox";
|
import { createSandbox } from "@silverbulletmd/plugos/environments/node_sandbox";
|
||||||
import { jwtSyscalls } from "@silverbulletmd/plugos/syscalls/jwt";
|
import { jwtSyscalls } from "@silverbulletmd/plugos/syscalls/jwt";
|
||||||
import { fetchSyscalls } from "@silverbulletmd/plugos/syscalls/fetch.node";
|
|
||||||
import buildMarkdown from "@silverbulletmd/web/parser";
|
import buildMarkdown from "@silverbulletmd/web/parser";
|
||||||
import { loadMarkdownExtensions } from "@silverbulletmd/web/markdown_ext";
|
import { loadMarkdownExtensions } from "@silverbulletmd/web/markdown_ext";
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ export class ExpressServer {
|
||||||
system.registerSyscalls([], spaceSyscalls(this.space));
|
system.registerSyscalls([], spaceSyscalls(this.space));
|
||||||
system.registerSyscalls([], eventSyscalls(this.eventHook));
|
system.registerSyscalls([], eventSyscalls(this.eventHook));
|
||||||
system.registerSyscalls([], markdownSyscalls(buildMarkdown([])));
|
system.registerSyscalls([], markdownSyscalls(buildMarkdown([])));
|
||||||
system.registerSyscalls([], fetchSyscalls());
|
|
||||||
system.registerSyscalls([], jwtSyscalls());
|
system.registerSyscalls([], jwtSyscalls());
|
||||||
system.addHook(new EndpointHook(app, "/_/"));
|
system.addHook(new EndpointHook(app, "/_/"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue