feat(files): add file storage subsystem with scenario and run artifact support

- 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
This commit is contained in:
ars9 committed 2026-04-21 13:01:09 +03:00
1 parent aa3bae9020
commit 6a91ce30e3
15 files changed
+864

No files matched your search

@@ -10,9 +10,13 @@ import {
Post,
Query,
Res,
UseInterceptors,
UploadedFile,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { Response } from "express";
import type { File as MulterFile } from "multer";
import { stringify as yamlStringify } from "yaml";
import { AddScenarioCredentialDto } from "./dto/add-scenario-credential.dto";
import { CreateScenarioRunDto } from "./dto/create-scenario-run.dto";
@@ -270,4 +274,78 @@ export class ScenarioController {
) {
return this.scenarioService.waitForRun(id, runId);
}
// ── Files ─────────────────────────────────────────────────────────────────
@Post(":id/files")
@UseInterceptors(FileInterceptor("file"))
@ApiOperation({ summary: "Upload a file to a scenario" })
@ApiResponse({ status: 201, description: "File uploaded" })
@ApiResponse({ status: 404, description: "Scenario not found" })
uploadFile(
@Param("id", ParseUUIDPipe) id: string,
@UploadedFile() file: MulterFile,
@Body() body: { expiresAt?: string },
) {
return this.scenarioService.uploadFile(id, file, body.expiresAt);
}
@Get(":id/files")
@ApiOperation({ summary: "List files attached to a scenario" })
@ApiResponse({ status: 200 })
@ApiResponse({ status: 404, description: "Scenario not found" })
listScenarioFiles(
@Param("id", ParseUUIDPipe) id: string,
@Query("limit") limit?: string,
@Query("offset") offset?: string,
) {
return this.scenarioService.listScenarioFiles(
id,
limit ? parseInt(limit, 10) : undefined,
offset ? parseInt(offset, 10) : undefined,
);
}
@Get(":id/files/:fileId/content")
@ApiOperation({ summary: "Download file content" })
@ApiResponse({ status: 200, description: "File content" })
@ApiResponse({ status: 404, description: "Scenario or file not found" })
async getScenarioFileContent(
@Param("id", ParseUUIDPipe) id: string,
@Param("fileId", ParseUUIDPipe) fileId: string,
@Res() res: Response,
) {
return this.scenarioService.getScenarioFileContent(id, fileId, res);
}
@Get(":id/runs/:runId/files")
@ApiOperation({ summary: "List files created during a run" })
@ApiResponse({ status: 200 })
@ApiResponse({ status: 404, description: "Scenario or run not found" })
listRunFiles(
@Param("id", ParseUUIDPipe) id: string,
@Param("runId", ParseUUIDPipe) runId: string,
@Query("limit") limit?: string,
@Query("offset") offset?: string,
) {
return this.scenarioService.listRunFiles(
id,
runId,
limit ? parseInt(limit, 10) : undefined,
offset ? parseInt(offset, 10) : undefined,
);
}
@Get(":id/runs/:runId/files/:fileId/content")
@ApiOperation({ summary: "Download run artifact file content" })
@ApiResponse({ status: 200, description: "File content" })
@ApiResponse({ status: 404, description: "Scenario, run, or file not found" })
async getRunFileContent(
@Param("id", ParseUUIDPipe) id: string,
@Param("runId", ParseUUIDPipe) runId: string,
@Param("fileId", ParseUUIDPipe) fileId: string,
@Res() res: Response,
) {
return this.scenarioService.getRunFileContent(id, runId, fileId, res);
}
}