Files
plainleaf/server/util.ts
T
Zef HemelandGitHub dc2987a3f9 Sync engine rearchitecture (#1516)
* Don't require auth for .ping
* Finally introducing loggers
* Remove file list caching from disk_space_primitives
I don't think this is required anymore with the sync model
* Simplification of space primitives and more tests
* More reliable online status
* Add .zed settings
* Remove selfUpdate argument from `writeFile` no longer used
- Add `sync` config schema and document sync options
- Move sync config handling to client boot logic
- Move BootConfig type to ui_types.ts
- Remove sync env vars from server
- Update documentation for sync and architecture
* Improve sync logic and proxy routing for full sync state
* Add BoxProxy for late-bound client and improve Lua boot
- Add isMobile syscall for editor
* Add concurrency to sync process and log indexing duration
* Better service worker lifecycle management
2025-09-12 14:43:57 +02:00

44 lines
1.4 KiB
TypeScript

import type { FileMeta } from "@silverbulletmd/silverbullet/type/index";
export function utcDateString(mtime: number): string {
return new Date(mtime).toUTCString();
}
export function authCookieName(host: string) {
return `auth_${host.replaceAll(/\W/g, "_")}`;
}
export function fileMetaToHeaders(fileMeta: FileMeta) {
return {
"Content-Type": fileMeta.contentType,
"X-Last-Modified": "" + fileMeta.lastModified,
"X-Created": "" + fileMeta.created,
"Cache-Control": "no-cache",
"X-Permission": fileMeta.perm,
"X-Content-Length": "" + fileMeta.size,
};
}
export function headersToFileMeta(
name: string,
headers: Headers,
): FileMeta | undefined {
if (headers.has("X-Last-Modified")) {
// If this header is set, we need to pull out the rest also
return {
name,
// The server may set a custom X-Content-Length header in case a GET request was sent with X-Get-Meta, in which case the body may be omitted
size: headers.has("X-Content-Length")
? +headers.get("X-Content-Length")!
: +headers.get("Content-Length")!,
contentType: headers.get("Content-type")!,
created: +(headers.get("X-Created") || "0"),
lastModified: +(headers.get("X-Last-Modified") || "0"),
perm: (headers.get("X-Permission") as "rw" | "ro") || "ro",
};
} else {
// Otherwise: no file meta in headers
return undefined;
}
}