- add FileEntity, ScenarioFileEntity, ScenarioRunFileEntity with UUID-sharded disk tree - FileStorageService: write/sha256/expiry, paginated listing, dynamic cleanup cron via SchedulerRegistry - expose getScenarioFiles() and downloadFile() on ScriptContext for use in exec code - wire scenarioId, runId, fileService into ExecContextBuilder and scenario scheduler - add file upload and listing endpoints to ScenarioController - add FILES_DIR, FILE_RUN_EXPIRATION_DAYS, FILE_CLEANUP_CRON to AppConfig
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import type { BrowserContext, Page } from "playwright";
|
|
import type { EnvironmentData } from "../environment/environment.entity";
|
|
import type { FileStorageService } from "../file/file-storage.service";
|
|
import type { ExecContext, ScriptLogger } from "./code-executor.service";
|
|
|
|
export class ExecContextBuilder {
|
|
private readonly ctx: Partial<ExecContext> = {};
|
|
|
|
page(page: Page): this {
|
|
this.ctx.page = page;
|
|
return this;
|
|
}
|
|
|
|
browser(browser: BrowserContext): this {
|
|
this.ctx.browser = browser;
|
|
return this;
|
|
}
|
|
|
|
code(code: string): this {
|
|
this.ctx.code = code;
|
|
return this;
|
|
}
|
|
|
|
log(log: ScriptLogger): this {
|
|
this.ctx.log = log;
|
|
return this;
|
|
}
|
|
|
|
getStepOutput(fn: (order: number) => Promise<unknown>): this {
|
|
this.ctx.getStepOutput = fn;
|
|
return this;
|
|
}
|
|
|
|
credentials(credentials: Record<string, unknown>): this {
|
|
this.ctx.credentials = credentials;
|
|
return this;
|
|
}
|
|
|
|
environment(environment: EnvironmentData | null): this {
|
|
this.ctx.environment = environment;
|
|
return this;
|
|
}
|
|
|
|
snippets(snippets: Record<string, string> | null): this {
|
|
this.ctx.snippets = snippets;
|
|
return this;
|
|
}
|
|
|
|
result(result: unknown): this {
|
|
this.ctx.result = result;
|
|
return this;
|
|
}
|
|
|
|
scenarioId(scenarioId: string): this {
|
|
this.ctx.scenarioId = scenarioId;
|
|
return this;
|
|
}
|
|
|
|
runId(runId: string): this {
|
|
this.ctx.runId = runId;
|
|
return this;
|
|
}
|
|
|
|
fileService(fileService: FileStorageService): this {
|
|
this.ctx.fileService = fileService;
|
|
return this;
|
|
}
|
|
|
|
build(): ExecContext {
|
|
if (!this.ctx.page) throw new Error("ExecContextBuilder: page is required");
|
|
if (!this.ctx.browser)
|
|
throw new Error("ExecContextBuilder: browser is required");
|
|
if (this.ctx.code === undefined)
|
|
throw new Error("ExecContextBuilder: code is required");
|
|
return this.ctx as ExecContext;
|
|
}
|
|
}
|