diff --git a/apps/daemon/src/index.ts b/apps/daemon/src/index.ts index 600ea2e..e479280 100644 --- a/apps/daemon/src/index.ts +++ b/apps/daemon/src/index.ts @@ -41,4 +41,6 @@ const app = new Elysia() }); console.log(`✨ Stardust daemon is running at ${app.server?.hostname}:${app.server?.port}`); + +// eden export type App = typeof app; diff --git a/apps/daemon/src/session/file.ts b/apps/daemon/src/session/file.ts index d30895d..3382b82 100644 --- a/apps/daemon/src/session/file.ts +++ b/apps/daemon/src/session/file.ts @@ -21,3 +21,20 @@ export async function getFile(id: string, name: string) { const unzipped = Bun.gunzipSync(file.read()); return unzipped; } + +export async function listFiles(id: string) { + const exec = await docker.getContainer(id).exec({ + Cmd: ["sh", "-c", "ls /home/stardust/Downloads"], + AttachStdout: true, + AttachStderr: true, + }); + + const stream = await exec.start({ hijack: true, stdin: true }); + const data = await new Promise((res, err) => { + const out: string[] = []; + stream.on("error", err); + stream.on("data", (chunk) => out.push(chunk.toString())); + stream.on("end", () => res(out.join(""))); + }); + return data; +} diff --git a/apps/daemon/src/session/index.ts b/apps/daemon/src/session/index.ts index 85d91b4..451c451 100644 --- a/apps/daemon/src/session/index.ts +++ b/apps/daemon/src/session/index.ts @@ -3,7 +3,7 @@ import { getConfig } from "~/lib/config/index.js"; import { docker } from "~/lib/docker.js"; import createSession from "./create.js"; import deleteSession from "./delete.js"; -import { getFile, sendFile } from "./file.js"; +import { getFile, listFiles, sendFile } from "./file.js"; import manageSession from "./manage.js"; import screenshot from "./screenshot.js"; // fill this @@ -81,19 +81,7 @@ export default new Elysia({ prefix: "/sessions" }) .group("/:id/files", (app) => app .get("/list", async ({ params: { id } }) => { - const exec = await docker.getContainer(id).exec({ - Cmd: ["sh", "-c", "ls /home/stardust/Downloads"], - AttachStdout: true, - AttachStderr: true, - }); - - const stream = await exec.start({ hijack: true, stdin: true }); - const data = await new Promise((res, err) => { - const out: string[] = []; - stream.on("error", err); - stream.on("data", (chunk) => out.push(chunk.toString())); - stream.on("end", () => res(out.join(""))); - }); + const data = await listFiles(id); return { success: true, data: data.split("\n").filter(Boolean),