From 234a6caeb678db1695fed51dc173fee0c20be0ed Mon Sep 17 00:00:00 2001 From: Exelo Date: Sun, 7 Jun 2026 14:00:14 +0900 Subject: [PATCH 1/2] feat: add code editor sync with server --- src/lib/client/sync-file-system/sfs-file.ts | 4 ++-- src/routes/fs/project/+server.ts | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib/client/sync-file-system/sfs-file.ts b/src/lib/client/sync-file-system/sfs-file.ts index 0bc3f16..125b60e 100644 --- a/src/lib/client/sync-file-system/sfs-file.ts +++ b/src/lib/client/sync-file-system/sfs-file.ts @@ -63,11 +63,11 @@ export class SfsFile { if (!this._cache) return; const file = await this._cache.getFile(); const res = await fetch(this._route, { - body: file.stream(), + body: file, method: 'POST', headers: { [SESSION_PROJECT_HEADER]: this._handler.project.id }, }); - if (!res.ok) throw new Error('Failed to sync file'); + if (!res.ok) throw new Error(`Failed to sync file: ${await res.text()}`); } async getFile(): Promise { diff --git a/src/routes/fs/project/+server.ts b/src/routes/fs/project/+server.ts index 0856a26..5238e51 100644 --- a/src/routes/fs/project/+server.ts +++ b/src/routes/fs/project/+server.ts @@ -1,3 +1,5 @@ +import { Writable } from 'stream'; + import { Exception } from '@utils/exception'; import { useRequestHandler } from '@utils-server/request-handler'; @@ -18,3 +20,23 @@ export const GET = useRequestHandler(({ event, project }) => { return new Response(stream); }); + +/** + * To post a project file, use the following URL: + * /fs/project?path=path/to/file + * The path must be relative to /client + * Only the client is handled for now + */ +export const POST = useRequestHandler(async ({ event, project }) => { + const path = event.url.searchParams.get('path'); + if (!path) throw new Exception('Bad Request', 'Missing path query param', 400); + + const file = project.client.fs.getFile(decodeURIComponent(path).replace(/\?url$/, '')); + + if (!event.request.body) throw new Exception('Bad Request', 'Missing body', 400); + + const stream = file.getWriteStream(); + await event.request.body.pipeTo(Writable.toWeb(stream)); + + return Response.json({ success: true }); +}); From 2b99ec984de2b934e285d902496e07d4548c312d Mon Sep 17 00:00:00 2001 From: Exelo Date: Sun, 7 Jun 2026 09:09:18 +0200 Subject: [PATCH 2/2] fix: add content type to sync fetch Co-authored-by: Leo <114911021+Tchips46@users.noreply.github.com> --- src/lib/client/sync-file-system/sfs-file.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/client/sync-file-system/sfs-file.ts b/src/lib/client/sync-file-system/sfs-file.ts index 125b60e..1699728 100644 --- a/src/lib/client/sync-file-system/sfs-file.ts +++ b/src/lib/client/sync-file-system/sfs-file.ts @@ -65,7 +65,10 @@ export class SfsFile { const res = await fetch(this._route, { body: file, method: 'POST', - headers: { [SESSION_PROJECT_HEADER]: this._handler.project.id }, + headers: { + [SESSION_PROJECT_HEADER]: this._handler.project.id, + 'Content-Type': 'application/octet-stream', + }, }); if (!res.ok) throw new Error(`Failed to sync file: ${await res.text()}`); }