From fe5dc80a14d72cf1a5caac7b162e68b7abcb6d81 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 27 Aug 2025 09:58:11 +0200 Subject: [PATCH] Expose file system API on /.fs instead of root (#1507) Fixes #1506 --- deno.json | 2 +- lib/spaces/constants.ts | 1 + lib/spaces/http_space_primitives.ts | 6 +- scripts/generate_fs_list.ts | 33 ------ server/http_server.ts | 168 +++++++++++++--------------- web/client.ts | 6 +- web/client_system.ts | 11 +- web/editor_ui.tsx | 98 ++++++++-------- web/markdown/inline.ts | 16 ++- web/service_worker.ts | 18 +-- web/styles/theme.scss | 4 +- website/HTTP API.md | 31 +++-- website/_headers | 8 -- website/_redirects | 2 - 14 files changed, 187 insertions(+), 217 deletions(-) delete mode 100644 scripts/generate_fs_list.ts delete mode 100644 website/_headers delete mode 100644 website/_redirects diff --git a/deno.json b/deno.json index 72f247dc..1a9bd518 100644 --- a/deno.json +++ b/deno.json @@ -109,7 +109,7 @@ "@silverbulletmd/silverbullet/lib/json": "./plug-api/lib/json.ts", "@silverbulletmd/silverbullet/lib/tree": "./plug-api/lib/tree.ts", "@silverbulletmd/silverbullet/lib/attribute": "./plug-api/lib/attribute.ts", - "@silverbulletmd/silverbullet/lib/page_ref": "./plug-api/lib/page_ref.ts", + "@silverbulletmd/silverbullet/lib/ref": "./plug-api/lib/ref.ts", "@silverbulletmd/silverbullet/lib/resolve": "./plug-api/lib/resolve.ts", "@silverbulletmd/silverbullet/lib/query_expression": "./plug-api/lib/query_expression.ts", "@silverbulletmd/silverbullet/lib/native_fetch": "./plug-api/lib/native_fetch.ts", diff --git a/lib/spaces/constants.ts b/lib/spaces/constants.ts index 735cb47a..310c0b48 100644 --- a/lib/spaces/constants.ts +++ b/lib/spaces/constants.ts @@ -1,2 +1,3 @@ export const plugPrefix = "_plug/"; export const stdLibPrefix = "Library/Std/"; +export const fsEndpoint = "/.fs"; diff --git a/lib/spaces/http_space_primitives.ts b/lib/spaces/http_space_primitives.ts index 0d041d3d..50936222 100644 --- a/lib/spaces/http_space_primitives.ts +++ b/lib/spaces/http_space_primitives.ts @@ -119,7 +119,7 @@ export class HttpSpacePrimitives implements SpacePrimitives { } async fetchFileList(): Promise { - const resp = await this.authenticatedFetch(`${this.url}/index.json`, { + const resp = await this.authenticatedFetch(this.url, { method: "GET", }); @@ -222,7 +222,9 @@ export class HttpSpacePrimitives implements SpacePrimitives { // If not: throws an error or invokes a redirect async ping() { - const response = await this.authenticatedFetch(`${this.url}/.ping`, { + const parentEndpoint = this.url.split("/").slice(0, -1).join("/") + + "/.ping"; + const response = await this.authenticatedFetch(parentEndpoint, { method: "GET", headers: { Accept: "application/json", diff --git a/scripts/generate_fs_list.ts b/scripts/generate_fs_list.ts deleted file mode 100644 index 95ccc38f..00000000 --- a/scripts/generate_fs_list.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { walk } from "@std/fs/walk"; -import { resolve } from "@std/path"; -import { mime } from "mimetypes"; - -import type { FileMeta } from "../type/index.ts"; - -const rootDir = resolve("website_build"); - -const lastModifiedTimestamp = +Deno.env.get("LAST_MODIFIED_TIMESTAMP")! || - Date.now(); - -const allFiles: FileMeta[] = []; -for await ( - const file of walk(rootDir, { - includeDirs: false, - // Exclude hidden files - skip: [ - /^.*\/(\..+|_redirects|_headers|service_worker\.js.*|index\.json|_client\/.*)$/, - ], - }) -) { - const fullPath = file.path; - const s = await Deno.stat(fullPath); - allFiles.push({ - name: fullPath.substring(rootDir.length + 1), - lastModified: lastModifiedTimestamp, - created: lastModifiedTimestamp, - contentType: mime.getType(fullPath) || "application/octet-stream", - size: s.size, - perm: "rw", - }); -} -console.log(JSON.stringify(allFiles, null, 2)); diff --git a/server/http_server.ts b/server/http_server.ts index bd4ffcf0..16ea7728 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -97,7 +97,7 @@ export class HttpServer { // Serve static files (javascript, css, html) this.serveStatic(); this.addAuth(); - this.addFsRoutes(); + this.app.route("/.fs", this.buildFsRoutes()); // Fallback, serve the UI index.html this.app.use("*", (c) => { @@ -369,13 +369,6 @@ export class HttpServer { }); }); - // Simple ping health endpoint - this.app.get("/.ping", (c) => { - return c.text("OK", 200, { - "Cache-Control": "no-cache", - }); - }); - // Shell command endpoint this.app.post("/.shell", (c) => { return handleShellEndpoint( @@ -385,6 +378,13 @@ export class HttpServer { ); }); + // Simple ping health endpoint + this.app.get("/.ping", (c) => { + return c.text("OK", 200, { + "Cache-Control": "no-cache", + }); + }); + // HTTP Proxy endpoint const proxyPathRegex = "/.proxy/:uri{.+}"; this.app.all( @@ -465,9 +465,10 @@ export class HttpServer { } } - private addFsRoutes() { + private buildFsRoutes(): Hono { + const fsRoutes = new Hono(); // File list - this.app.get("/index.json", async (c) => { + fsRoutes.get("/", async (c) => { const req = c.req; if (req.header("X-Sync-Mode")) { // Only handle direct requests for a JSON representation of the file list @@ -482,94 +483,79 @@ export class HttpServer { } }); - const filePathRegex = "/:path{.*\\.[a-zA-Z0-9]+}"; - const mdExt = ".md"; + fsRoutes.get("/:path{.*}", this.handleGet.bind(this)).put( + this.handlePut.bind(this), + ).delete(this.handleDelete.bind(this)).options(); - this.app.get(filePathRegex, async (c, next) => { - const req = c.req; - const name = req.param("path")!; + return fsRoutes; + } - if ( - name.endsWith(mdExt) && - // This header signififies the requests comes directly from the http_space_primitives client (not the browser) - !req.header("X-Sync-Mode") && - req.header("sec-fetch-mode") !== "cors" - ) { - // It can happen that during a sync, authentication expires, this may result in a redirect to the login page and then back to this particular file. This particular file may be an .md file, which isn't great to show so we're redirecting to the associated SB UI page. - console.warn( - "Request was without X-Sync-Mode nor a CORS request, redirecting to page", + private async handleDelete(c: Context) { + const req = c.req; + const name = req.param("path")!; + if (this.options.readOnly) { + return c.text("Read only mode, no writes allowed", 405); + } + console.log("Deleting file", name); + try { + await this.spacePrimitives.deleteFile(name); + return c.text("OK"); + } catch (e: any) { + console.error("Error deleting document", e); + return c.text(e.message, 500); + } + } + + private async handlePut(c: Context) { + const req = c.req; + const path = req.param("path")!; + if (this.options.readOnly) { + return c.text("Read only mode, no writes allowed", 405); + } + console.log("Writing file", path); + + const body = await req.arrayBuffer(); + + try { + const meta = await this.spacePrimitives.writeFile( + path, + new Uint8Array(body), + ); + return c.text("OK", 200, this.fileMetaToHeaders(meta)); + } catch (err) { + console.error("Write failed", err); + return c.text("Write failed", 500); + } + } + + async handleGet(c: Context) { + const req = c.req; + const name = req.param("path")!; + + try { + if (req.header("X-Get-Meta")) { + // Getting meta via GET request + const fileData = await this.spacePrimitives.getFileMeta( + name, ); - return c.redirect(this.prefixedUrl(`/${name.slice(0, -mdExt.length)}`)); + return c.text("", 200, this.fileMetaToHeaders(fileData)); } - // This is a good guess that the request comes directly from a user + const fileData = await this.spacePrimitives.readFile(name); + const lastModifiedHeader = new Date(fileData.meta.lastModified) + .toUTCString(); if ( - req.header("Accept")?.includes("text/html") && - req.query("raw") !== "true" + req.header("If-Modified-Since") === lastModifiedHeader ) { - return next(); + return c.body(null, 304); } - - try { - if (req.header("X-Get-Meta")) { - // Getting meta via GET request - const fileData = await this.spacePrimitives.getFileMeta( - name, - ); - return c.text("", 200, this.fileMetaToHeaders(fileData)); - } - const fileData = await this.spacePrimitives.readFile(name); - const lastModifiedHeader = new Date(fileData.meta.lastModified) - .toUTCString(); - if ( - req.header("If-Modified-Since") === lastModifiedHeader - ) { - return c.body(null, 304); - } - return c.body(new Uint8Array(fileData.data).buffer, 200, { - ...this.fileMetaToHeaders(fileData.meta), - "Last-Modified": lastModifiedHeader, - }); - } catch (e: any) { - console.error("Error GETting file", name, e.message); - return c.notFound(); - } - }).put( - async (c) => { - const req = c.req; - const path = req.param("path")!; - if (this.options.readOnly) { - return c.text("Read only mode, no writes allowed", 405); - } - console.log("Writing file", path); - - const body = await req.arrayBuffer(); - - try { - const meta = await this.spacePrimitives.writeFile( - path, - new Uint8Array(body), - ); - return c.text("OK", 200, this.fileMetaToHeaders(meta)); - } catch (err) { - console.error("Write failed", err); - return c.text("Write failed", 500); - } - }, - ).delete(async (c) => { - const req = c.req; - const name = req.param("path")!; - if (this.options.readOnly) { - return c.text("Read only mode, no writes allowed", 405); - } - console.log("Deleting file", name); - try { - await this.spacePrimitives.deleteFile(name); - return c.text("OK"); - } catch (e: any) { - console.error("Error deleting document", e); - return c.text(e.message, 500); - } - }).options(); + return c.body(new Uint8Array(fileData.data).buffer, 200, { + ...this.fileMetaToHeaders(fileData.meta), + "Last-Modified": lastModifiedHeader, + }); + } catch (e: any) { + console.error("Error GETting file", name, e.message); + return c.notFound(); + } } private fileMetaToHeaders(fileMeta: FileMeta) { diff --git a/web/client.ts b/web/client.ts index a893cf20..b4e2e2ea 100644 --- a/web/client.ts +++ b/web/client.ts @@ -58,7 +58,7 @@ import { DataStoreSpacePrimitives } from "../lib/spaces/datastore_space_primitiv import { ReadOnlySpacePrimitives } from "../lib/spaces/ro_space_primitives.ts"; import { LimitedMap } from "../lib/limited_map.ts"; -import { plugPrefix } from "../lib/spaces/constants.ts"; +import { fsEndpoint, plugPrefix } from "../lib/spaces/constants.ts"; import { diffAndPrepareChanges } from "./cm_util.ts"; import { DocumentEditor } from "./document_editor.ts"; import { parseExpressionString } from "../lib/space_lua/parse.ts"; @@ -319,7 +319,7 @@ export class Client { initSpace() { this.httpSpacePrimitives = new HttpSpacePrimitives( - document.baseURI.replace(/\/*$/, ""), + document.baseURI.replace(/\/*$/, "") + fsEndpoint, this.clientConfig.spaceFolderPath, ); @@ -943,7 +943,7 @@ export class Client { } catch (e: any) { // If there is no document editor we will open the file raw if (e.message.includes("Couldn't find")) { - this.openUrl(path + "?raw=true", !previousPath); + this.openUrl(fsEndpoint + "/" + path, !previousPath); } throw e; diff --git a/web/client_system.ts b/web/client_system.ts index ad976c72..cf0a599f 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -34,7 +34,7 @@ import { clientCodeWidgetSyscalls } from "./syscalls/client_code_widget.ts"; import { KVPrimitivesManifestCache } from "../lib/plugos/manifest_cache.ts"; import { createKeyBindings } from "./editor_state.ts"; import type { DataStoreMQ } from "../lib/data/mq.datastore.ts"; -import { plugPrefix } from "../lib/spaces/constants.ts"; +import { fsEndpoint, plugPrefix } from "../lib/spaces/constants.ts"; import { jsonschemaSyscalls } from "./syscalls/jsonschema.ts"; import { luaSyscalls } from "./syscalls/lua.ts"; import { indexSyscalls } from "./syscalls/index.ts"; @@ -150,7 +150,12 @@ export class ClientSystem { this.system.unload(path); await this.system.load( plugName, - createSandbox(new URL(`${path}`, document.baseURI)), + createSandbox( + new URL( + `${path}`, + document.baseURI.slice(0, -1) + fsEndpoint + "/", + ), + ), newHash, ); } @@ -266,7 +271,7 @@ export class ClientSystem { createSandbox( new URL( plugMeta.name, - document.baseURI, // We're NOT striping trailing '/', this used to be `location.origin` + document.baseURI.slice(0, -1) + fsEndpoint + "/", // We're NOT striping trailing '/', this used to be `location.origin` ), ), plugMeta.lastModified, diff --git a/web/editor_ui.tsx b/web/editor_ui.tsx index 0dd706a7..1fdcef27 100644 --- a/web/editor_ui.tsx +++ b/web/editor_ui.tsx @@ -181,7 +181,7 @@ export class MainUI { if (client.clientSystem.allKnownFiles.has(name)) { // Try it as a document name === path - await askForModification( + await this.promptDocumentOperation( name as Path, `'${name}' has an invalid name. You can now modify it`, ); @@ -189,7 +189,7 @@ export class MainUI { client.clientSystem.allKnownFiles.has(`${name}.md`) ) { // Try it as a page - await askForModification( + await this.promptDocumentOperation( `${name}.md`, `'${name}.md' has an invalid name. You can now modify it`, ); @@ -212,9 +212,9 @@ export class MainUI { extensions.includes(getPathExtension(ref.path)) ) ) { - await askForModification( + await this.promptDocumentOperation( ref.path, - "There is no editor for this file type. Modify the selected document", + "This file cannot be edited, select your desired action.", ); } else { client.navigate(ref); @@ -434,9 +434,55 @@ export class MainUI { container.innerHTML = ""; preactRender(h(this.ViewComponent.bind(this), {}), container); } + + async promptDocumentOperation(path: Path, msg: string) { + const options: string[] = ["View", "Delete", "Rename"]; + + const option = await client.filterBox( + "Modify", + options.map((x) => ({ name: x } as FilterOption)), + msg, + ); + if (!option) return; + + switch (option.name) { + case "View": { + await client.navigate({ path: path }); + break; + } + case "Delete": { + if ( + await client.confirm( + `Are you sure you would like delete ${getNameFromPath(path)}?`, + ) + ) { + if (isMarkdownPath(path)) { + await client.space.deletePage(getNameFromPath(path)); + } else { + await client.space.deleteDocument(getNameFromPath(path)); + } + } + break; + } + case "Rename": { + if (isMarkdownPath(path)) { + await client.clientSystem.system.invokeFunction( + "index.renamePageCommand", + [{ oldPage: getNameFromPath(path) }], + ); + } else { + await client.clientSystem.system.invokeFunction( + "index.renameDocumentCommand", + [{ oldDocument: getNameFromPath(path) }], + ); + } + break; + } + } + } } -// TODO: Parking this here for now +// TODO: Parking this here for now, this is very similar to the definition in top_bar.tsx type ActionButton = { icon: string; @@ -452,45 +498,3 @@ function kebabToCamel(str: string) { (g) => g.toUpperCase(), ); } - -async function askForModification(path: Path, msg: string) { - const options: string[] = ["Delete", "Rename"]; - - const option = await client.filterBox( - "Modify", - options.map((x) => ({ name: x } as FilterOption)), - msg, - ); - if (!option) return; - - switch (option.name) { - case "Delete": { - if ( - await client.confirm( - `Are you sure you would like delete ${getNameFromPath(path)}?`, - ) - ) { - if (isMarkdownPath(path)) { - await client.space.deletePage(getNameFromPath(path)); - } else { - await client.space.deleteDocument(getNameFromPath(path)); - } - } - break; - } - case "Rename": { - if (isMarkdownPath(path)) { - await client.clientSystem.system.invokeFunction( - "index.renamePageCommand", - [{ oldPage: getNameFromPath(path) }], - ); - } else { - await client.clientSystem.system.invokeFunction( - "index.renameDocumentCommand", - [{ oldDocument: getNameFromPath(path) }], - ); - } - break; - } - } -} diff --git a/web/markdown/inline.ts b/web/markdown/inline.ts index b466800d..40fdd7c9 100644 --- a/web/markdown/inline.ts +++ b/web/markdown/inline.ts @@ -26,6 +26,8 @@ import { evalExpression } from "../../lib/space_lua/eval.ts"; import type { LuaExpression } from "../../lib/space_lua/ast.ts"; import { mdLinkRegex, wikiLinkRegex } from "../markdown_parser/constants.ts"; +import { fsEndpoint } from "../../lib/spaces/constants.ts"; + /** * Describes the dimensions of a transclusion, if provided through the alias. * Can be parsed from the alias using {@link parseDimensionFromAlias} @@ -225,19 +227,21 @@ export function inlineContentFromURL( (dimension?.width ? `width: ${dimension.width}px;` : "") + (dimension?.height ? `height: ${dimension.height}px;` : ""); - // If the URL is a local, encode the : so that it's not interpreted as a protocol - const sanitizedURL = isLocalURL(url) ? url.replace(":", "%3A") : url; + // If the URL is a local, prefix it with /.fs and encode the : so that it's not interpreted as a protocol + const sanitizedFsUrl = isLocalURL(url) + ? fsEndpoint.slice(1) + "/" + url.replace(":", "%3A") + : url; let result: HTMLElement | string | Promise; if (mimeType.startsWith("image/")) { const img = document.createElement("img"); - img.src = sanitizedURL; + img.src = sanitizedFsUrl; img.alt = alias; img.style = style; result = img; } else if (mimeType.startsWith("video/")) { const video = document.createElement("video"); - video.src = sanitizedURL; + video.src = sanitizedFsUrl; video.title = alias; video.controls = true; video.autoplay = false; @@ -245,7 +249,7 @@ export function inlineContentFromURL( result = video; } else if (mimeType.startsWith("audio/")) { const audio = document.createElement("audio"); - audio.src = sanitizedURL; + audio.src = sanitizedFsUrl; audio.title = alias; audio.controls = true; audio.autoplay = false; @@ -254,7 +258,7 @@ export function inlineContentFromURL( } else if (mimeType === "application/pdf") { const embed = document.createElement("object"); embed.type = mimeType; - embed.data = sanitizedURL; + embed.data = sanitizedFsUrl; embed.style.width = "100%"; embed.style.height = "20em"; embed.style = style; diff --git a/web/service_worker.ts b/web/service_worker.ts index 26efe656..401cd91b 100644 --- a/web/service_worker.ts +++ b/web/service_worker.ts @@ -4,6 +4,8 @@ import { DataStore } from "../lib/data/datastore.ts"; import { IndexedDBKvPrimitives } from "../lib/data/indexeddb_kv_primitives.ts"; import { decodePageURI } from "@silverbulletmd/silverbullet/lib/ref"; +import { fsEndpoint } from "../lib/spaces/constants.ts"; + // Note: the only thing cached here is SilverBullet client assets, files and databases are kept in IndexedDB const CACHE_NAME = "{{CACHE_NAME}}"; @@ -123,23 +125,25 @@ self.addEventListener("fetch", (event: any) => { pathname === "/.auth" || pathname === "/.logout" || pathname === "/.config" || - pathname === "/index.json" + pathname === "/.fs" ) { + // Always proxy auth, config and fs listing requests to the server return fetch(request); } else if ( + pathname.startsWith(fsEndpoint) && pathname.endsWith(".md") && request.headers.get("accept") !== "application/octet-stream" && request.headers.get("sec-fetch-mode") !== "cors" ) { - return Response.redirect(`${pathname.slice(0, -3)}`); + // This handles the case of ending up with a .md URL in the browser address bar (likely due to a auth proxy redirect) + return Response.redirect(`${pathname.slice(fsEndpoint.length, -3)}`); } else if ( - !request.headers.get("accept").includes("text/html") || - requestUrl.searchParams.get("raw") === "true" + // /.fs file system APIs: handled locally + pathname.startsWith(fsEndpoint) ) { - // If this is a /*.* request, this can either be a plug worker load or an document load return handleLocalFileRequest(pathname, request); } else { - // Must be a page URL, let's serve index.html which will handle it + // Fallback to the SB app shell for all other requests (SPA) return (await caches.match(precacheFiles["/"])) || fetch(request); } })().catch((e) => { @@ -155,7 +159,7 @@ async function handleLocalFileRequest( pathname: string, request: Request, ): Promise { - const path = decodePageURI(pathname.slice(1)); + const path = decodePageURI(pathname.slice(fsEndpoint.length + 1)); const data = await ds?.get([...filesContentPrefix, path]); if (data) { // console.log("Serving from space", path); diff --git a/web/styles/theme.scss b/web/styles/theme.scss index e25ab4b2..1f4fcfec 100644 --- a/web/styles/theme.scss +++ b/web/styles/theme.scss @@ -5,7 +5,7 @@ html { --highlight-color: rgba(255, 255, 0, 0.5); --link-color: #0330cb; --link-missing-color: #9e4705; - --link-invalid-color: #BB08E7; + --link-invalid-color: #bb08e7; --meta-color: #650007; --meta-subtle-color: #959595; --subtle-color: #676767; @@ -153,7 +153,7 @@ html[data-theme="dark"] { --highlight-color: rgba(255, 255, 0, 0.5); --link-color: #7e99fc; --link-missing-color: #9e4705; - --link-invalid-color: #D444F8; + --link-invalid-color: #d444f8; --meta-color: #d6222e; --meta-subtle-color: #959595; --subtle-color: #959595; diff --git a/website/HTTP API.md b/website/HTTP API.md index 660b6072..d18a43aa 100644 --- a/website/HTTP API.md +++ b/website/HTTP API.md @@ -1,23 +1,30 @@ The server API is relatively small. The client primarily communicates with the server for file “CRUD” (Create, Read, Update, Delete) style operations. -All API requests from the client will always set the `X-Sync-Mode` request header set to `true`. The server may use this fact to distinguish between requests coming from the client and regular e.g. `GET` requests from the browser (through navigation) and redirect appropriately (for instance to the UI URL associated with a specific `.md` file). +All API requests from the client will always set the `X-Sync-Mode` request header set to `true`. The server _will_ use this fact to distinguish between requests coming from the client and regular e.g. `GET` requests from the browser (through navigation) and redirect appropriately (for instance to the UI URL associated with a specific `.md` file). -The API: +# File system +The space file system is exposed under the `/.fs` prefix: -* `GET /index.json` will return a full listing of all files in your space including metadata like when the file was last modified, as well as permissions. This is primarily used for sync purposes with the client. -* `GET /*.*`: _Reads_ and returns the content of the file at the given path. This means that if you `GET /index.md` you will receive the content of your `index` page. If the optional `X-Get-Meta` _request header_ is set, the server does not _need to_ return the body of the file (but it can). The `GET` _response_ will have a few additional SB-specific headers: - * (optional) `X-Last-Modified` the last modified time of the file as a UNIX timestamp in ms since the epoch (as coming from `Data.now()`). This timestamp _has_ to match the `lastModified` listed for this file in `/index.json` otherwise syncing issues may occur. When this header is missing, frequent polling-based sync will be disabled for this file. +* `GET /.fs` will return a full listing of all files in your space including metadata like when the file was last modified, as well as permissions in JSON format. This is primarily used for sync purposes with the client. +* `GET /.fs/*`: _Reads_ and returns the content of the file at the given path. This means that if you `GET /.fs/index.md` you will receive the content of your `index` page. If the optional `X-Get-Meta` _request header_ is set, the server does not _need to_ return the body of the file (but it can). The `GET` _response_ will have a few additional SB-specific headers: + * (optional) `X-Last-Modified` the last modified time of the file as a UNIX timestamp in ms since the epoch (as coming from `Data.now()`). This timestamp _has_ to match the `lastModified` listed for this file in `/.fs` otherwise syncing issues may occur. When this header is missing, frequent polling-based sync will be disabled for this file. * (optional) `X-Created` the created time of the file as a UNIX timestamp in ms since the epoch (as coming from `Data.now()`). * (optional) `X-Permission`: either `rw` or `ro` which will change whether the editor opens in read-only or edit mode. When missing, `ro` is assumed. * (optional) `X-Content-Length`: which will be the same as `Content-Length` except if the request was sent with a `X-Get-Meta` header and the body is not returned (then `Content-Length` will be `0` and `X-Content-Length` will be the size of the file) -* `PUT /*.*`: The same as `GET` except that it takes the body of the request and _writes_ it to a file. -* `DELETE /*.*`: Again the same, except this will _delete_ the given file. -* `GET /*` and `GET /`: Anything else (any path without a file extension) will serve the SilverBullet UI HTML. -* `GET /.client/*`: Retrieve files implementing the client +* `PUT /.fs/*`: The same as `GET` except that it takes the body of the request and _writes_ it to a file. +* `DELETE /.fs/*`: Again the same, except this will _delete_ the given file. + +# RPC +Some functionality is exposed as RPC calls + +* `GET /.ping`: Returns 200 if the server is available +* `POST /.shell`: Run a shell command on the server side and return the result +* `* /.proxy/`: Proxy a HTTP request (to avoid CORS issues) + +# Client * `GET /.config`: Retrieve client configuration, JSON with the following keys: * `readOnly`: Run the client in read-only mode * `spaceFolderPath`: Path of the space (used to prefix client database names to support switching space folders) * `indexPage`: name of the index page -* `GET /.ping`: Returns 200 if the server is available -* `POST /.shell`: Run a shell command on the server side and return the result -* `* /.proxy/`: Proxy a HTTP request (to avoid CORS issues) +* `GET /.client/*`: Retrieve files implementing the client +* `GET /*` (every other path) will serve the HTML of the SilverBullet UI diff --git a/website/_headers b/website/_headers deleted file mode 100644 index b33691c8..00000000 --- a/website/_headers +++ /dev/null @@ -1,8 +0,0 @@ -/* - X-Last-Modified: 12345 - X-Created: 12345 - X-Permission: rw - access-control-allow-headers: * - access-control-allow-methods: GET,POST,PUT,DELETE,OPTIONS,HEAD - access-control-allow-origin: * - access-control-expose-headers: * \ No newline at end of file diff --git a/website/_redirects b/website/_redirects deleted file mode 100644 index 95afc944..00000000 --- a/website/_redirects +++ /dev/null @@ -1,2 +0,0 @@ -/.client/* /_client/:splat 200! -/* /_client/index.html 200 \ No newline at end of file