diff options
Diffstat (limited to 'src/SomhairlesDream.Server')
| -rw-r--r-- | src/SomhairlesDream.Server/ArtifactRunApi.fs | 16 | ||||
| -rw-r--r-- | src/SomhairlesDream.Server/ArtifactRunCoordinator.fs | 15 | ||||
| -rw-r--r-- | src/SomhairlesDream.Server/Store.fs | 3 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/SomhairlesDream.Server/ArtifactRunApi.fs b/src/SomhairlesDream.Server/ArtifactRunApi.fs index 8d76ffc..8f63b99 100644 --- a/src/SomhairlesDream.Server/ArtifactRunApi.fs +++ b/src/SomhairlesDream.Server/ArtifactRunApi.fs @@ -115,6 +115,19 @@ module ArtifactRunApi = | Error ArtifactNotFound -> error options 404 "artifact not found" | Error(InvalidManifest message) -> error options 500 message + let private stepArtifact options (context: HttpContext) = + match selector context, queryValue context "path" with + | Error message, _ -> error options 400 message + | _, None -> error options 400 "missing query parameter 'path'" + | Ok(projectId, runId), Some relativePath -> + match options.Coordinator.StepArtifact(projectId, runId, relativePath) with + | Ok path -> Results.File(path, artifactContentType path) + | Error RunNotFound -> error options 404 "run not found" + | Error(RunNotComplete snapshot) -> jsonWithStatus options 409 snapshot + | Error(InvalidArtifactPath message) -> error options 400 message + | Error ArtifactNotFound -> error options 404 "artifact not found" + | Error(InvalidManifest message) -> error options 500 message + let private writeError options (context: HttpContext) statusCode message = task { context.Response.StatusCode <- statusCode @@ -159,3 +172,6 @@ module ArtifactRunApi = app.MapGet("/api/artifacts/file", Func<HttpContext, IResult>(fun context -> artifact options context)) |> ignore + + app.MapGet("/api/artifacts/steps", Func<HttpContext, IResult>(fun context -> stepArtifact options context)) + |> ignore diff --git a/src/SomhairlesDream.Server/ArtifactRunCoordinator.fs b/src/SomhairlesDream.Server/ArtifactRunCoordinator.fs index 78d5dee..dbf87df 100644 --- a/src/SomhairlesDream.Server/ArtifactRunCoordinator.fs +++ b/src/SomhairlesDream.Server/ArtifactRunCoordinator.fs @@ -139,3 +139,18 @@ type ArtifactRunCoordinator( | Error message -> Error(InvalidArtifactPath message) | Ok path when not (File.Exists(path)) -> Error ArtifactNotFound | Ok path -> Ok path + + member _.StepArtifact(projectId: string, runId: string, relativePath: string) : Result<string, ArtifactLookupError> = + match registry.TryFind(projectId, runId) with + | None -> Error RunNotFound + | Some _ -> + let directory = runDirectory projectId runId + + match safeArtifactPath directory relativePath with + | Error message -> Error(InvalidArtifactPath message) + | Ok path when not (path.EndsWith(".glb", StringComparison.OrdinalIgnoreCase)) -> + Error(InvalidArtifactPath "step artifacts must be .glb files") + | Ok path when not (path.StartsWith(Path.Combine(directory, "steps") + string Path.DirectorySeparatorChar, StringComparison.Ordinal)) -> + Error(InvalidArtifactPath "step artifacts must live under steps/") + | Ok path when not (File.Exists(path)) -> Error ArtifactNotFound + | Ok path -> Ok path diff --git a/src/SomhairlesDream.Server/Store.fs b/src/SomhairlesDream.Server/Store.fs index b4a2293..e1ee814 100644 --- a/src/SomhairlesDream.Server/Store.fs +++ b/src/SomhairlesDream.Server/Store.fs @@ -60,6 +60,7 @@ type ArtifactRunStore(ids: RunIds, staleAfter: TimeSpan, initialAt: DateTimeOffs CurrentStepId = None CurrentStepIndex = -1 TotalSteps = 0 + CompletedSteps = [||] LastHeartbeatAt = None UpdatedAt = initialAt Message = "waiting for design run" @@ -120,6 +121,7 @@ type ArtifactRunStore(ids: RunIds, staleAfter: TimeSpan, initialAt: DateTimeOffs TotalSteps = value.TotalSteps CurrentStepId = None CurrentStepIndex = -1 + CompletedSteps = [||] LastHeartbeatAt = Some value.At UpdatedAt = value.At Message = "design run started" @@ -149,6 +151,7 @@ type ArtifactRunStore(ids: RunIds, staleAfter: TimeSpan, initialAt: DateTimeOffs { state with CurrentStepId = Some value.StepId CurrentStepIndex = value.StepIndex + CompletedSteps = Array.append state.CompletedSteps [| value.ArtifactPath |] LastHeartbeatAt = Some value.At UpdatedAt = value.At Message = value.Message |
