mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
30 lines
848 B
TypeScript
30 lines
848 B
TypeScript
import { mkdir, rm } from "node:fs/promises";
|
|||
|
|
import { join } from "node:path";
|
||
|
|
import { env } from "../config.js";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a workspace directory structure for a processing job.
|
||
|
|
* Returns the workspace root path.
|
||
|
|
*/
|
||
|
|
export async function createWorkspace(jobId: string): Promise<string> {
|
||
|
|
const root = getWorkspacePath(jobId);
|
||
|
|
await mkdir(join(root, "input"), { recursive: true });
|
||
|
|
await mkdir(join(root, "output"), { recursive: true });
|
||
|
|
return root;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the workspace root path for a job.
|
||
|
|
*/
|
||
|
|
export function getWorkspacePath(jobId: string): string {
|
||
|
|
return join(env.WORKSPACE_PATH, jobId);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the entire workspace directory for a job.
|
||
|
|
*/
|
||
|
|
export async function cleanupWorkspace(jobId: string): Promise<void> {
|
||
|
|
const root = getWorkspacePath(jobId);
|
||
|
|
await rm(root, { recursive: true, force: true });
|
||
|
|
}
|