Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 27d9618995 | |||
| 1d60a55b3c | |||
| 88112112d4 | |||
| 91e69f0bcb | |||
| 477aef7b27 | |||
| f30acef101 | |||
| 326d8cbefa | |||
| b596c97faf | |||
| 824695ef30 | |||
| 390d7a21ac | |||
| 5e29c3b88d | |||
| c2509512ff | |||
| 27f9f7ac64 | |||
| 9660cdc21c | |||
| bae46c2968 | |||
| 2e9fa45580 | |||
| 2817c7e815 | |||
| 428814b8b9 | |||
| 45459e4b12 | |||
| 2b373737d8 | |||
| 724b0cbefe | |||
| 0c4f94d56a | |||
| 40b99f3add | |||
| 33bc6a935c | |||
| 532ebd82d7 | |||
| 708e8a0d8f | |||
| 97246bcbc3 | |||
| 400cf3f6ea | |||
| 2dee1bf6fc | |||
| 469d782b4f | |||
| 6afbe82a29 | |||
| 6bfc013e35 | |||
| f6a7f0ef5a | |||
| fe420b9455 | |||
| 2a8888089f | |||
| a073f92da3 | |||
| 04e5eb123a | |||
| 75f9258b69 |
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.0.1",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "web",
|
||||||
|
"runtimeExecutable": "npm",
|
||||||
|
"runtimeArgs": ["run", "dev"],
|
||||||
|
"port": 3000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+66
-9
@@ -20,9 +20,14 @@ This is the operational guide. The design rationale and normative rules live in
|
|||||||
18 shots"*, click **Build delivery**.
|
18 shots"*, click **Build delivery**.
|
||||||
3. A render worker builds the folder on the delivery volume, verifies every
|
3. A render worker builds the folder on the delivery volume, verifies every
|
||||||
file, and writes a manifest and CSV report.
|
file, and writes a manifest and CSV report.
|
||||||
4. A human uploads that folder to the client, then clicks **Mark delivered**.
|
4. A human uploads that folder to the client and clicks **Record upload**,
|
||||||
|
pasting the link to where it now lives.
|
||||||
|
5. They send the client that link and click **Share link**, recording who it
|
||||||
|
went to. Only then is the package `DELIVERED`.
|
||||||
|
|
||||||
Nothing is ever sent to the client automatically. Step 4 is deliberately manual.
|
Nothing is ever sent to the client automatically. Steps 4 and 5 are deliberately
|
||||||
|
manual — but until both are recorded the package sits in **Awaiting delivery**
|
||||||
|
at the top of the dashboard.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -69,8 +74,8 @@ Watch the package status on the same page:
|
|||||||
|---|---|
|
|---|---|
|
||||||
| `QUEUED` | Waiting for a worker to pick it up |
|
| `QUEUED` | Waiting for a worker to pick it up |
|
||||||
| `BUILDING` | A worker is creating folders and linking files |
|
| `BUILDING` | A worker is creating folders and linking files |
|
||||||
| `READY` | Built and verified — upload it |
|
| `READY` | Built and verified. Shown as *Built — not uploaded*, then *Uploaded — link not shared* |
|
||||||
| `DELIVERED` | You confirmed the client has it |
|
| `DELIVERED` | The upload location and who the link was sent to are both on record |
|
||||||
| `FAILED` | Something did not verify — see the error and the per-shot list |
|
| `FAILED` | Something did not verify — see the error and the per-shot list |
|
||||||
| `CANCELLED` | Abandoned before delivery |
|
| `CANCELLED` | Abandoned before delivery |
|
||||||
|
|
||||||
@@ -166,11 +171,59 @@ so it is logged and the package continues without it.
|
|||||||
|
|
||||||
## Marking delivered
|
## Marking delivered
|
||||||
|
|
||||||
Once you have uploaded the folder, **Mark delivered** moves every packaged
|
A built package is not a delivered one, so delivery is two recorded steps. Both
|
||||||
export to `DELIVERED`. Requires admin, producer or supervisor.
|
require admin, producer or supervisor.
|
||||||
|
|
||||||
This is the end of the pipeline, and it is a human statement of fact — the app
|
1. **Record upload** — paste the link to the folder on the client's portal and
|
||||||
has no way to know the client received anything.
|
confirm it matches the shot, frame and MOV counts shown. The link can be
|
||||||
|
corrected until it is shared.
|
||||||
|
2. **Share link** — copy the generated message (link, shots, versions), send it,
|
||||||
|
and record who it went to. This moves every packaged export to `DELIVERED`.
|
||||||
|
|
||||||
|
The second step is refused until the first is on record. Meanwhile the package
|
||||||
|
is listed under **Awaiting delivery** on the dashboard, amber after a day and
|
||||||
|
red after two.
|
||||||
|
|
||||||
|
This is still a human statement of fact — the client's portal has no API, so
|
||||||
|
the app cannot see the upload itself. What it guarantees is that nothing reads
|
||||||
|
as delivered without a link, a recipient, a name and a time behind it. Packages
|
||||||
|
delivered before this existed show as delivered with no evidence recorded.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Delivery requests
|
||||||
|
|
||||||
|
When a client asks for something ("EXRs for 116"), log it so it cannot be
|
||||||
|
forgotten. Requires admin, producer or supervisor.
|
||||||
|
|
||||||
|
- **Dashboard → Awaiting delivery → Log request**, or the same button on
|
||||||
|
**Pipeline → Deliveries**: pick the project, then a whole episode or a pasted
|
||||||
|
list of shot codes (ours or the client's; a code that matches nothing is
|
||||||
|
refused rather than skipped).
|
||||||
|
- **Shot Status → Bulk Actions → Log Delivery Request** for a ticked selection.
|
||||||
|
|
||||||
|
The shot list is a snapshot taken when the request is logged. The request then
|
||||||
|
sits in **Awaiting delivery** showing *"3 of 9 delivered"*, and on the
|
||||||
|
deliveries page every shot shows where it stands: not through QC, in QC, ready
|
||||||
|
to package, building, built, uploaded, delivered. **Build N ready** packages
|
||||||
|
the shots that have passed QC.
|
||||||
|
|
||||||
|
A request has no "done" button. A shot's line closes only when:
|
||||||
|
|
||||||
|
- a package containing it is shared (step 2 of marking delivered) after the
|
||||||
|
request was logged, or
|
||||||
|
- it is marked **Delivered Outside Pipeline** with the upload link and who the
|
||||||
|
link was sent to, dated on or after the day the request was logged. For a
|
||||||
|
shot on an open request those two fields are required.
|
||||||
|
|
||||||
|
The request closes when every line has. A delivery made *before* the request
|
||||||
|
was logged does not count — a client asking again is asking for it again. The
|
||||||
|
only other way out is **Cancel request**, which needs a reason and stays in the
|
||||||
|
history.
|
||||||
|
|
||||||
|
The *Wanted* field (EXRs, MOVs, both) records what was asked for; it does not
|
||||||
|
change what closes a line. A MOV-only ask is closed through Delivered Outside
|
||||||
|
Pipeline, since a MOV review package has no delivered state.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -233,8 +286,12 @@ a different spec is a config change rather than a code change.
|
|||||||
| E16 | `POST` | `/api/deliveries` | Create a package and queue the build |
|
| E16 | `POST` | `/api/deliveries` | Create a package and queue the build |
|
||||||
| E17 | `GET` | `/api/deliveries` | List packages / history |
|
| E17 | `GET` | `/api/deliveries` | List packages / history |
|
||||||
| E18 | `GET` | `/api/deliveries/ready` | Ready exports grouped by episode |
|
| E18 | `GET` | `/api/deliveries/ready` | Ready exports grouped by episode |
|
||||||
| E19 | `POST` | `/api/deliveries/{id}/delivered` | Mark delivered |
|
| — | `POST` | `/api/deliveries/{id}/uploaded` | Record the upload: `{ uploadUrl, contentsConfirmed: true }` |
|
||||||
|
| E19 | `POST` | `/api/deliveries/{id}/delivered` | Record the share and mark delivered: `{ sharedWith, note? }` |
|
||||||
| — | `POST` | `/api/deliveries/{id}/cancel` | Cancel a package |
|
| — | `POST` | `/api/deliveries/{id}/cancel` | Cancel a package |
|
||||||
|
| — | `GET` | `/api/delivery-requests` | List requests with per-shot stages (`?projectId=`, `?open=1`) |
|
||||||
|
| — | `POST` | `/api/delivery-requests` | Log a request: `{ projectId, episode \| shotIds \| shotCodes, deliverable, requestedBy, dueDate?, note? }` |
|
||||||
|
| — | `POST` | `/api/delivery-requests/{id}/cancel` | Cancel a request: `{ reason }` |
|
||||||
| — | `POST` | `/api/ext/render/jobs/{jobId}/delivery` | Worker reports a build (API key) |
|
| — | `POST` | `/api/ext/render/jobs/{jobId}/delivery` | Worker reports a build (API key) |
|
||||||
|
|
||||||
`POST /api/deliveries` takes `{ projectId, episode?, exportIds?, options? }`.
|
`POST /api/deliveries` takes `{ projectId, episode?, exportIds?, options? }`.
|
||||||
|
|||||||
@@ -1073,6 +1073,8 @@ Timecode is the check this engine exists for. It is validated **against the sour
|
|||||||
| 2 | Plate re-derived on the worker from the footage root + shot code (manifestVersion 1, or a timing plate that no longer resolves). If elements disagree, the one matching the render's frame count wins; still ambiguous → WARN, never PASS | PASS / FAIL, `reference: "derived"` |
|
| 2 | Plate re-derived on the worker from the footage root + shot code (manifestVersion 1, or a timing plate that no longer resolves). If elements disagree, the one matching the render's frame count wins; still ambiguous → WARN, never PASS | PASS / FAIL, `reference: "derived"` |
|
||||||
| 3 | API `Shot.timecodeStart` **minus `handleFrames`** | **WARN only, never PASS** — `reference: "api"`, message states the plate could not be read |
|
| 3 | API `Shot.timecodeStart` **minus `handleFrames`** | **WARN only, never PASS** — `reference: "api"`, message states the plate could not be read |
|
||||||
|
|
||||||
|
**Several delivered elements.** When the rank-1 timing plate does not match, the worker tries the manifest's other `plates[]` before failing — the panel's longest-duration pick is not always the element the comp was anchored to. A match against one of them is a PASS naming that element; no match still FAILs against the timing plate, listing the others tried. Only delivered footage qualifies: plates under a configured plate search root, or (with none configured) alongside the timing plate in its footage folder. `plates[]` also holds pre-renders, which agree with the render by construction and must never rescue it.
|
||||||
|
|
||||||
Rank 3 is a diagnostic, not a verification: it depends on the show's handle count being correct for that specific plate, which is exactly the assumption the defects above violate.
|
Rank 3 is a diagnostic, not a verification: it depends on the show's handle count being correct for that specific plate, which is exactly the assumption the defects above violate.
|
||||||
|
|
||||||
**Comparison, given the plate reference:**
|
**Comparison, given the plate reference:**
|
||||||
@@ -1177,6 +1179,27 @@ Not every export is framed like its review. A deliverable rendered unscaled or w
|
|||||||
|
|
||||||
With no earlier export to inherit from, the export still reaches READY_FOR_QC and the timeline records that it has no review media.
|
With no earlier export to inherit from, the export still reaches READY_FOR_QC and the timeline records that it has no review media.
|
||||||
|
|
||||||
|
### 9.5 Handles in review (metadata only)
|
||||||
|
|
||||||
|
Renders run past the cut at each end (8 + 8 by house convention). Handles ship with the EXRs and stay in the preview, but reviewers must be able to tell them from the cut, or a glitch in a handle gets flagged as a problem in the shot. **Nothing is trimmed or burned in** — this is deliberately not the reverted picture-lock trim (which desynced the overlay timecode); the render and every delivered file are unchanged.
|
||||||
|
|
||||||
|
- **Panel:** "Includes handles [8] frames each end" (default on, prefilled from Handle Frames) sends `manifest.review = { handleHead, handleTail }`; unticked sends 0/0. Manifests without `review` (older panels) fall back to `source.handleFrames` (`manifestHandles`, exports.ts).
|
||||||
|
- **Export → Version:** `createExport` stores `Export.handleHead/handleTail`; `finalizePreview` copies them onto the Version, plus `pictureStartFrame` = the head slate length from the build's `pictureStartSeconds` (worker ≥ 1.6.4). Left null, the player infers the slate as MP4 frames − `frameCount` (the EXR count), within 0–5 frames.
|
||||||
|
- **Player** (`lib/handles.ts` → `computeEditRange`): the timeline hatches the handles amber and labels them HANDLE (the slate, SLATE); while the playhead is in a handle the picture gets an amber frame and a "HEAD/TAIL HANDLE · NOT IN EDIT" tag; notes on handle frames carry a HANDLE badge. "Edit range only" (scissors) keeps play, reverse and go-to-start/end inside the cut — on by default in the client portal, off for staff.
|
||||||
|
- **Staff override:** the review page's Handles button edits a version's head/tail/slate — for manual uploads, or to correct a render.
|
||||||
|
- **Backfill** (`20260922000000_version_handles`): every existing export takes its manifest's `source.handleFrames` (else 8), and the Versions they produced take the same.
|
||||||
|
|
||||||
|
### 9.6 High quality playback and the ProRes download
|
||||||
|
|
||||||
|
The Standard review MP4 is AE's H.264 (UHD, ~35 Mbps). ProRes itself can't be the player's source — only Safari on a Mac decodes it in a web page, and UHD ProRes LT is ~280 Mbps — so the worker (≥ 1.7.0, when `preview.highQuality` is on) adds two things after the AE render, both **best-effort** (a failure costs the extras, never the preview):
|
||||||
|
|
||||||
|
- **High quality MP4:** ffmpeg re-encodes the delivery MOV as full-res H.264 High, CRF 14 capped at 100 Mbps, yuv420p, faststart → `Version.hqFileUrl`. The player shows an **HQ** switch when present; switching keeps frame, play state, speed and zoom, is remembered per browser (`review:quality`), and falls back to Standard if the file won't load. Same comp as the Standard MP4, so slate and handles line up frame for frame.
|
||||||
|
- **ProRes download:** the MOV itself is uploaded (presign kind `highres`) → `Version.highResKey/highResFilename/highResSize`. It is the version's **High Res** download in the client portal (named with the client code, `clientHighResFilename`) and a **ProRes** button on the staff review page. The shot's manually uploaded High Res remains the fallback for versions without one. Since worker 1.7.1 the MOV uploads **in the background after finalize** (`HighResUploader`, queue in `%ProgramData%\VFXReviewWorker\highres-queue`, resumes after a restart, 5 attempts) and attaches via `POST /api/ext/render/jobs/{id}/attach-highres` (E13b); a MOV from a preview that a newer preview has superseded is discarded. While a preview job uploads, the worker replaces the job's log tail with live upload status. Since 1.7.2, artifacts of 16 MB or more upload as S3 multipart: `artifact-presign` with `multipart: true, size` returns `uploadId`, `partSize` (8 MB minimum) and one presigned URL per part; the worker PUTs parts on `uploadConcurrency` connections (default 16), retries each part up to 4 times, then calls `artifact-complete` (E20b) to stitch them, or with `abort: true` to discard them. A single connection from the studio to nbg1 is capped near 0.1 MB/s.
|
||||||
|
|
||||||
|
A lease keep-alive runs during the encode and uploads (they can outlast the 300 s lease). The export timeline records what was attached.
|
||||||
|
|
||||||
|
**Housekeeping** (`lib/render-pipeline/high-res.ts`): a version keeps its HQ MP4 and ProRes while it is the task's latest, shared with the client, approved, or younger than `preview.highResRetentionDays` (14). Otherwise both are deleted from storage and the row gets `highResPrunedAt`; the Standard MP4 is never touched. It runs for the task after every finalize and studio-wide hourly from the reaper; deleting a version deletes its files. A reslate replaces (and deletes) the version's previous HQ/ProRes.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 10. QC Workflow
|
## 10. QC Workflow
|
||||||
|
|||||||
@@ -208,6 +208,9 @@ read back from the assembly, so a machine can never report a version it is not r
|
|||||||
`pathMappings` translate the manifest's canonical UNC paths to this machine's drive
|
`pathMappings` translate the manifest's canonical UNC paths to this machine's drive
|
||||||
mappings. `plateSearchRoots` is optional: it is only consulted when a manifest carries no
|
mappings. `plateSearchRoots` is optional: it is only consulted when a manifest carries no
|
||||||
timing plate (older panel versions), to find the shot's plates for the timecode check.
|
timing plate (older panel versions), to find the shot's plates for the timecode check.
|
||||||
|
`uploadConcurrency` (default 16) is how many parallel connections a file of 16 MB or more
|
||||||
|
uploads over. Each connection to object storage is capped near 0.1 MB/s from the studio, so
|
||||||
|
throughput scales with it (measured 2026-10-01: 1 → 0.13 MB/s, 8 → 0.64, 24 → 1.69 MB/s).
|
||||||
Everything tunable (poll interval, lease, stall timeout, max attempts, validation) lives in
|
Everything tunable (poll interval, lease, stall timeout, max attempts, validation) lives in
|
||||||
the server's SystemConfig and arrives at registration — no per-machine tuning files.
|
the server's SystemConfig and arrives at registration — no per-machine tuning files.
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,46 @@ public class BlenderProgressParserTests
|
|||||||
Assert.Equal(1002, frames[^1]);
|
Assert.Equal(1002, frames[^1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Blender 5.x prefixes every line with elapsed time and a log category.
|
||||||
|
/// Anchored on "Saved:", the parser counted no frames from a render that
|
||||||
|
/// wrote every one, and the job failed as "saved no frames".
|
||||||
|
/// These lines are verbatim Blender 5.2 output.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ParsesBlender5PrefixedOutput()
|
||||||
|
{
|
||||||
|
Assert.Equal(@"X:\renders\frame_0001.png",
|
||||||
|
BlenderProgressParser.ParseSaved(@"00:02.954 render | Saved: 'X:\renders\frame_0001.png'"));
|
||||||
|
Assert.Equal(1, BlenderProgressParser.ParseFrame("00:02.469 render | Fra: 1 | Mem: 0M | Synchronizing object | Cube"));
|
||||||
|
Assert.Null(BlenderProgressParser.ParseSaved("00:02.954 render | Time: 00:00.87 (Saving: 00:00.14)"));
|
||||||
|
Assert.Null(BlenderProgressParser.ParseFrame("00:02.079 render | Rendering frame 1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RecognisesBlender5Errors()
|
||||||
|
{
|
||||||
|
const string unwritable = @"00:03.063 reports | ERROR Render error (No such file or directory) cannot save: 'Q:\out\f_0001.png'";
|
||||||
|
Assert.True(BlenderProgressParser.IsErrorLine(unwritable));
|
||||||
|
Assert.True(BlenderProgressParser.IsNonRetryableError(unwritable));
|
||||||
|
|
||||||
|
const string missing = @"00:13.250 reports | ERROR Cannot read file ""X:\gone.blend"": No such file or directory";
|
||||||
|
Assert.True(BlenderProgressParser.IsErrorLine(missing));
|
||||||
|
Assert.True(BlenderProgressParser.IsNonRetryableError(missing));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add-ons print warnings on every launch; one must never become the
|
||||||
|
/// reported reason a render failed.
|
||||||
|
/// </summary>
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Warning: add-on missing 'bl_info', this can cause poor performance!: 'G:\\addons\\x\\__init__.py'")]
|
||||||
|
[InlineData("00:01.000 addon | WARNING something harmless")]
|
||||||
|
public void WarningsAreNotErrors(string line)
|
||||||
|
{
|
||||||
|
Assert.False(BlenderProgressParser.IsErrorLine(line));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Mirrors BlenderRunner.PumpAsync: CR and LF both end a line.</summary>
|
/// <summary>Mirrors BlenderRunner.PumpAsync: CR and LF both end a line.</summary>
|
||||||
private static List<string> SplitLikeThePump(string text)
|
private static List<string> SplitLikeThePump(string text)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,205 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using VFXReviewWorker;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VFXReviewWorker.Tests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Large artifacts go up as parallel multipart parts: from the studio a single
|
||||||
|
/// connection to object storage is capped near 0.1 MB/s, so a ProRes MOV could
|
||||||
|
/// not finish inside the 30 min request timeout. These drive the real upload
|
||||||
|
/// code against a local fake of the server + storage.
|
||||||
|
/// </summary>
|
||||||
|
public class MultipartUploadTests : IDisposable
|
||||||
|
{
|
||||||
|
private const int PartSize = 8 * 1024 * 1024;
|
||||||
|
|
||||||
|
private readonly HttpListener _listener = new();
|
||||||
|
private readonly string _base;
|
||||||
|
private readonly ConcurrentDictionary<int, byte[]> _parts = new();
|
||||||
|
private readonly ConcurrentDictionary<int, int> _failuresLeft = new();
|
||||||
|
private readonly ConcurrentBag<string> _completions = new();
|
||||||
|
private int _inFlight, _maxInFlight;
|
||||||
|
private bool _multipartSupported = true;
|
||||||
|
private byte[]? _singlePut;
|
||||||
|
|
||||||
|
public MultipartUploadTests()
|
||||||
|
{
|
||||||
|
var port = FreePort();
|
||||||
|
_base = $"http://localhost:{port}/";
|
||||||
|
_listener.Prefixes.Add(_base);
|
||||||
|
_listener.Start();
|
||||||
|
_ = Task.Run(Serve);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int FreePort()
|
||||||
|
{
|
||||||
|
var l = new TcpListener(IPAddress.Loopback, 0);
|
||||||
|
l.Start();
|
||||||
|
var port = ((IPEndPoint)l.LocalEndpoint).Port;
|
||||||
|
l.Stop();
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Serve()
|
||||||
|
{
|
||||||
|
while (_listener.IsListening)
|
||||||
|
{
|
||||||
|
HttpListenerContext ctx;
|
||||||
|
try { ctx = await _listener.GetContextAsync(); } catch { return; }
|
||||||
|
_ = Task.Run(() => Handle(ctx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Handle(HttpListenerContext ctx)
|
||||||
|
{
|
||||||
|
var path = ctx.Request.Url!.AbsolutePath;
|
||||||
|
using var ms = new MemoryStream();
|
||||||
|
await ctx.Request.InputStream.CopyToAsync(ms);
|
||||||
|
var body = ms.ToArray();
|
||||||
|
var res = ctx.Response;
|
||||||
|
|
||||||
|
if (path.EndsWith("/artifact-presign"))
|
||||||
|
{
|
||||||
|
var req = JsonDocument.Parse(body).RootElement;
|
||||||
|
var size = req.GetProperty("size").GetInt64();
|
||||||
|
object payload = _multipartSupported && req.GetProperty("multipart").GetBoolean()
|
||||||
|
? new
|
||||||
|
{
|
||||||
|
key = "highres/x.mov",
|
||||||
|
uploadId = "up1",
|
||||||
|
partSize = PartSize,
|
||||||
|
partUrls = Enumerable.Range(1, (int)((size + PartSize - 1) / PartSize))
|
||||||
|
.Select(n => $"{_base}part/{n}").ToList(),
|
||||||
|
}
|
||||||
|
: new { key = "highres/x.mov", presignedUrl = $"{_base}single" };
|
||||||
|
await Json(res, payload);
|
||||||
|
}
|
||||||
|
else if (path.StartsWith("/part/"))
|
||||||
|
{
|
||||||
|
var n = int.Parse(path["/part/".Length..]);
|
||||||
|
var now = Interlocked.Increment(ref _inFlight);
|
||||||
|
InterlockedMax(ref _maxInFlight, now);
|
||||||
|
await Task.Delay(50);
|
||||||
|
Interlocked.Decrement(ref _inFlight);
|
||||||
|
if (_failuresLeft.TryGetValue(n, out var left) && left > 0)
|
||||||
|
{
|
||||||
|
_failuresLeft[n] = left - 1;
|
||||||
|
res.StatusCode = 500;
|
||||||
|
res.Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_parts[n] = body;
|
||||||
|
res.Headers["ETag"] = $"\"etag-{n}\"";
|
||||||
|
res.Close();
|
||||||
|
}
|
||||||
|
else if (path == "/single")
|
||||||
|
{
|
||||||
|
_singlePut = body;
|
||||||
|
res.Close();
|
||||||
|
}
|
||||||
|
else if (path.EndsWith("/artifact-complete"))
|
||||||
|
{
|
||||||
|
_completions.Add(System.Text.Encoding.UTF8.GetString(body));
|
||||||
|
await Json(res, new { ok = true });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.StatusCode = 404;
|
||||||
|
res.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void InterlockedMax(ref int target, int value)
|
||||||
|
{
|
||||||
|
int seen;
|
||||||
|
while ((seen = Volatile.Read(ref target)) < value && Interlocked.CompareExchange(ref target, value, seen) != seen) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task Json(HttpListenerResponse res, object payload)
|
||||||
|
{
|
||||||
|
var bytes = JsonSerializer.SerializeToUtf8Bytes(payload, WorkerOptions.JsonOpts);
|
||||||
|
res.ContentType = "application/json";
|
||||||
|
await res.OutputStream.WriteAsync(bytes);
|
||||||
|
res.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiClient Client(int concurrency = 4) =>
|
||||||
|
new(new WorkerOptions { ServerUrl = _base, ApiKey = "k", UploadConcurrency = concurrency },
|
||||||
|
NullLogger<ApiClient>.Instance);
|
||||||
|
|
||||||
|
private static string TempFile(int bytes)
|
||||||
|
{
|
||||||
|
var path = Path.GetTempFileName();
|
||||||
|
var data = new byte[bytes];
|
||||||
|
new Random(42).NextBytes(data);
|
||||||
|
File.WriteAllBytes(path, data);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Uploads_parts_in_parallel_and_stitches_them_in_order()
|
||||||
|
{
|
||||||
|
var file = TempFile(PartSize * 5 + 12345);
|
||||||
|
long lastProgress = 0;
|
||||||
|
var key = await Client(4).UploadArtifactAsync("job1", "m1", "highres", file, "video/quicktime",
|
||||||
|
CancellationToken.None, sent => Interlocked.Exchange(ref lastProgress, sent));
|
||||||
|
|
||||||
|
Assert.Equal("highres/x.mov", key);
|
||||||
|
var stitched = Enumerable.Range(1, 6).SelectMany(n => _parts[n]).ToArray();
|
||||||
|
Assert.Equal(File.ReadAllBytes(file), stitched);
|
||||||
|
Assert.True(_maxInFlight > 1, "parts should upload concurrently");
|
||||||
|
Assert.True(_maxInFlight <= 4, "concurrency is capped by UploadConcurrency");
|
||||||
|
Assert.Equal(new FileInfo(file).Length, Interlocked.Read(ref lastProgress));
|
||||||
|
|
||||||
|
var complete = JsonDocument.Parse(Assert.Single(_completions)).RootElement;
|
||||||
|
Assert.False(complete.TryGetProperty("abort", out _));
|
||||||
|
Assert.Equal(6, complete.GetProperty("parts").GetArrayLength());
|
||||||
|
Assert.Equal("\"etag-1\"", complete.GetProperty("parts")[0].GetProperty("etag").GetString());
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task A_failed_part_is_retried_on_its_own()
|
||||||
|
{
|
||||||
|
var file = TempFile(PartSize * 3);
|
||||||
|
_failuresLeft[2] = 2;
|
||||||
|
var key = await Client().UploadArtifactAsync("job1", "m1", "highres", file, "video/quicktime", CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.NotNull(key);
|
||||||
|
Assert.Equal(File.ReadAllBytes(file), Enumerable.Range(1, 3).SelectMany(n => _parts[n]).ToArray());
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task A_part_that_keeps_failing_aborts_the_upload()
|
||||||
|
{
|
||||||
|
var file = TempFile(PartSize * 3);
|
||||||
|
_failuresLeft[3] = 99;
|
||||||
|
var key = await Client().UploadArtifactAsync("job1", "m1", "highres", file, "video/quicktime", CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Null(key);
|
||||||
|
var abort = JsonDocument.Parse(Assert.Single(_completions)).RootElement;
|
||||||
|
Assert.True(abort.GetProperty("abort").GetBoolean());
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Falls_back_to_a_single_put_on_a_server_without_multipart()
|
||||||
|
{
|
||||||
|
_multipartSupported = false;
|
||||||
|
var file = TempFile(PartSize * 3);
|
||||||
|
var key = await Client().UploadArtifactAsync("job1", "m1", "highres", file, "video/quicktime", CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal("highres/x.mov", key);
|
||||||
|
Assert.Equal(File.ReadAllBytes(file), _singlePut);
|
||||||
|
Assert.Empty(_completions);
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() => _listener.Close();
|
||||||
|
}
|
||||||
@@ -70,6 +70,59 @@ public class PrepareOutputDirTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The version folder holds the preview MOV/MP4 built from the same
|
||||||
|
/// basename. A shot re-rendered at the same version — the "No preview"
|
||||||
|
/// workflow, where the EXRs are re-exported unscaled and the earlier MOV is
|
||||||
|
/// inherited as the review media — must not have that MOV cleared out from
|
||||||
|
/// under it before aerender starts.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void KeepsPreviewMediaSharingThePatternPrefix()
|
||||||
|
{
|
||||||
|
var dir = Path.Combine(Path.GetTempPath(), "vfxr-test-" + Guid.NewGuid().ToString("N"));
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr"), "old");
|
||||||
|
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.mov"), "delivery mov");
|
||||||
|
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.mp4"), "review mp4");
|
||||||
|
|
||||||
|
AerenderRunner.PrepareOutputDir(dir, "SHOT_cmp_TT_v004.[####].exr");
|
||||||
|
|
||||||
|
Assert.False(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr")));
|
||||||
|
Assert.True(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.mov")));
|
||||||
|
Assert.True(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.mp4")));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Directory.Delete(dir, recursive: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ClearsOnlyThisVersionsFrames()
|
||||||
|
{
|
||||||
|
var dir = Path.Combine(Path.GetTempPath(), "vfxr-test-" + Guid.NewGuid().ToString("N"));
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr"), "old");
|
||||||
|
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v005.1001.exr"), "other version");
|
||||||
|
File.WriteAllText(Path.Combine(dir, "OTHERSHOT_cmp_TT_v004.1001.exr"), "other shot");
|
||||||
|
|
||||||
|
AerenderRunner.PrepareOutputDir(dir, "SHOT_cmp_TT_v004.[####].exr");
|
||||||
|
|
||||||
|
Assert.False(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr")));
|
||||||
|
Assert.True(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v005.1001.exr")));
|
||||||
|
Assert.True(File.Exists(Path.Combine(dir, "OTHERSHOT_cmp_TT_v004.1001.exr")));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Directory.Delete(dir, recursive: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CreatesMissingDirectory()
|
public void CreatesMissingDirectory()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -117,4 +117,21 @@ public class LogTailTests
|
|||||||
for (var i = 1; i <= 5; i++) tail.Add($"line {i}");
|
for (var i = 1; i <= 5; i++) tail.Add($"line {i}");
|
||||||
Assert.Equal("line 3\nline 4\nline 5", tail.ToString());
|
Assert.Equal("line 3\nline 4\nline 5", tail.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ReadingWhileAnotherThreadWritesDoesNotThrow()
|
||||||
|
{
|
||||||
|
// The Blender runner's output pumps add lines while its progress loop
|
||||||
|
// reads the tail; unsynchronised this threw "Collection was modified".
|
||||||
|
var tail = new LogTail(200);
|
||||||
|
using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(1));
|
||||||
|
var writer = Task.Run(() =>
|
||||||
|
{
|
||||||
|
var i = 0;
|
||||||
|
while (!stop.IsCancellationRequested) tail.Add($"Fra:1001 Sample {i++}/128");
|
||||||
|
});
|
||||||
|
|
||||||
|
while (!stop.IsCancellationRequested) _ = tail.ToString();
|
||||||
|
await writer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,74 @@ public class ValidationStageTests : IDisposable
|
|||||||
Assert.Contains("8-frame handle", tc.Message);
|
Assert.Contains("8-frame handle", tc.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Writes a one-frame plate into a footage-style element folder.</summary>
|
||||||
|
private string WritePlate(string element, string timecode, int fps = 24)
|
||||||
|
{
|
||||||
|
var plate = Path.Combine(_dir, "footage", $"UNG_107_051_010_{element}_TT_v001", $"UNG_107_051_010_{element}_TT_v001.01001.exr");
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(plate)!);
|
||||||
|
File.Move(ExrFixture.Write(timecode, 3840, 2160, new[] { ("B", 1), ("G", 1), ("R", 1) }, fps, 4), plate);
|
||||||
|
return plate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ManifestSource Source(string timingPlate, params string[] plates) => new()
|
||||||
|
{
|
||||||
|
TimingPlate = new PlateRef { Path = timingPlate, FrameStart = 1001 },
|
||||||
|
Plates = plates.Select(p => new PlateRef { Path = p, FrameStart = 1001 }).ToList(),
|
||||||
|
HandleFrames = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AnotherDeliveredPlatePassesWhenTheTimingPlateDoesNot()
|
||||||
|
{
|
||||||
|
// The comp was anchored to FG01, but the panel named BG01 (longest) as
|
||||||
|
// the timing plate — the two carry unrelated camera timecodes.
|
||||||
|
WriteSequence(105, "09:12:00:00");
|
||||||
|
var bg = WritePlate("BG01", "14:26:31:08");
|
||||||
|
var fg = WritePlate("FG01", "09:12:00:00");
|
||||||
|
|
||||||
|
var manifest = Manifest(_dir, null, 1001);
|
||||||
|
manifest.Source = Source(bg, bg, fg);
|
||||||
|
|
||||||
|
var tc = Check(NewStage().Run(manifest, _dir, new ServerConfig()), "timecode_plate_match");
|
||||||
|
Assert.Equal("PASS", tc.Status);
|
||||||
|
Assert.Contains("UNG_107_051_010_FG01_TT_v001.01001.exr", tc.Message);
|
||||||
|
Assert.Contains("BG01", tc.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void NoMatchingPlateStillFailsAgainstTheTimingPlate()
|
||||||
|
{
|
||||||
|
WriteSequence(105, "14:26:31:16");
|
||||||
|
var bg = WritePlate("BG01", "14:26:31:08");
|
||||||
|
var fg = WritePlate("FG01", "09:12:00:00");
|
||||||
|
|
||||||
|
var manifest = Manifest(_dir, null, 1001);
|
||||||
|
manifest.Source = Source(bg, bg, fg);
|
||||||
|
|
||||||
|
var tc = Check(NewStage().Run(manifest, _dir, new ServerConfig()), "timecode_plate_match");
|
||||||
|
Assert.Equal("FAIL", tc.Status);
|
||||||
|
Assert.Equal("14:26:31:08", tc.Expected);
|
||||||
|
Assert.Contains("8-frame handle", tc.Message);
|
||||||
|
Assert.Contains("1 other delivered plate", tc.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void APreRenderIsNeverUsedAsTheFallbackPlate()
|
||||||
|
{
|
||||||
|
// plates[] is every file in the comp. A pre-render was rendered from
|
||||||
|
// this comp, so it agrees with the render whether or not either is right.
|
||||||
|
WriteSequence(105, "14:26:31:16");
|
||||||
|
var bg = WritePlate("BG01", "14:26:31:08");
|
||||||
|
var preRender = Path.Combine(_dir, "renders", "prerender", "UNG_107_051_010_PRERENDER_01001.exr");
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(preRender)!);
|
||||||
|
File.Move(ExrFixture.Write("14:26:31:16", 3840, 2160, new[] { ("B", 1), ("G", 1), ("R", 1) }, 24, 4), preRender);
|
||||||
|
|
||||||
|
var manifest = Manifest(_dir, null, 1001);
|
||||||
|
manifest.Source = Source(bg, bg, preRender);
|
||||||
|
|
||||||
|
Assert.Equal("FAIL", Check(NewStage().Run(manifest, _dir, new ServerConfig()), "timecode_plate_match").Status);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void APlateAtADifferentRateFailsPlateFps()
|
public void APlateAtADifferentRateFailsPlateFps()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -234,26 +234,30 @@ public sealed class AerenderRunner
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// §7.3: outputDir is created before launch; a pre-existing non-empty dir
|
/// §7.3: outputDir is created before launch; a pre-existing dir can hold
|
||||||
/// can only hold output from a previous crashed attempt of this same
|
/// frames from a previous crashed attempt, which aerender would otherwise
|
||||||
/// immutable version. Safety guard: only files matching the job's own
|
/// leave interleaved with this attempt's. Safety guard: only files matching
|
||||||
/// output pattern prefix are ever deleted.
|
/// the job's own output pattern — its prefix *and* its extension — are ever
|
||||||
|
/// deleted.
|
||||||
|
///
|
||||||
|
/// The extension is not optional. The version folder is shared with the
|
||||||
|
/// preview stage, whose MOV and MP4 are built from the same basename
|
||||||
|
/// (preview.ts: `{outputDir}/{base}.mov`), so prefix alone also matches
|
||||||
|
/// them. A version folder can legitimately be rendered into twice — the
|
||||||
|
/// output path is keyed on the shot's manually-set version, not on the
|
||||||
|
/// export — and on a no-preview re-render (Export.skipPreview) the media
|
||||||
|
/// that gets inherited is precisely the MOV sitting in this folder.
|
||||||
|
/// Deleting it left the export pointing at a file that no longer existed,
|
||||||
|
/// and delivery silently packaged the EXRs without their viewing copy.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <summary>Filename prefix of an output pattern ("X.[####].exr" → "X").</summary>
|
|
||||||
internal static string OutputPatternPrefix(string outputPattern)
|
|
||||||
{
|
|
||||||
var bracket = outputPattern.IndexOf('[');
|
|
||||||
return bracket > 0 ? outputPattern[..bracket].TrimEnd('.') : Path.GetFileNameWithoutExtension(outputPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void PrepareOutputDir(string outputDirLocal, string outputPattern)
|
internal static void PrepareOutputDir(string outputDirLocal, string outputPattern)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(outputDirLocal);
|
Directory.CreateDirectory(outputDirLocal);
|
||||||
var prefix = OutputPatternPrefix(outputPattern);
|
var pattern = SequencePattern.FromOutputPattern(outputPattern);
|
||||||
if (string.IsNullOrEmpty(prefix)) return;
|
if (string.IsNullOrEmpty(pattern.Prefix)) return;
|
||||||
foreach (var file in Directory.EnumerateFiles(outputDirLocal))
|
foreach (var file in Directory.EnumerateFiles(outputDirLocal))
|
||||||
{
|
{
|
||||||
if (Path.GetFileName(file).StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
if (pattern.MatchesOutputFile(Path.GetFileName(file)))
|
||||||
{
|
{
|
||||||
try { File.Delete(file); } catch { /* locked leftovers surface as an aerender error */ }
|
try { File.Delete(file); } catch { /* locked leftovers surface as an aerender error */ }
|
||||||
}
|
}
|
||||||
@@ -276,11 +280,19 @@ public sealed class AerenderRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Ring buffer of the last N output lines (§5.3 logTail).</summary>
|
/// <summary>
|
||||||
|
/// Ring buffer of the last N output lines (§5.3 logTail).
|
||||||
|
///
|
||||||
|
/// Thread-safe: output readers add lines while the progress loop reads the
|
||||||
|
/// tail for its report. Unsynchronised, ToString enumerates the queue while a
|
||||||
|
/// reader enqueues and throws "Collection was modified" — Blender, which
|
||||||
|
/// writes a status line many times a second, hit this on every job.
|
||||||
|
/// </summary>
|
||||||
public sealed class LogTail
|
public sealed class LogTail
|
||||||
{
|
{
|
||||||
private readonly Queue<string> _lines;
|
private readonly Queue<string> _lines;
|
||||||
private readonly int _capacity;
|
private readonly int _capacity;
|
||||||
|
private readonly object _gate = new();
|
||||||
|
|
||||||
public LogTail(int capacity)
|
public LogTail(int capacity)
|
||||||
{
|
{
|
||||||
@@ -289,10 +301,16 @@ public sealed class LogTail
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Add(string line)
|
public void Add(string line)
|
||||||
|
{
|
||||||
|
lock (_gate)
|
||||||
{
|
{
|
||||||
_lines.Enqueue(line);
|
_lines.Enqueue(line);
|
||||||
while (_lines.Count > _capacity) _lines.Dequeue();
|
while (_lines.Count > _capacity) _lines.Dequeue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public override string ToString() => string.Join('\n', _lines);
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
lock (_gate) return string.Join('\n', _lines);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,16 @@ namespace VFXReviewWorker;
|
|||||||
public sealed class ApiClient
|
public sealed class ApiClient
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
private readonly HttpClient _http;
|
||||||
|
private readonly WorkerOptions _options;
|
||||||
private readonly ILogger<ApiClient> _log;
|
private readonly ILogger<ApiClient> _log;
|
||||||
|
|
||||||
|
// Presigned uploads: a separate client so the URL is not sent with our
|
||||||
|
// Authorization header, and a generous per-request timeout for media.
|
||||||
|
private static readonly HttpClient _upload = new() { Timeout = TimeSpan.FromMinutes(30) };
|
||||||
|
|
||||||
public ApiClient(WorkerOptions options, ILogger<ApiClient> log)
|
public ApiClient(WorkerOptions options, ILogger<ApiClient> log)
|
||||||
{
|
{
|
||||||
|
_options = options;
|
||||||
_log = log;
|
_log = log;
|
||||||
_http = new HttpClient
|
_http = new HttpClient
|
||||||
{
|
{
|
||||||
@@ -124,6 +130,7 @@ public sealed class ApiClient
|
|||||||
"validation" => $"api/ext/render/jobs/{jobId}/validation",
|
"validation" => $"api/ext/render/jobs/{jobId}/validation",
|
||||||
"delivery" => $"api/ext/render/jobs/{jobId}/delivery",
|
"delivery" => $"api/ext/render/jobs/{jobId}/delivery",
|
||||||
"finalize" => $"api/ext/render/jobs/{jobId}/finalize",
|
"finalize" => $"api/ext/render/jobs/{jobId}/finalize",
|
||||||
|
"attach-highres" => $"api/ext/render/jobs/{jobId}/attach-highres",
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, "unknown lifecycle report kind"),
|
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, "unknown lifecycle report kind"),
|
||||||
};
|
};
|
||||||
var res = await _http.PostAsJsonAsync(path, payload, Json, ct);
|
var res = await _http.PostAsJsonAsync(path, payload, Json, ct);
|
||||||
@@ -143,8 +150,10 @@ public sealed class ApiClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// E20 + PUT upload. Returns the storage key, or null when the upload failed.
|
// E20 + PUT upload. Returns the storage key, or null when the upload failed.
|
||||||
|
// onProgress receives the bytes sent so far, for status lines in the app.
|
||||||
public async Task<string?> UploadArtifactAsync(
|
public async Task<string?> UploadArtifactAsync(
|
||||||
string jobId, string machineId, string kind, string filePath, string contentType, CancellationToken ct)
|
string jobId, string machineId, string kind, string filePath, string contentType, CancellationToken ct,
|
||||||
|
Action<long>? onProgress = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -153,6 +162,13 @@ public sealed class ApiClient
|
|||||||
_log.LogWarning("Artifact {Kind} not found at {Path}", kind, filePath);
|
_log.LogWarning("Artifact {Kind} not found at {Path}", kind, filePath);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
var size = new FileInfo(filePath).Length;
|
||||||
|
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||||
|
// Uploads can run for many minutes on a slow uplink; without these two
|
||||||
|
// lines the log goes silent and a busy worker looks hung.
|
||||||
|
if (kind != "log")
|
||||||
|
_log.LogInformation("Uploading {Kind} for job {JobId}: {File} ({MB:F1} MB)",
|
||||||
|
kind, jobId, Path.GetFileName(filePath), size / 1048576.0);
|
||||||
|
|
||||||
var presignRes = await _http.PostAsJsonAsync($"api/ext/render/jobs/{jobId}/artifact-presign", new
|
var presignRes = await _http.PostAsJsonAsync($"api/ext/render/jobs/{jobId}/artifact-presign", new
|
||||||
{
|
{
|
||||||
@@ -160,6 +176,8 @@ public sealed class ApiClient
|
|||||||
kind,
|
kind,
|
||||||
fileName = Path.GetFileName(filePath),
|
fileName = Path.GetFileName(filePath),
|
||||||
contentType,
|
contentType,
|
||||||
|
multipart = size >= MultipartThreshold,
|
||||||
|
size,
|
||||||
}, Json, ct);
|
}, Json, ct);
|
||||||
if (!presignRes.IsSuccessStatusCode)
|
if (!presignRes.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
@@ -169,18 +187,27 @@ public sealed class ApiClient
|
|||||||
var presign = await presignRes.Content.ReadFromJsonAsync<PresignResponse>(Json, ct);
|
var presign = await presignRes.Content.ReadFromJsonAsync<PresignResponse>(Json, ct);
|
||||||
if (presign is null) return null;
|
if (presign is null) return null;
|
||||||
|
|
||||||
// Media files can be large — generous timeout, separate client so the
|
if (presign.UploadId is not null && presign.PartUrls is { Count: > 0 } && presign.PartSize > 0)
|
||||||
// presigned URL is not sent with our Authorization header.
|
|
||||||
using var upload = new HttpClient { Timeout = TimeSpan.FromMinutes(30) };
|
|
||||||
await using var stream = File.OpenRead(filePath);
|
|
||||||
var content = new StreamContent(stream);
|
|
||||||
content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
|
||||||
var putRes = await upload.PutAsync(presign.PresignedUrl, content, ct);
|
|
||||||
if (!putRes.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
_log.LogWarning("Upload of {Kind} failed: {Status}", kind, (int)putRes.StatusCode);
|
if (!await UploadMultipartAsync(jobId, machineId, kind, filePath, size, presign, onProgress, ct))
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Single PUT: small files, or a server that predates multipart.
|
||||||
|
await using var stream = File.OpenRead(filePath);
|
||||||
|
var content = new ProgressStreamContent(stream, onProgress);
|
||||||
|
content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
||||||
|
var putRes = await _upload.PutAsync(presign.PresignedUrl, content, ct);
|
||||||
|
if (!putRes.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_log.LogWarning("Upload of {Kind} failed after {Sec:F0}s: {Status}", kind, sw.Elapsed.TotalSeconds, (int)putRes.StatusCode);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (kind != "log")
|
||||||
|
_log.LogInformation("Uploaded {Kind} for job {JobId} in {Sec:F0}s ({Speed:F1} MB/s)",
|
||||||
|
kind, jobId, sw.Elapsed.TotalSeconds, size / 1048576.0 / Math.Max(0.001, sw.Elapsed.TotalSeconds));
|
||||||
return presign.Key;
|
return presign.Key;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -190,6 +217,117 @@ public sealed class ApiClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Files at least this big go up as parallel multipart parts (E20b).
|
||||||
|
private const long MultipartThreshold = 16L * 1024 * 1024;
|
||||||
|
private const int PartAttempts = 4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uploads the parts concurrently (UploadConcurrency connections), each
|
||||||
|
/// retried on its own so a dropped connection costs one part, not the
|
||||||
|
/// file; then asks the server to stitch them. Aborts on failure so the
|
||||||
|
/// stored parts don't linger in the bucket.
|
||||||
|
/// </summary>
|
||||||
|
private async Task<bool> UploadMultipartAsync(string jobId, string machineId, string kind, string filePath,
|
||||||
|
long size, PresignResponse presign, Action<long>? onProgress, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var partUrls = presign.PartUrls!;
|
||||||
|
var partSize = presign.PartSize;
|
||||||
|
var etags = new string?[partUrls.Count];
|
||||||
|
var sentPerPart = new long[partUrls.Count];
|
||||||
|
long sentTotal = 0;
|
||||||
|
var next = -1;
|
||||||
|
|
||||||
|
using var handle = File.OpenHandle(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, FileOptions.Asynchronous);
|
||||||
|
using var failed = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||||
|
|
||||||
|
async Task Worker()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
while ((i = Interlocked.Increment(ref next)) < partUrls.Count && !failed.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
var offset = i * partSize;
|
||||||
|
var len = (int)Math.Min(partSize, size - offset);
|
||||||
|
var buffer = new byte[len];
|
||||||
|
var read = 0;
|
||||||
|
while (read < len) read += await RandomAccess.ReadAsync(handle, buffer.AsMemory(read), offset + read, failed.Token);
|
||||||
|
|
||||||
|
for (var attempt = 1; ; attempt++)
|
||||||
|
{
|
||||||
|
var part = i;
|
||||||
|
// Progress restarts from zero for a retried part.
|
||||||
|
Interlocked.Add(ref sentTotal, -Interlocked.Exchange(ref sentPerPart[part], 0));
|
||||||
|
var content = new ProgressStreamContent(new MemoryStream(buffer, writable: false), sent =>
|
||||||
|
{
|
||||||
|
var delta = sent - Interlocked.Exchange(ref sentPerPart[part], sent);
|
||||||
|
onProgress?.Invoke(Interlocked.Add(ref sentTotal, delta));
|
||||||
|
});
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var res = await _upload.PutAsync(partUrls[i], content, failed.Token);
|
||||||
|
var etag = res.Headers.ETag?.Tag
|
||||||
|
?? (res.Headers.TryGetValues("ETag", out var v) ? v.FirstOrDefault() : null);
|
||||||
|
if (res.IsSuccessStatusCode && etag is not null)
|
||||||
|
{
|
||||||
|
etags[i] = etag;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_log.LogWarning("Part {Part}/{Count} of {Kind} for job {JobId} failed: {Status} (attempt {N}/{Max})",
|
||||||
|
i + 1, partUrls.Count, kind, jobId, (int)res.StatusCode, attempt, PartAttempts);
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (!failed.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
_log.LogWarning("Part {Part}/{Count} of {Kind} for job {JobId} failed: {Error} (attempt {N}/{Max})",
|
||||||
|
i + 1, partUrls.Count, kind, jobId, ex.Message, attempt, PartAttempts);
|
||||||
|
}
|
||||||
|
if (attempt >= PartAttempts)
|
||||||
|
{
|
||||||
|
failed.Cancel(); // no point finishing the other parts
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(5 * attempt), failed.Token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var concurrency = Math.Clamp(_options.UploadConcurrency, 1, 64);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.WhenAll(Enumerable.Range(0, Math.Min(concurrency, partUrls.Count)).Select(_ => Task.Run(Worker)));
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
// a part gave up, or shutdown — either way the upload is aborted below
|
||||||
|
}
|
||||||
|
|
||||||
|
var complete = !failed.IsCancellationRequested && etags.All(e => e is not null);
|
||||||
|
if (complete)
|
||||||
|
{
|
||||||
|
var res = await _http.PostAsJsonAsync($"api/ext/render/jobs/{jobId}/artifact-complete", new
|
||||||
|
{
|
||||||
|
machineId,
|
||||||
|
key = presign.Key,
|
||||||
|
uploadId = presign.UploadId,
|
||||||
|
parts = etags.Select((etag, i) => new { partNumber = i + 1, etag }),
|
||||||
|
}, Json, ct);
|
||||||
|
if (res.IsSuccessStatusCode) return true;
|
||||||
|
_log.LogWarning("Completing multipart {Kind} for job {JobId} failed: {Status} {Body}",
|
||||||
|
kind, jobId, (int)res.StatusCode, await res.Content.ReadAsStringAsync(ct));
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _http.PostAsJsonAsync($"api/ext/render/jobs/{jobId}/artifact-complete", new
|
||||||
|
{
|
||||||
|
machineId,
|
||||||
|
key = presign.Key,
|
||||||
|
uploadId = presign.UploadId,
|
||||||
|
abort = true,
|
||||||
|
}, Json, CancellationToken.None);
|
||||||
|
}
|
||||||
|
catch { /* parts expire on their own */ }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public Task<string?> UploadLogAsync(string jobId, string machineId, string logFilePath, CancellationToken ct) =>
|
public Task<string?> UploadLogAsync(string jobId, string machineId, string logFilePath, CancellationToken ct) =>
|
||||||
UploadArtifactAsync(jobId, machineId, "log", logFilePath, "text/plain", ct);
|
UploadArtifactAsync(jobId, machineId, "log", logFilePath, "text/plain", ct);
|
||||||
|
|
||||||
|
|||||||
@@ -8,18 +8,36 @@ namespace VFXReviewWorker;
|
|||||||
/// with "Saved: '...'". The saved lines are the reliable signal — a frame can
|
/// with "Saved: '...'". The saved lines are the reliable signal — a frame can
|
||||||
/// be reported for a long time while it renders — so progress counts those and
|
/// be reported for a long time while it renders — so progress counts those and
|
||||||
/// falls back to Fra: for a first sign of life.
|
/// falls back to Fra: for a first sign of life.
|
||||||
|
///
|
||||||
|
/// Blender 5.x logs through CLOG, which prefixes every line with an elapsed
|
||||||
|
/// time and a category ("00:02.954 render | Saved: '...'") and
|
||||||
|
/// reports errors as "ERROR ..." rather than "Error: ...". The prefix is
|
||||||
|
/// stripped before matching, so both formats parse the same way.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static partial class BlenderProgressParser
|
public static partial class BlenderProgressParser
|
||||||
{
|
{
|
||||||
[GeneratedRegex(@"^Fra:(\d+)", RegexOptions.Compiled)]
|
[GeneratedRegex(@"^(?:\d+:)?\d{2}:\d{2}\.\d{3}\s+\S+\s*\| ?", RegexOptions.Compiled)]
|
||||||
|
private static partial Regex LogPrefix();
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^Fra:\s*(\d+)", RegexOptions.Compiled)]
|
||||||
private static partial Regex FrameLine();
|
private static partial Regex FrameLine();
|
||||||
|
|
||||||
[GeneratedRegex(@"^Saved:\s*'(.+)'", RegexOptions.Compiled)]
|
[GeneratedRegex(@"^Saved:\s*'(.+)'", RegexOptions.Compiled)]
|
||||||
private static partial Regex SavedLine();
|
private static partial Regex SavedLine();
|
||||||
|
|
||||||
[GeneratedRegex(@"^(Error|Warning): |^Error: ", RegexOptions.Compiled | RegexOptions.IgnoreCase)]
|
// Errors only. Warnings are not failures, and add-ons print them on every
|
||||||
|
// launch ("Warning: add-on missing 'bl_info'"), so counting them made an
|
||||||
|
// add-on's complaint the reported reason for a failed render.
|
||||||
|
[GeneratedRegex(@"(?i:^Error: )|^(ERROR|FATAL) ", RegexOptions.Compiled)]
|
||||||
private static partial Regex ErrorLine();
|
private static partial Regex ErrorLine();
|
||||||
|
|
||||||
|
/// <summary>The line without Blender 5.x's "elapsed category | " prefix.</summary>
|
||||||
|
private static string Message(string line)
|
||||||
|
{
|
||||||
|
var m = LogPrefix().Match(line);
|
||||||
|
return m.Success ? line[m.Length..] : line;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Failures that will repeat identically on another machine — a missing
|
/// Failures that will repeat identically on another machine — a missing
|
||||||
/// file, an unknown scene, an unwritable output. Retrying these burns the
|
/// file, an unknown scene, an unwritable output. Retrying these burns the
|
||||||
@@ -35,7 +53,9 @@ public static partial class BlenderProgressParser
|
|||||||
"unknown scene",
|
"unknown scene",
|
||||||
"scene not found",
|
"scene not found",
|
||||||
"unable to create directory",
|
"unable to create directory",
|
||||||
|
"couldn't create directory",
|
||||||
"cannot write file",
|
"cannot write file",
|
||||||
|
"cannot save:",
|
||||||
"no camera",
|
"no camera",
|
||||||
"python script fail",
|
"python script fail",
|
||||||
"unknown argument",
|
"unknown argument",
|
||||||
@@ -44,18 +64,18 @@ public static partial class BlenderProgressParser
|
|||||||
/// <summary>The frame Blender is currently working on, or null.</summary>
|
/// <summary>The frame Blender is currently working on, or null.</summary>
|
||||||
public static int? ParseFrame(string line)
|
public static int? ParseFrame(string line)
|
||||||
{
|
{
|
||||||
var m = FrameLine().Match(line);
|
var m = FrameLine().Match(Message(line));
|
||||||
return m.Success && int.TryParse(m.Groups[1].Value, out var f) ? f : null;
|
return m.Success && int.TryParse(m.Groups[1].Value, out var f) ? f : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>The path of a frame Blender has just written, or null.</summary>
|
/// <summary>The path of a frame Blender has just written, or null.</summary>
|
||||||
public static string? ParseSaved(string line)
|
public static string? ParseSaved(string line)
|
||||||
{
|
{
|
||||||
var m = SavedLine().Match(line);
|
var m = SavedLine().Match(Message(line));
|
||||||
return m.Success ? m.Groups[1].Value : null;
|
return m.Success ? m.Groups[1].Value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsErrorLine(string line) => ErrorLine().IsMatch(line);
|
public static bool IsErrorLine(string line) => ErrorLine().IsMatch(Message(line));
|
||||||
|
|
||||||
public static bool IsNonRetryableError(string line)
|
public static bool IsNonRetryableError(string line)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -190,6 +190,21 @@ public sealed class BlenderRunner
|
|||||||
PumpAsync(process.StandardError, line => HandleLine(line, isStderr: true)),
|
PumpAsync(process.StandardError, line => HandleLine(line, isStderr: true)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await MonitorAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Disposing a Process does not end it: without this, any exception
|
||||||
|
// in the monitor loop leaves Blender rendering on the node,
|
||||||
|
// unsupervised, while the job is retried alongside it.
|
||||||
|
KillTree(process);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task<RenderResult> MonitorAsync()
|
||||||
|
{
|
||||||
while (!process.HasExited)
|
while (!process.HasExited)
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromSeconds(2), CancellationToken.None);
|
await Task.Delay(TimeSpan.FromSeconds(2), CancellationToken.None);
|
||||||
@@ -253,13 +268,16 @@ public sealed class BlenderRunner
|
|||||||
if (framesSaved == 0)
|
if (framesSaved == 0)
|
||||||
{
|
{
|
||||||
return new RenderResult(false, 0, Retryable: false,
|
return new RenderResult(false, 0, Retryable: false,
|
||||||
"Blender exited cleanly but saved no frames — check the output path and frame range in the .blend",
|
firstError is not null
|
||||||
|
? $"Blender exited cleanly but saved no frames: {firstError}"
|
||||||
|
: "Blender exited cleanly but saved no frames — check the output path and frame range in the .blend",
|
||||||
tail.ToString(), fullLogPath, sw.Elapsed.TotalSeconds);
|
tail.ToString(), fullLogPath, sw.Elapsed.TotalSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.LogInformation("Job {JobId}: {Saved}/{Total} frames in {Sec:F0}s", jobId, framesSaved, totalFrames, sw.Elapsed.TotalSeconds);
|
_log.LogInformation("Job {JobId}: {Saved}/{Total} frames in {Sec:F0}s", jobId, framesSaved, totalFrames, sw.Elapsed.TotalSeconds);
|
||||||
return new RenderResult(true, 0, true, null, tail.ToString(), fullLogPath, sw.Elapsed.TotalSeconds);
|
return new RenderResult(true, 0, true, null, tail.ToString(), fullLogPath, sw.Elapsed.TotalSeconds);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a stream treating both CR and LF as line terminators, so
|
/// Reads a stream treating both CR and LF as line terminators, so
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ public sealed class PreviewManifest
|
|||||||
public string Mp4Output { get; set; } = "";
|
public string Mp4Output { get; set; } = "";
|
||||||
public string? SlateScopeProp { get; set; }
|
public string? SlateScopeProp { get; set; }
|
||||||
public string? SlateSubmissionProp { get; set; }
|
public string? SlateSubmissionProp { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Also encode the High quality MP4 from the MOV and upload the MOV itself
|
||||||
|
/// as the version's High Res file (server "preview.highQuality").
|
||||||
|
/// </summary>
|
||||||
|
public bool HighQuality { get; set; }
|
||||||
public SlateInfo Slate { get; set; } = new();
|
public SlateInfo Slate { get; set; } = new();
|
||||||
|
|
||||||
public int TotalFrames => FrameEnd - FrameStart + 1;
|
public int TotalFrames => FrameEnd - FrameStart + 1;
|
||||||
@@ -299,6 +304,11 @@ public sealed class PresignResponse
|
|||||||
public string PresignedUrl { get; set; } = "";
|
public string PresignedUrl { get; set; } = "";
|
||||||
public string Key { get; set; } = "";
|
public string Key { get; set; } = "";
|
||||||
public string Url { get; set; } = "";
|
public string Url { get; set; } = "";
|
||||||
|
// Multipart (server ≥ 1.7.2 contract) — absent from older servers, which
|
||||||
|
// only ever return PresignedUrl.
|
||||||
|
public string? UploadId { get; set; }
|
||||||
|
public long PartSize { get; set; }
|
||||||
|
public List<string>? PartUrls { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ExportDetailResponse
|
public sealed class ExportDetailResponse
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace VFXReviewWorker;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uploads each preview's ProRes MOV (the version's High Res download) in the
|
||||||
|
/// background, after the job has already been finalized.
|
||||||
|
///
|
||||||
|
/// The MOV is by far the largest upload — hundreds of MB — and on a slow or
|
||||||
|
/// flaky uplink it held every preview job open for 10+ minutes, during which
|
||||||
|
/// the job looked stuck in the app and a worker restart threw the whole
|
||||||
|
/// preview away. Now the job completes as soon as the review MP4s are up, the
|
||||||
|
/// worker moves on to the next job, and the MOV follows; an "attach-highres"
|
||||||
|
/// report (through the ordered spooler, so always after its finalize) attaches
|
||||||
|
/// it to the version.
|
||||||
|
///
|
||||||
|
/// Pending uploads are files in highres-queue/, so a restart resumes them. The
|
||||||
|
/// MOV itself lives on the SAN beside the EXRs, never in scratch.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class HighResUploader
|
||||||
|
{
|
||||||
|
private const int MaxAttempts = 5;
|
||||||
|
|
||||||
|
private readonly ApiClient _api;
|
||||||
|
private readonly ReportSpooler _spooler;
|
||||||
|
private readonly ILogger<HighResUploader> _log;
|
||||||
|
private readonly string _dir;
|
||||||
|
private readonly SemaphoreSlim _wake = new(0);
|
||||||
|
|
||||||
|
public HighResUploader(ApiClient api, ReportSpooler spooler, ILogger<HighResUploader> log)
|
||||||
|
{
|
||||||
|
_api = api;
|
||||||
|
_spooler = spooler;
|
||||||
|
_log = log;
|
||||||
|
_dir = Path.Combine(WorkerOptions.DataDir, "highres-queue");
|
||||||
|
Directory.CreateDirectory(_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class Pending
|
||||||
|
{
|
||||||
|
public string JobId { get; set; } = "";
|
||||||
|
public string MachineId { get; set; } = "";
|
||||||
|
public string MovPath { get; set; } = "";
|
||||||
|
public int Attempts { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Enqueue(string jobId, string machineId, string movPath)
|
||||||
|
{
|
||||||
|
var item = new Pending { JobId = jobId, MachineId = machineId, MovPath = movPath };
|
||||||
|
var name = $"{DateTimeOffset.UtcNow.UtcTicks:D20}_{jobId}.json";
|
||||||
|
var tmp = Path.Combine(_dir, name + ".tmp");
|
||||||
|
File.WriteAllText(tmp, JsonSerializer.Serialize(item, WorkerOptions.JsonOpts));
|
||||||
|
File.Move(tmp, Path.Combine(_dir, name));
|
||||||
|
_log.LogInformation("ProRes for job {JobId} queued for background upload ({MB:F0} MB)",
|
||||||
|
jobId, File.Exists(movPath) ? new FileInfo(movPath).Length / 1048576.0 : 0);
|
||||||
|
_wake.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Long-running loop; started once by the worker service.</summary>
|
||||||
|
public async Task RunAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
var backoff = TimeSpan.FromSeconds(30);
|
||||||
|
while (!ct.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
var next = Directory.EnumerateFiles(_dir, "*.json").OrderBy(f => f, StringComparer.Ordinal).FirstOrDefault();
|
||||||
|
if (next is null)
|
||||||
|
{
|
||||||
|
try { await _wake.WaitAsync(TimeSpan.FromSeconds(30), ct); } catch (OperationCanceledException) { break; }
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pending? item;
|
||||||
|
try { item = JsonSerializer.Deserialize<Pending>(File.ReadAllText(next), WorkerOptions.JsonOpts); }
|
||||||
|
catch { item = null; }
|
||||||
|
if (item is null || string.IsNullOrEmpty(item.JobId))
|
||||||
|
{
|
||||||
|
_log.LogWarning("Discarding unreadable ProRes queue file {File}", next);
|
||||||
|
TryDelete(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(item.MovPath))
|
||||||
|
{
|
||||||
|
_log.LogWarning("ProRes for job {JobId} is gone ({Path}) — not uploading", item.JobId, item.MovPath);
|
||||||
|
Report(item, null, $"MOV not found at {item.MovPath}");
|
||||||
|
TryDelete(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? key;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
key = await _api.UploadArtifactAsync(item.JobId, item.MachineId, "highres", item.MovPath, "video/quicktime", ct);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException) when (ct.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
_log.LogInformation("Worker stopping — ProRes upload for job {JobId} resumes on next start", item.JobId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key is not null)
|
||||||
|
{
|
||||||
|
Report(item, key, null);
|
||||||
|
TryDelete(next);
|
||||||
|
backoff = TimeSpan.FromSeconds(30);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.Attempts++;
|
||||||
|
if (item.Attempts >= MaxAttempts)
|
||||||
|
{
|
||||||
|
_log.LogWarning("ProRes upload for job {JobId} failed {N} times — giving up", item.JobId, item.Attempts);
|
||||||
|
Report(item, null, $"upload failed {item.Attempts} times (see the worker log)");
|
||||||
|
TryDelete(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.LogWarning("ProRes upload for job {JobId} failed (attempt {N}/{Max}); retrying in {Sec}s",
|
||||||
|
item.JobId, item.Attempts, MaxAttempts, backoff.TotalSeconds);
|
||||||
|
try { File.WriteAllText(next, JsonSerializer.Serialize(item, WorkerOptions.JsonOpts)); } catch { /* retried anyway */ }
|
||||||
|
try { await Task.Delay(backoff, ct); } catch (OperationCanceledException) { break; }
|
||||||
|
backoff = TimeSpan.FromSeconds(Math.Min(backoff.TotalSeconds * 2, 600));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Report(Pending item, string? key, string? error)
|
||||||
|
{
|
||||||
|
_spooler.Enqueue("attach-highres", item.JobId, new Dictionary<string, object?>
|
||||||
|
{
|
||||||
|
["machineId"] = item.MachineId,
|
||||||
|
["highResKey"] = key,
|
||||||
|
["highResFileName"] = key is null ? null : Path.GetFileName(item.MovPath),
|
||||||
|
["highResSize"] = key is null ? null : new FileInfo(item.MovPath).Length,
|
||||||
|
["error"] = error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TryDelete(string path)
|
||||||
|
{
|
||||||
|
try { File.Delete(path); } catch { /* next pass */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,11 +18,14 @@ public sealed class JobExecutor
|
|||||||
private readonly DeliveryStage _delivery;
|
private readonly DeliveryStage _delivery;
|
||||||
private readonly BlenderRunner _blender;
|
private readonly BlenderRunner _blender;
|
||||||
private readonly ReportSpooler _spooler;
|
private readonly ReportSpooler _spooler;
|
||||||
|
private readonly HighResUploader _highRes;
|
||||||
private readonly ILogger<JobExecutor> _log;
|
private readonly ILogger<JobExecutor> _log;
|
||||||
|
|
||||||
public JobExecutor(WorkerOptions options, ApiClient api, AerenderRunner runner, PreviewStage preview,
|
public JobExecutor(WorkerOptions options, ApiClient api, AerenderRunner runner, PreviewStage preview,
|
||||||
ValidationStage validation, DeliveryStage delivery, BlenderRunner blender, ReportSpooler spooler, ILogger<JobExecutor> log)
|
ValidationStage validation, DeliveryStage delivery, BlenderRunner blender, ReportSpooler spooler,
|
||||||
|
HighResUploader highRes, ILogger<JobExecutor> log)
|
||||||
{
|
{
|
||||||
|
_highRes = highRes;
|
||||||
_options = options;
|
_options = options;
|
||||||
_api = api;
|
_api = api;
|
||||||
_runner = runner;
|
_runner = runner;
|
||||||
@@ -76,12 +79,15 @@ public sealed class JobExecutor
|
|||||||
{
|
{
|
||||||
long totalBytes = 0;
|
long totalBytes = 0;
|
||||||
int fileCount = 0;
|
int fileCount = 0;
|
||||||
var prefix = AerenderRunner.OutputPatternPrefix(manifest.OutputPattern);
|
// Prefix and extension both: the preview MOV/MP4 for this
|
||||||
|
// version share the basename and live in this same folder, and
|
||||||
|
// counting them as frames would inflate the EXR stats.
|
||||||
|
var pattern = SequencePattern.FromOutputPattern(manifest.OutputPattern);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var f in Directory.EnumerateFiles(outputDirLocal))
|
foreach (var f in Directory.EnumerateFiles(outputDirLocal))
|
||||||
{
|
{
|
||||||
if (!Path.GetFileName(f).StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) continue;
|
if (!pattern.MatchesOutputFile(Path.GetFileName(f))) continue;
|
||||||
fileCount++;
|
fileCount++;
|
||||||
totalBytes += new FileInfo(f).Length;
|
totalBytes += new FileInfo(f).Length;
|
||||||
}
|
}
|
||||||
@@ -94,8 +100,8 @@ public sealed class JobExecutor
|
|||||||
// range, template mismatch, silently swallowed error).
|
// range, template mismatch, silently swallowed error).
|
||||||
// Until Phase 3 validation exists, an empty output dir must
|
// Until Phase 3 validation exists, an empty output dir must
|
||||||
// never become READY_FOR_QC.
|
// never become READY_FOR_QC.
|
||||||
_log.LogError("Job {JobId}: aerender exited 0 but no \"{Prefix}*\" files exist in {Dir} — reporting failure",
|
_log.LogError("Job {JobId}: aerender exited 0 but no \"{Prefix}*{Ext}\" files exist in {Dir} — reporting failure",
|
||||||
job.Id, prefix, outputDirLocal);
|
job.Id, pattern.Prefix, pattern.Extension, outputDirLocal);
|
||||||
_spooler.Enqueue("fail", job.Id, new Dictionary<string, object?>
|
_spooler.Enqueue("fail", job.Id, new Dictionary<string, object?>
|
||||||
{
|
{
|
||||||
["machineId"] = machineId,
|
["machineId"] = machineId,
|
||||||
@@ -415,8 +421,15 @@ public sealed class JobExecutor
|
|||||||
return; // temp AEP is deliberately kept for debugging
|
return; // temp AEP is deliberately kept for debugging
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// From here on aerender is done and the app would keep showing its
|
||||||
|
// last frame line; this reports what the worker is doing instead,
|
||||||
|
// and renews the lease through the encode and uploads.
|
||||||
|
await using var status = new LeaseKeepAlive(_api, job.Id, machineId, TimeSpan.FromSeconds(10), shutdown);
|
||||||
|
status.Line($"Preview rendered in {result.Seconds:F0}s — uploading review media");
|
||||||
|
|
||||||
var previewKey = await _api.UploadArtifactAsync(
|
var previewKey = await _api.UploadArtifactAsync(
|
||||||
job.Id, machineId, "preview", result.Mp4Path!, "video/mp4", shutdown);
|
job.Id, machineId, "preview", result.Mp4Path!, "video/mp4", shutdown,
|
||||||
|
status.Track("preview MP4", result.Mp4Path!));
|
||||||
if (previewKey is null)
|
if (previewKey is null)
|
||||||
{
|
{
|
||||||
// The renders are on the SAN and fine — only the upload failed,
|
// The renders are on the SAN and fine — only the upload failed,
|
||||||
@@ -430,6 +443,7 @@ public sealed class JobExecutor
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
status.Line("Preview MP4 uploaded");
|
||||||
|
|
||||||
string? thumbKey = null;
|
string? thumbKey = null;
|
||||||
if (result.ThumbnailPath is not null)
|
if (result.ThumbnailPath is not null)
|
||||||
@@ -438,6 +452,30 @@ public sealed class JobExecutor
|
|||||||
job.Id, machineId, "thumbnail", result.ThumbnailPath, "image/jpeg", shutdown);
|
job.Id, machineId, "thumbnail", result.ThumbnailPath, "image/jpeg", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// High quality MP4 + the MOV as the version's High Res download
|
||||||
|
// (§9.6). Both optional: a failure here costs the extras, never the
|
||||||
|
// preview, which is already safely uploaded. The MOV is uploaded in
|
||||||
|
// the background after finalize (HighResUploader) — it is the big
|
||||||
|
// one and used to hold the job open for many minutes.
|
||||||
|
string? hqKey = null;
|
||||||
|
var highResPending = false;
|
||||||
|
if (manifest.HighQuality)
|
||||||
|
{
|
||||||
|
status.Line("Encoding High quality MP4");
|
||||||
|
var hqPath = await _preview.TryMakeHighQualityAsync(job.Id, result.MovPath!, result.Mp4Path!, shutdown);
|
||||||
|
if (hqPath is not null)
|
||||||
|
{
|
||||||
|
hqKey = await _api.UploadArtifactAsync(job.Id, machineId, "preview", hqPath, "video/mp4", shutdown,
|
||||||
|
status.Track("High quality MP4", hqPath));
|
||||||
|
if (hqKey is null) _log.LogWarning("High quality MP4 upload failed for job {JobId}", job.Id);
|
||||||
|
status.Line(hqKey is null ? "High quality MP4 upload FAILED (see worker log)" : "High quality MP4 uploaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
highResPending = result.MovPath is not null && File.Exists(result.MovPath);
|
||||||
|
if (highResPending)
|
||||||
|
status.Line("ProRes MOV queued for background upload — completing the job now");
|
||||||
|
}
|
||||||
|
|
||||||
_spooler.Enqueue("finalize", job.Id, new Dictionary<string, object?>
|
_spooler.Enqueue("finalize", job.Id, new Dictionary<string, object?>
|
||||||
{
|
{
|
||||||
["machineId"] = machineId,
|
["machineId"] = machineId,
|
||||||
@@ -446,6 +484,8 @@ public sealed class JobExecutor
|
|||||||
["deliveryMovPath"] = manifest.MovOutput,
|
["deliveryMovPath"] = manifest.MovOutput,
|
||||||
["previewMovKey"] = previewKey,
|
["previewMovKey"] = previewKey,
|
||||||
["thumbnailKey"] = thumbKey,
|
["thumbnailKey"] = thumbKey,
|
||||||
|
["hqPreviewKey"] = hqKey,
|
||||||
|
["highResPending"] = highResPending,
|
||||||
},
|
},
|
||||||
["renderStats"] = new Dictionary<string, object?>
|
["renderStats"] = new Dictionary<string, object?>
|
||||||
{
|
{
|
||||||
@@ -458,9 +498,16 @@ public sealed class JobExecutor
|
|||||||
["frameCount"] = result.Build?.FrameCount,
|
["frameCount"] = result.Build?.FrameCount,
|
||||||
["fps"] = manifest.Fps,
|
["fps"] = manifest.Fps,
|
||||||
["fileName"] = Path.GetFileName(result.Mp4Path!),
|
["fileName"] = Path.GetFileName(result.Mp4Path!),
|
||||||
|
// Slate length, so the review player can place the handle
|
||||||
|
// markers exactly instead of inferring it (server ≥ 2026-09-22).
|
||||||
|
["pictureStartSeconds"] = result.Build?.PictureStartSeconds,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Enqueued after finalize: its attach report must reach the spooler
|
||||||
|
// behind finalize, which creates the version it attaches to.
|
||||||
|
if (highResPending) _highRes.Enqueue(job.Id, machineId, result.MovPath!);
|
||||||
|
|
||||||
// Only clean up once the outputs are safely reported.
|
// Only clean up once the outputs are safely reported.
|
||||||
CleanScratch(job.Id, result.TempAep);
|
CleanScratch(job.Id, result.TempAep);
|
||||||
}
|
}
|
||||||
@@ -488,6 +535,12 @@ public sealed class JobExecutor
|
|||||||
PreviewStage.TryDelete(Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_run.jsx"));
|
PreviewStage.TryDelete(Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_run.jsx"));
|
||||||
PreviewStage.TryDelete(Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_thumb.jpg"));
|
PreviewStage.TryDelete(Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_thumb.jpg"));
|
||||||
if (tempAep is not null) PreviewStage.TryDelete(tempAep);
|
if (tempAep is not null) PreviewStage.TryDelete(tempAep);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var hqDir = PreviewStage.HighQualityDir(jobId);
|
||||||
|
if (Directory.Exists(hqDir)) Directory.Delete(hqDir, recursive: true);
|
||||||
|
}
|
||||||
|
catch { /* scratch only */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace VFXReviewWorker;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renews a job's lease with progress reports while the worker does something
|
||||||
|
/// long that reports nothing on its own — the High quality encode and the
|
||||||
|
/// uploads can each outlast a 300 s lease, and an expired lease lets the
|
||||||
|
/// reaper hand the job to another machine mid-upload.
|
||||||
|
///
|
||||||
|
/// Each report also replaces the job's log tail with what the worker is doing
|
||||||
|
/// now ("Uploading High quality MP4: 12.0 / 34.0 MB…"). Without it the app
|
||||||
|
/// keeps showing aerender's last frame line and a busy job looks hung.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class LeaseKeepAlive : IAsyncDisposable
|
||||||
|
{
|
||||||
|
private readonly ApiClient _api;
|
||||||
|
private readonly string _jobId;
|
||||||
|
private readonly string _machineId;
|
||||||
|
private readonly CancellationTokenSource _cts;
|
||||||
|
private readonly SemaphoreSlim _wake = new(0);
|
||||||
|
private readonly Task _loop;
|
||||||
|
private readonly object _lock = new();
|
||||||
|
private readonly List<string> _lines = new();
|
||||||
|
private string? _current;
|
||||||
|
|
||||||
|
public LeaseKeepAlive(ApiClient api, string jobId, string machineId, TimeSpan interval, CancellationToken shutdown)
|
||||||
|
{
|
||||||
|
_api = api;
|
||||||
|
_jobId = jobId;
|
||||||
|
_machineId = machineId;
|
||||||
|
_cts = CancellationTokenSource.CreateLinkedTokenSource(shutdown);
|
||||||
|
var token = _cts.Token;
|
||||||
|
_loop = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
// Best-effort by contract (ApiClient.ProgressAsync never throws
|
||||||
|
// on transport errors); progress stays at 1.0 — the render is done.
|
||||||
|
await _api.ProgressAsync(_jobId, _machineId, 1.0, null, null, null, Render(), token);
|
||||||
|
await _wake.WaitAsync(interval, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
// stopped
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Adds a finished step to the status shown in the app.</summary>
|
||||||
|
public void Line(string text)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
_current = null;
|
||||||
|
_lines.Add($"{DateTime.Now:HH:mm:ss} {text}");
|
||||||
|
}
|
||||||
|
_wake.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Progress callback for <see cref="ApiClient.UploadArtifactAsync"/>: keeps
|
||||||
|
/// one live line ("Uploading X: 12.0 / 34.0 MB (35%, 2.1 MB/s)") up to date.
|
||||||
|
/// </summary>
|
||||||
|
public Action<long> Track(string label, string filePath)
|
||||||
|
{
|
||||||
|
long total = File.Exists(filePath) ? new FileInfo(filePath).Length : 0;
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
lock (_lock) _current = $"Uploading {label}: 0.0 / {Mb(total)} MB";
|
||||||
|
_wake.Release();
|
||||||
|
return sent =>
|
||||||
|
{
|
||||||
|
var pct = total > 0 ? 100.0 * sent / total : 0;
|
||||||
|
var speed = sent / 1048576.0 / Math.Max(0.001, sw.Elapsed.TotalSeconds);
|
||||||
|
lock (_lock) _current = $"Uploading {label}: {Mb(sent)} / {Mb(total)} MB ({pct:F0}%, {speed:F1} MB/s)";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Mb(long bytes) => (bytes / 1048576.0).ToString("F1");
|
||||||
|
|
||||||
|
private string Render()
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (var l in _lines) sb.AppendLine(l);
|
||||||
|
if (_current is not null) sb.AppendLine($"{DateTime.Now:HH:mm:ss} {_current}");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
_cts.Cancel();
|
||||||
|
try { await _loop; } catch { /* already reported */ }
|
||||||
|
_cts.Dispose();
|
||||||
|
_wake.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -302,6 +302,107 @@ public sealed class PreviewStage
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Scratch folder for a job's High quality encode.</summary>
|
||||||
|
internal static string HighQualityDir(string jobId) =>
|
||||||
|
Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_hq");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// High quality review MP4 (§9.6): the delivery MOV re-encoded as
|
||||||
|
/// full-resolution, high-bitrate H.264 High — the player's "High" quality.
|
||||||
|
/// ProRes itself only plays in Safari on a Mac, so the MOV is offered as a
|
||||||
|
/// download and this is what streams. Never fatal: without it the version
|
||||||
|
/// simply has Standard quality only.
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string?> TryMakeHighQualityAsync(
|
||||||
|
string jobId, string movPath, string mp4Path, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(_options.FfmpegPath) || !File.Exists(_options.FfmpegPath))
|
||||||
|
{
|
||||||
|
_log.LogWarning("No High quality MP4 for job {JobId}: ffmpegPath is not set or missing.", jobId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!File.Exists(movPath))
|
||||||
|
{
|
||||||
|
_log.LogWarning("No High quality MP4 for job {JobId}: MOV not found at {Path}.", jobId, movPath);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dir = HighQualityDir(jobId);
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
// Named after the review MP4 so the stored object reads as its sibling.
|
||||||
|
var outPath = Path.Combine(dir, Path.GetFileNameWithoutExtension(mp4Path) + "_HQ.mp4");
|
||||||
|
TryDelete(outPath);
|
||||||
|
|
||||||
|
var args = new List<string>
|
||||||
|
{
|
||||||
|
"-y", "-i", movPath,
|
||||||
|
"-map", "0:v:0", "-map", "0:a?",
|
||||||
|
// Visually lossless for review, capped so a busy shot can't balloon
|
||||||
|
// past what a good connection streams. yuv420p 8-bit High profile
|
||||||
|
// is the combination every browser decodes.
|
||||||
|
"-c:v", "libx264", "-profile:v", "high", "-preset", "medium", "-crf", "14",
|
||||||
|
"-maxrate", "100M", "-bufsize", "200M", "-pix_fmt", "yuv420p",
|
||||||
|
"-c:a", "aac", "-b:a", "256k",
|
||||||
|
// Index at the front so the player can start before it's all loaded
|
||||||
|
"-movflags", "+faststart",
|
||||||
|
outPath,
|
||||||
|
};
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = _options.FfmpegPath,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
};
|
||||||
|
foreach (var a in args) psi.ArgumentList.Add(a);
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var process = Process.Start(psi);
|
||||||
|
if (process is null)
|
||||||
|
{
|
||||||
|
_log.LogWarning("Could not start ffmpeg for the High quality MP4 (job {JobId})", jobId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Drain both pipes (see RunFfmpegThumbnailAsync — an unread pipe deadlocks ffmpeg).
|
||||||
|
var stderrTask = process.StandardError.ReadToEndAsync();
|
||||||
|
var stdoutTask = process.StandardOutput.ReadToEndAsync();
|
||||||
|
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||||
|
timeout.CancelAfter(TimeSpan.FromMinutes(30));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await process.WaitForExitAsync(timeout.Token);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
_log.LogWarning("High quality encode for job {JobId} timed out or was cancelled — killing ffmpeg", jobId);
|
||||||
|
try { process.Kill(entireProcessTree: true); } catch { }
|
||||||
|
TryDelete(outPath);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var stderr = await stderrTask;
|
||||||
|
await stdoutTask;
|
||||||
|
|
||||||
|
if (process.ExitCode == 0 && File.Exists(outPath) && new FileInfo(outPath).Length > 0)
|
||||||
|
{
|
||||||
|
_log.LogInformation("High quality MP4 for job {JobId} encoded in {Sec:F0}s ({MB:F0} MB)",
|
||||||
|
jobId, sw.Elapsed.TotalSeconds, new FileInfo(outPath).Length / 1e6);
|
||||||
|
return outPath;
|
||||||
|
}
|
||||||
|
_log.LogWarning("High quality encode failed for job {JobId} (exit {Exit}): {Stderr}",
|
||||||
|
jobId, process.ExitCode, Tail(stderr, 1200));
|
||||||
|
TryDelete(outPath);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.LogWarning(ex, "High quality encode failed for job {JobId} (non-fatal)", jobId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>How one ffmpeg attempt ended.</summary>
|
/// <summary>How one ffmpeg attempt ended.</summary>
|
||||||
private enum ThumbAttempt
|
private enum ThumbAttempt
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ builder.Logging.AddProvider(new FileLoggerProvider());
|
|||||||
builder.Services.AddSingleton(options);
|
builder.Services.AddSingleton(options);
|
||||||
builder.Services.AddSingleton<ApiClient>();
|
builder.Services.AddSingleton<ApiClient>();
|
||||||
builder.Services.AddSingleton<ReportSpooler>();
|
builder.Services.AddSingleton<ReportSpooler>();
|
||||||
|
builder.Services.AddSingleton<HighResUploader>();
|
||||||
builder.Services.AddSingleton<AerenderRunner>();
|
builder.Services.AddSingleton<AerenderRunner>();
|
||||||
builder.Services.AddSingleton<PreviewStage>();
|
builder.Services.AddSingleton<PreviewStage>();
|
||||||
builder.Services.AddSingleton<ValidationStage>();
|
builder.Services.AddSingleton<ValidationStage>();
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace VFXReviewWorker;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// StreamContent that reports bytes sent, so a long upload can show progress.
|
||||||
|
/// Length is computed from the stream, so the PUT still carries Content-Length
|
||||||
|
/// (presigned S3 uploads reject chunked bodies).
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class ProgressStreamContent : HttpContent
|
||||||
|
{
|
||||||
|
private readonly Stream _source;
|
||||||
|
private readonly Action<long>? _onProgress;
|
||||||
|
|
||||||
|
public ProgressStreamContent(Stream source, Action<long>? onProgress)
|
||||||
|
{
|
||||||
|
_source = source;
|
||||||
|
_onProgress = onProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) =>
|
||||||
|
SerializeToStreamAsync(stream, context, CancellationToken.None);
|
||||||
|
|
||||||
|
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var buffer = new byte[81920];
|
||||||
|
long sent = 0;
|
||||||
|
int read;
|
||||||
|
while ((read = await _source.ReadAsync(buffer, ct)) > 0)
|
||||||
|
{
|
||||||
|
await stream.WriteAsync(buffer.AsMemory(0, read), ct);
|
||||||
|
sent += read;
|
||||||
|
_onProgress?.Invoke(sent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool TryComputeLength(out long length)
|
||||||
|
{
|
||||||
|
length = _source.Length;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
every change that gets published. publish.ps1 appends the git SHA via
|
every change that gets published. publish.ps1 appends the git SHA via
|
||||||
SourceRevisionId, giving "1.1.0+feb1c7b".
|
SourceRevisionId, giving "1.1.0+feb1c7b".
|
||||||
-->
|
-->
|
||||||
<Version>1.6.0</Version>
|
<Version>1.7.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -350,6 +350,31 @@ public sealed class ValidationStage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deltaOf = (TimecodeReference r) =>
|
||||||
|
renderTc.ToFrames(fps) - (r.PlateTimecode.ToFrames(fps) + (renderFirstFrame - r.PlateFirstFrame));
|
||||||
|
|
||||||
|
// A shot with several delivered elements: the panel names the longest
|
||||||
|
// as the timing plate, but the comp may have been anchored to another
|
||||||
|
// (BG01 and FG01 carry unrelated camera timecodes). When the timing
|
||||||
|
// plate disagrees, the manifest's other delivered plates are tried
|
||||||
|
// before failing. The comparison is unchanged — it is still a plate, so
|
||||||
|
// a match is a real PASS and no match still FAILs against the timing plate.
|
||||||
|
var timingPlate = reference;
|
||||||
|
var alternatesTried = new List<object>();
|
||||||
|
if (reference.Kind == "manifest" && deltaOf(reference) != 0)
|
||||||
|
{
|
||||||
|
foreach (var alternate in ResolveAlternatePlates(m, renderFirstFrame, reference))
|
||||||
|
{
|
||||||
|
var altDelta = deltaOf(alternate);
|
||||||
|
alternatesTried.Add(new { platePath = alternate.PlatePath, plateTimecode = alternate.PlateTimecode.ToString(), deltaFrames = altDelta });
|
||||||
|
if (altDelta == 0)
|
||||||
|
{
|
||||||
|
reference = alternate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// plate_fps — the render's rate against the plate's own.
|
// plate_fps — the render's rate against the plate's own.
|
||||||
//
|
//
|
||||||
// timecode_fps only compares the render to the manifest, and both come
|
// timecode_fps only compares the render to the manifest, and both come
|
||||||
@@ -377,8 +402,8 @@ public sealed class ValidationStage
|
|||||||
|
|
||||||
var expectedFrames = reference.PlateTimecode.ToFrames(fps) + (renderFirstFrame - reference.PlateFirstFrame);
|
var expectedFrames = reference.PlateTimecode.ToFrames(fps) + (renderFirstFrame - reference.PlateFirstFrame);
|
||||||
var expected = Timecode.FromFrames(expectedFrames, fps);
|
var expected = Timecode.FromFrames(expectedFrames, fps);
|
||||||
var actualFrames = renderTc.ToFrames(fps);
|
var deltaFrames = deltaOf(reference);
|
||||||
var deltaFrames = actualFrames - expectedFrames;
|
var matchedAlternate = !ReferenceEquals(reference, timingPlate);
|
||||||
var details = new
|
var details = new
|
||||||
{
|
{
|
||||||
reference = reference.Kind,
|
reference = reference.Kind,
|
||||||
@@ -387,10 +412,14 @@ public sealed class ValidationStage
|
|||||||
plateFirstFrame = reference.PlateFirstFrame,
|
plateFirstFrame = reference.PlateFirstFrame,
|
||||||
renderFirstFrame,
|
renderFirstFrame,
|
||||||
deltaFrames,
|
deltaFrames,
|
||||||
|
timingPlatePath = timingPlate.PlatePath,
|
||||||
|
matchedAlternate,
|
||||||
|
alternatesTried,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (deltaFrames == 0)
|
if (deltaFrames == 0)
|
||||||
{
|
{
|
||||||
|
var timingDelta = deltaOf(timingPlate);
|
||||||
// The API fallback proves nothing on its own (§8.1a): it is the
|
// The API fallback proves nothing on its own (§8.1a): it is the
|
||||||
// editorial in-point minus a handle count that may not be this
|
// editorial in-point minus a handle count that may not be this
|
||||||
// plate's, so a match is reported as a WARN, never a PASS.
|
// plate's, so a match is reported as a WARN, never a PASS.
|
||||||
@@ -398,7 +427,11 @@ public sealed class ValidationStage
|
|||||||
? ValidationCheck.Warn("timecode_plate_match", expected.ToString(), renderTc.ToString(),
|
? ValidationCheck.Warn("timecode_plate_match", expected.ToString(), renderTc.ToString(),
|
||||||
"Matches the API timecode less handles, but the plate itself could not be read — unverified.", details)
|
"Matches the API timecode less handles, but the plate itself could not be read — unverified.", details)
|
||||||
: ValidationCheck.Pass("timecode_plate_match", expected.ToString(), renderTc.ToString(),
|
: ValidationCheck.Pass("timecode_plate_match", expected.ToString(), renderTc.ToString(),
|
||||||
$"Matches {reference.Kind} plate {Path.GetFileName(reference.PlatePath ?? "")}", details));
|
$"Matches {reference.Kind} plate {Path.GetFileName(reference.PlatePath ?? "")}" +
|
||||||
|
(matchedAlternate
|
||||||
|
? $" (the timing plate {Path.GetFileName(timingPlate.PlatePath ?? "")} is {(timingDelta > 0 ? "+" : "")}{timingDelta} frames off — the comp was anchored to this element instead)"
|
||||||
|
: ""),
|
||||||
|
details));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +442,9 @@ public sealed class ValidationStage
|
|||||||
? $"That is exactly the {reference.HandleFrames}-frame handle: the comp was anchored to the editorial in-point instead of the plate's first frame."
|
? $"That is exactly the {reference.HandleFrames}-frame handle: the comp was anchored to the editorial in-point instead of the plate's first frame."
|
||||||
: renderTc.Hours == 0 && renderTc.Minutes == 0
|
: renderTc.Hours == 0 && renderTc.Minutes == 0
|
||||||
? "A near-zero timecode means the comp had no source timecode at all and AE derived it from the frame number."
|
? "A near-zero timecode means the comp had no source timecode at all and AE derived it from the frame number."
|
||||||
|
: "") +
|
||||||
|
(alternatesTried.Count > 0
|
||||||
|
? $" Also checked {alternatesTried.Count} other delivered plate{(alternatesTried.Count == 1 ? "" : "s")} in the manifest: none match."
|
||||||
: "");
|
: "");
|
||||||
|
|
||||||
checks.Add(reference.Kind == "api"
|
checks.Add(reference.Kind == "api"
|
||||||
@@ -430,20 +466,9 @@ public sealed class ValidationStage
|
|||||||
var timing = m.Source?.TimingPlate;
|
var timing = m.Source?.TimingPlate;
|
||||||
if (timing is not null && !string.IsNullOrWhiteSpace(timing.Path))
|
if (timing is not null && !string.IsNullOrWhiteSpace(timing.Path))
|
||||||
{
|
{
|
||||||
var local = mapper.Map(timing.Path);
|
var manifestPlate = ReadManifestPlate(timing, mapper, handleFrames, renderFirstFrame);
|
||||||
var header = File.Exists(local) ? ExrHeader.TryRead(local) : null;
|
if (manifestPlate is not null) return manifestPlate;
|
||||||
if (header?.Timecode is not null)
|
_log.LogWarning("Timing plate from manifest is unreadable: {Path}", mapper.Map(timing.Path));
|
||||||
{
|
|
||||||
// The plate's own file numbering, never the comp's frame range:
|
|
||||||
// the render's first frame is in output numbering, so anchoring
|
|
||||||
// on a comp frame skews the comparison by the gap between them.
|
|
||||||
var frame = SequencePattern.FrameFromName(Path.GetFileName(local))
|
|
||||||
?? timing.FrameStart
|
|
||||||
?? renderFirstFrame;
|
|
||||||
return new TimecodeReference("manifest", local, header.Timecode.Value, frame, handleFrames,
|
|
||||||
header.FramesPerSecond);
|
|
||||||
}
|
|
||||||
_log.LogWarning("Timing plate from manifest is unreadable: {Path}", local);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rank 2 — derive the plate from a configured search root.
|
// Rank 2 — derive the plate from a configured search root.
|
||||||
@@ -469,6 +494,63 @@ public sealed class ValidationStage
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TimecodeReference? ReadManifestPlate(PlateRef plate, PathMapper mapper, int handleFrames, int renderFirstFrame)
|
||||||
|
{
|
||||||
|
var local = mapper.Map(plate.Path);
|
||||||
|
var header = File.Exists(local) ? ExrHeader.TryRead(local) : null;
|
||||||
|
if (header?.Timecode is null) return null;
|
||||||
|
|
||||||
|
// The plate's own file numbering, never the comp's frame range: the
|
||||||
|
// render's first frame is in output numbering, so anchoring on a comp
|
||||||
|
// frame skews the comparison by the gap between them.
|
||||||
|
var frame = SequencePattern.FrameFromName(Path.GetFileName(local))
|
||||||
|
?? plate.FrameStart
|
||||||
|
?? renderFirstFrame;
|
||||||
|
return new TimecodeReference("manifest", local, header.Timecode.Value, frame, handleFrames,
|
||||||
|
header.FramesPerSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The manifest's other delivered plates, tried when the timing plate does
|
||||||
|
/// not match. Only real footage qualifies — under a configured plate search
|
||||||
|
/// root or, with none configured, alongside the timing plate in its footage
|
||||||
|
/// folder — because plates[] is every file in the comp, and a pre-render
|
||||||
|
/// agrees with the render whether or not either is right.
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerable<TimecodeReference> ResolveAlternatePlates(RenderManifest m, int renderFirstFrame, TimecodeReference timingPlate)
|
||||||
|
{
|
||||||
|
var plates = m.Source?.Plates;
|
||||||
|
if (plates is null || plates.Count == 0 || timingPlate.PlatePath is null) yield break;
|
||||||
|
|
||||||
|
var mapper = new PathMapper(_options.PathMappings);
|
||||||
|
static string AsFolder(string dir) => Path.TrimEndingDirectorySeparator(Path.GetFullPath(dir)) + Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
|
var deliveredRoots = _options.PlateSearchRoots.Count > 0
|
||||||
|
? _options.PlateSearchRoots.Select(r => AsFolder(mapper.Map(r))).ToList()
|
||||||
|
// {footage}/{shot}_{element}/file.exr or {footage}/{shot}/{element}/file.exr:
|
||||||
|
// two levels up from the timing plate is the folder its siblings share.
|
||||||
|
: Path.GetDirectoryName(Path.GetDirectoryName(Path.GetFullPath(timingPlate.PlatePath))) is { } footage
|
||||||
|
? new List<string> { AsFolder(footage) }
|
||||||
|
: new List<string>();
|
||||||
|
|
||||||
|
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { Path.GetFullPath(timingPlate.PlatePath) };
|
||||||
|
foreach (var plate in plates)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(plate.Path)) continue;
|
||||||
|
var local = Path.GetFullPath(mapper.Map(plate.Path));
|
||||||
|
if (!seen.Add(local)) continue;
|
||||||
|
if (!deliveredRoots.Any(root => local.StartsWith(root, StringComparison.OrdinalIgnoreCase))) continue;
|
||||||
|
|
||||||
|
var reference = ReadManifestPlate(plate, mapper, timingPlate.HandleFrames, renderFirstFrame);
|
||||||
|
if (reference is null)
|
||||||
|
{
|
||||||
|
_log.LogWarning("Alternate plate from manifest is unreadable: {Path}", local);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
yield return reference;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rank 2: look for the shot's plate folders under the configured roots,
|
/// Rank 2: look for the shot's plate folders under the configured roots,
|
||||||
/// mirroring the panel's two on-disk layouts ({shotCode}/{element}/ and
|
/// mirroring the panel's two on-disk layouts ({shotCode}/{element}/ and
|
||||||
@@ -645,6 +727,16 @@ public sealed class SequencePattern
|
|||||||
return new SequencePattern { Prefix = prefix, Extension = ext, Padding = padding };
|
return new SequencePattern { Prefix = prefix, Extension = ext, Padding = padding };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether a filename belongs to *this* render's output: the pattern's own
|
||||||
|
/// prefix and extension. A version folder also holds the preview MOV and
|
||||||
|
/// MP4, which are built from the same basename and so share the prefix —
|
||||||
|
/// only the extension separates them from the frames.
|
||||||
|
/// </summary>
|
||||||
|
public bool MatchesOutputFile(string fileName) =>
|
||||||
|
fileName.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase)
|
||||||
|
&& fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public int? FrameNumberOf(string fileName) => FrameFromName(fileName);
|
public int? FrameNumberOf(string fileName) => FrameFromName(fileName);
|
||||||
|
|
||||||
/// <summary>`UNG_102_019_010_cmp_TT_v005.01001.exr` → 1001.</summary>
|
/// <summary>`UNG_102_019_010_cmp_TT_v005.01001.exr` → 1001.</summary>
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ public sealed class WorkerOptions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> PlateSearchRoots { get; set; } = new();
|
public List<string> PlateSearchRoots { get; set; } = new();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Parallel connections per large upload. From the studio each connection
|
||||||
|
/// to object storage is capped near 0.1 MB/s, so throughput scales with
|
||||||
|
/// this (measured: 1 → 0.13 MB/s, 8 → 0.64, 24 → 1.69).
|
||||||
|
/// </summary>
|
||||||
|
public int UploadConcurrency { get; set; } = 16;
|
||||||
|
/// <summary>
|
||||||
/// Read from the assembly, not from config.json: a hand-maintained version
|
/// Read from the assembly, not from config.json: a hand-maintained version
|
||||||
/// string is exactly the thing that goes stale, and a machine reporting a
|
/// string is exactly the thing that goes stale, and a machine reporting a
|
||||||
/// version it is not running is worse than no version at all.
|
/// version it is not running is worse than no version at all.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public sealed class WorkerService : BackgroundService
|
|||||||
private readonly ApiClient _api;
|
private readonly ApiClient _api;
|
||||||
private readonly JobExecutor _executor;
|
private readonly JobExecutor _executor;
|
||||||
private readonly ReportSpooler _spooler;
|
private readonly ReportSpooler _spooler;
|
||||||
|
private readonly HighResUploader _highRes;
|
||||||
private readonly ILogger<WorkerService> _log;
|
private readonly ILogger<WorkerService> _log;
|
||||||
|
|
||||||
private string? _machineId;
|
private string? _machineId;
|
||||||
@@ -23,8 +24,10 @@ public sealed class WorkerService : BackgroundService
|
|||||||
private CancellationTokenSource? _cancelCurrentJob;
|
private CancellationTokenSource? _cancelCurrentJob;
|
||||||
private bool? _lastAeOpen;
|
private bool? _lastAeOpen;
|
||||||
|
|
||||||
public WorkerService(WorkerOptions options, ApiClient api, JobExecutor executor, ReportSpooler spooler, ILogger<WorkerService> log)
|
public WorkerService(WorkerOptions options, ApiClient api, JobExecutor executor, ReportSpooler spooler,
|
||||||
|
HighResUploader highRes, ILogger<WorkerService> log)
|
||||||
{
|
{
|
||||||
|
_highRes = highRes;
|
||||||
_options = options;
|
_options = options;
|
||||||
_api = api;
|
_api = api;
|
||||||
_executor = executor;
|
_executor = executor;
|
||||||
@@ -40,6 +43,7 @@ public sealed class WorkerService : BackgroundService
|
|||||||
_ = Task.Run(() => _spooler.RunAsync(stoppingToken), stoppingToken);
|
_ = Task.Run(() => _spooler.RunAsync(stoppingToken), stoppingToken);
|
||||||
|
|
||||||
await RegisterWithRetryAsync(stoppingToken);
|
await RegisterWithRetryAsync(stoppingToken);
|
||||||
|
_ = Task.Run(() => _highRes.RunAsync(stoppingToken), stoppingToken);
|
||||||
await _api.ReportVersionAsync(_options, stoppingToken);
|
await _api.ReportVersionAsync(_options, stoppingToken);
|
||||||
await _executor.ReconcileAsync(_machineId!, stoppingToken);
|
await _executor.ReconcileAsync(_machineId!, stoppingToken);
|
||||||
|
|
||||||
|
|||||||
+42
-8
@@ -32,7 +32,7 @@ var SETTINGS_KEY = "cfg";
|
|||||||
// Bump on every change deployed to a workstation. The panel reports this to
|
// Bump on every change deployed to a workstation. The panel reports this to
|
||||||
// the server on load, so Pipeline → Machines shows which version each machine
|
// the server on load, so Pipeline → Machines shows which version each machine
|
||||||
// is actually running and flags the ones left behind.
|
// is actually running and flags the ones left behind.
|
||||||
var PANEL_VERSION = "2.6.2";
|
var PANEL_VERSION = "2.7.1";
|
||||||
|
|
||||||
(function VFXReviewConnector(thisObj) {
|
(function VFXReviewConnector(thisObj) {
|
||||||
var uiState = {
|
var uiState = {
|
||||||
@@ -45,6 +45,8 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
pipelineStatusText: null,
|
pipelineStatusText: null,
|
||||||
urgentCheckbox: null,
|
urgentCheckbox: null,
|
||||||
skipPreviewCheckbox: null,
|
skipPreviewCheckbox: null,
|
||||||
|
handlesCheckbox: null,
|
||||||
|
handleFramesField: null,
|
||||||
submissionNoteField: null,
|
submissionNoteField: null,
|
||||||
qcList: null,
|
qcList: null,
|
||||||
qcNotesField: null,
|
qcNotesField: null,
|
||||||
@@ -3476,6 +3478,9 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
CONFIG.bannerImagePath = trimText(fBanner.text);
|
CONFIG.bannerImagePath = trimText(fBanner.text);
|
||||||
CONFIG.artistEmail = trimText(fEmail.text);
|
CONFIG.artistEmail = trimText(fEmail.text);
|
||||||
CONFIG.handleFrames = parseInt(fHandles.text, 10) || 8;
|
CONFIG.handleFrames = parseInt(fHandles.text, 10) || 8;
|
||||||
|
if (uiState.handleFramesField) {
|
||||||
|
uiState.handleFramesField.text = String(CONFIG.handleFrames);
|
||||||
|
}
|
||||||
CONFIG.pathMappings = trimText(fMappings.text);
|
CONFIG.pathMappings = trimText(fMappings.text);
|
||||||
CONFIG.sequenceStart = parseInt(fSeqStart.text, 10) || 1001;
|
CONFIG.sequenceStart = parseInt(fSeqStart.text, 10) || 1001;
|
||||||
saveConfig();
|
saveConfig();
|
||||||
@@ -4196,7 +4201,23 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
return manifest;
|
return manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handles the render carries past the cut. Review metadata only: the web
|
||||||
|
// player marks these frames as "not in edit". Nothing in the comp or the
|
||||||
|
// render changes — unticked just means the frames are all in the edit.
|
||||||
|
function reviewHandles() {
|
||||||
|
var frames;
|
||||||
|
if (!uiState.handlesCheckbox || !uiState.handlesCheckbox.value) {
|
||||||
|
return { handleHead: 0, handleTail: 0 };
|
||||||
|
}
|
||||||
|
frames = parseInt(uiState.handleFramesField ? uiState.handleFramesField.text : "", 10);
|
||||||
|
if (isNaN(frames) || frames < 0) {
|
||||||
|
frames = CONFIG.handleFrames;
|
||||||
|
}
|
||||||
|
return { handleHead: frames, handleTail: frames };
|
||||||
|
}
|
||||||
|
|
||||||
function submitExport(manifest, urgent, force) {
|
function submitExport(manifest, urgent, force) {
|
||||||
|
manifest.review = reviewHandles();
|
||||||
var body = {
|
var body = {
|
||||||
manifest: manifest,
|
manifest: manifest,
|
||||||
force: force ? true : false
|
force: force ? true : false
|
||||||
@@ -4689,7 +4710,6 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
var importRendersButton;
|
var importRendersButton;
|
||||||
var btnRow6;
|
var btnRow6;
|
||||||
var pictureLockButton;
|
var pictureLockButton;
|
||||||
var btnRow7;
|
|
||||||
var incrementVersionButton;
|
var incrementVersionButton;
|
||||||
var btnRow6b;
|
var btnRow6b;
|
||||||
var setStartTCButton;
|
var setStartTCButton;
|
||||||
@@ -4803,6 +4823,25 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
"un-punched-in EXRs — where a preview rebuilt from these frames\n" +
|
"un-punched-in EXRs — where a preview rebuilt from these frames\n" +
|
||||||
"would be the wrong picture.";
|
"would be the wrong picture.";
|
||||||
|
|
||||||
|
var handlesGroup = pipelinePanel.add("group");
|
||||||
|
handlesGroup.orientation = "row";
|
||||||
|
handlesGroup.alignChildren = ["left", "center"];
|
||||||
|
handlesGroup.spacing = 6;
|
||||||
|
uiState.handlesCheckbox = handlesGroup.add("checkbox", undefined, "Includes handles");
|
||||||
|
uiState.handlesCheckbox.value = true;
|
||||||
|
uiState.handleFramesField = handlesGroup.add("edittext", undefined, String(CONFIG.handleFrames));
|
||||||
|
uiState.handleFramesField.characters = 3;
|
||||||
|
handlesGroup.add("statictext", undefined, "frames each end");
|
||||||
|
uiState.handlesCheckbox.helpTip =
|
||||||
|
"The render runs past the cut at both ends (handles). The review\n" +
|
||||||
|
"player marks those frames HANDLE / NOT IN EDIT so a glitch in a\n" +
|
||||||
|
"handle isn't mistaken for a problem in the shot.\n\n" +
|
||||||
|
"Review-only: nothing is burned in and the EXRs are unchanged.\n" +
|
||||||
|
"Untick for a render cut exactly to the edit.";
|
||||||
|
uiState.handlesCheckbox.onClick = function () {
|
||||||
|
uiState.handleFramesField.enabled = uiState.handlesCheckbox.value;
|
||||||
|
};
|
||||||
|
|
||||||
var slateNoteGroup = pipelinePanel.add("group");
|
var slateNoteGroup = pipelinePanel.add("group");
|
||||||
slateNoteGroup.orientation = "row";
|
slateNoteGroup.orientation = "row";
|
||||||
slateNoteGroup.alignChildren = ["fill", "top"];
|
slateNoteGroup.alignChildren = ["fill", "top"];
|
||||||
@@ -4828,6 +4867,7 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
"Rebuild the MOV/MP4 slate and burn-ins for the delivered version.\n" +
|
"Rebuild the MOV/MP4 slate and burn-ins for the delivered version.\n" +
|
||||||
"Reuses the rendered EXRs and keeps the version number. Slate text is\n" +
|
"Reuses the rendered EXRs and keeps the version number. Slate text is\n" +
|
||||||
"re-read from the shot, so fix it on the web app's Slate tab first.";
|
"re-read from the shot, so fix it on the web app's Slate tab first.";
|
||||||
|
incrementVersionButton = pipelineRow3.add("button", undefined, "Increment Shot Version");
|
||||||
|
|
||||||
qcPanel = scrollContent.add("panel", undefined, "QC");
|
qcPanel = scrollContent.add("panel", undefined, "QC");
|
||||||
qcPanel.orientation = "column";
|
qcPanel.orientation = "column";
|
||||||
@@ -4934,12 +4974,6 @@ var PANEL_VERSION = "2.6.2";
|
|||||||
btnRow6b.spacing = 6;
|
btnRow6b.spacing = 6;
|
||||||
setStartTCButton = btnRow6b.add("button", undefined, "Set Start Timecode");
|
setStartTCButton = btnRow6b.add("button", undefined, "Set Start Timecode");
|
||||||
|
|
||||||
btnRow7 = buttonsPanel.add("group");
|
|
||||||
btnRow7.orientation = "row";
|
|
||||||
btnRow7.alignChildren = ["fill", "center"];
|
|
||||||
btnRow7.spacing = 6;
|
|
||||||
incrementVersionButton = btnRow7.add("button", undefined, "Increment Shot Version");
|
|
||||||
|
|
||||||
workspacePanel = scrollContent.add("panel", undefined, "Workspace");
|
workspacePanel = scrollContent.add("panel", undefined, "Workspace");
|
||||||
workspacePanel.orientation = "column";
|
workspacePanel.orientation = "column";
|
||||||
workspacePanel.alignChildren = ["fill", "top"];
|
workspacePanel.alignChildren = ["fill", "top"];
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ Same applies to `footageRoot`: change `V:/_FOOTAGE/UNG` → `V:/_FOOTAGE`.
|
|||||||
The panel is divided into seven sections:
|
The panel is divided into seven sections:
|
||||||
|
|
||||||
1. **Shot Builder** — Episode/shot selection and comp creation
|
1. **Shot Builder** — Episode/shot selection and comp creation
|
||||||
2. **Render Pipeline** — Queue Export, status polling, retry, regenerate previews
|
2. **Render Pipeline** — Queue Export, status polling, retry, regenerate previews, increment shot version
|
||||||
3. **QC** — Technical QC queue for rendered exports
|
3. **QC** — Technical QC queue for rendered exports
|
||||||
4. **Actions** — Per-shot and batch operations
|
4. **Actions** — Per-shot and batch operations
|
||||||
5. **Workspace** — One-time project initialisation
|
5. **Workspace** — One-time project initialisation
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const saveAnnotationSchema = z.object({
|
|||||||
shapes: z.array(z.any()),
|
shapes: z.array(z.any()),
|
||||||
canvasWidth: z.number(),
|
canvasWidth: z.number(),
|
||||||
canvasHeight: z.number(),
|
canvasHeight: z.number(),
|
||||||
version: z.literal("1.0"),
|
version: z.enum(["1.0", "2.0"]),
|
||||||
}),
|
}),
|
||||||
color: z.string().default("#ef4444"),
|
color: z.string().default("#ef4444"),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { revalidatePath } from "next/cache";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ShotStatus, ShotPriority, ShotApprovalStatus, Prisma } from "@prisma/client";
|
import { ShotStatus, ShotPriority, ShotApprovalStatus, Prisma } from "@prisma/client";
|
||||||
import { recalcShotStatus, markShotForRevisions } from "@/lib/shot-status";
|
import { recalcShotStatus, markShotForRevisions } from "@/lib/shot-status";
|
||||||
|
import { countShotsOnOpenRequests } from "@/lib/render-pipeline/delivery-requests";
|
||||||
|
|
||||||
const createShotSchema = z.object({
|
const createShotSchema = z.object({
|
||||||
scene: z.string().min(1).max(50).regex(/^[A-Z0-9_]+$/i, "Alphanumeric and underscore only"),
|
scene: z.string().min(1).max(50).regex(/^[A-Z0-9_]+$/i, "Alphanumeric and underscore only"),
|
||||||
@@ -652,6 +653,150 @@ export async function bulkUpdateDueDates(
|
|||||||
return { success: true, updated: shots.length };
|
return { success: true, updated: shots.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Bulk Assign Artist ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point a selection of shots at one artist, or clear the assignment when
|
||||||
|
* `artistId` is null. Mirrors the single-shot artist field in updateShot —
|
||||||
|
* the assignment is a plain column write with no notification, so reassigning
|
||||||
|
* a batch during planning stays quiet.
|
||||||
|
*/
|
||||||
|
export async function bulkAssignArtist(shotIds: string[], artistId: string | null) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) throw new Error("Unauthorized");
|
||||||
|
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||||
|
throw new Error("Insufficient permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
const ids = z.array(z.string().cuid()).parse(shotIds);
|
||||||
|
if (!ids.length) return { success: true, updated: 0, artistName: null as string | null };
|
||||||
|
|
||||||
|
let artistName: string | null = null;
|
||||||
|
if (artistId) {
|
||||||
|
const artist = await db.user.findUnique({
|
||||||
|
where: { id: z.string().cuid().parse(artistId) },
|
||||||
|
select: { id: true, name: true, email: true, role: true, isActive: true },
|
||||||
|
});
|
||||||
|
// A deactivated user or a client account must never end up owning a shot,
|
||||||
|
// so this is checked here rather than trusting whatever the picker sent.
|
||||||
|
if (!artist || !artist.isActive || artist.role === "CLIENT") {
|
||||||
|
throw new Error("That user cannot be assigned shots");
|
||||||
|
}
|
||||||
|
artistName = artist.name ?? artist.email;
|
||||||
|
}
|
||||||
|
|
||||||
|
const shots = await db.shot.findMany({
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
select: { id: true, projectId: true },
|
||||||
|
});
|
||||||
|
if (shots.length !== ids.length) throw new Error("Some shots not found");
|
||||||
|
|
||||||
|
await db.shot.updateMany({
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
data: { artistId },
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const pid of [...new Set(shots.map((s) => s.projectId))]) {
|
||||||
|
revalidatePath(`/projects/${pid}`);
|
||||||
|
}
|
||||||
|
revalidatePath(`/shot-status`);
|
||||||
|
|
||||||
|
return { success: true, updated: shots.length, artistName };
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Bulk Manual Delivery ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record that a selection of shots was delivered outside the render pipeline
|
||||||
|
* (by hand, before packages existed), or clear that record when
|
||||||
|
* `deliveredOn` is null. The delivery countdown counts these alongside
|
||||||
|
* DELIVERED EXR packages (lib/dashboard/ops.ts).
|
||||||
|
*
|
||||||
|
* `deliveredOn` is the day the frames went out ("yyyy-MM-dd"), stored at
|
||||||
|
* noon UTC so the calendar day survives any timezone it is shown in.
|
||||||
|
*/
|
||||||
|
export async function bulkSetManualDelivery(
|
||||||
|
shotIds: string[],
|
||||||
|
deliveredOn: string | null,
|
||||||
|
note?: string,
|
||||||
|
/** Where it was uploaded and who was sent the link. */
|
||||||
|
evidence?: { uploadUrl?: string; sharedWith?: string },
|
||||||
|
) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) throw new Error("Unauthorized");
|
||||||
|
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||||
|
throw new Error("Insufficient permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
const ids = z.array(z.string().cuid()).parse(shotIds);
|
||||||
|
if (!ids.length) return { success: true as const, updated: 0 };
|
||||||
|
|
||||||
|
let deliveredAt: Date | null = null;
|
||||||
|
if (deliveredOn) {
|
||||||
|
const day = z.string().regex(/^\d{4}-\d{2}-\d{2}$/).parse(deliveredOn);
|
||||||
|
deliveredAt = new Date(`${day}T12:00:00.000Z`);
|
||||||
|
if (Number.isNaN(deliveredAt.getTime())) throw new Error("Invalid delivery date");
|
||||||
|
if (deliveredAt.getTime() > Date.now() + 24 * 60 * 60 * 1000) {
|
||||||
|
throw new Error("A delivery date can't be in the future");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const shots = await db.shot.findMany({
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
select: { id: true, projectId: true },
|
||||||
|
});
|
||||||
|
if (shots.length !== ids.length) throw new Error("Some shots not found");
|
||||||
|
|
||||||
|
const trimmedNote = note?.trim() || null;
|
||||||
|
const uploadUrl = evidence?.uploadUrl?.trim() || null;
|
||||||
|
const sharedWith = evidence?.sharedWith?.trim() || null;
|
||||||
|
if (uploadUrl && !/^https?:\/\/\S+$/i.test(uploadUrl)) {
|
||||||
|
return { success: false as const, error: "The upload link must be a full http(s) link" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// A backfill of old deliveries may have no link to give. A shot a client is
|
||||||
|
// waiting on is different: without the link and recipient the request it
|
||||||
|
// answers would stay open, so say so now rather than leave it unexplained.
|
||||||
|
if (deliveredAt && (!uploadUrl || !sharedWith)) {
|
||||||
|
const owed = await countShotsOnOpenRequests(ids);
|
||||||
|
if (owed > 0) {
|
||||||
|
// Returned, not thrown: a production build replaces a thrown action
|
||||||
|
// error with a generic message, and this one has to reach the person.
|
||||||
|
return {
|
||||||
|
success: false as const,
|
||||||
|
error: `${owed} of these shots ${owed === 1 ? "is" : "are"} on an open delivery request — add the upload link and who it was sent to`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.shot.updateMany({
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
data: deliveredAt
|
||||||
|
? {
|
||||||
|
manualDeliveredAt: deliveredAt,
|
||||||
|
manualDeliveredById: session.user.id,
|
||||||
|
manualDeliveryNote: trimmedNote,
|
||||||
|
manualDeliveryUrl: uploadUrl,
|
||||||
|
manualDeliverySharedWith: sharedWith,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
manualDeliveredAt: null,
|
||||||
|
manualDeliveredById: null,
|
||||||
|
manualDeliveryNote: null,
|
||||||
|
manualDeliveryUrl: null,
|
||||||
|
manualDeliverySharedWith: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const pid of [...new Set(shots.map((s) => s.projectId))]) {
|
||||||
|
revalidatePath(`/projects/${pid}`);
|
||||||
|
}
|
||||||
|
revalidatePath(`/shot-status`);
|
||||||
|
revalidatePath(`/dashboard`);
|
||||||
|
|
||||||
|
return { success: true as const, updated: shots.length };
|
||||||
|
}
|
||||||
|
|
||||||
// ── Bulk Delete Shots ─────────────────────────────────────────────────────────
|
// ── Bulk Delete Shots ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export async function bulkDeleteShots(shotIds: string[]) {
|
export async function bulkDeleteShots(shotIds: string[]) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { z } from "zod";
|
|||||||
import { recalcShotStatus, clearStaleShotApproval } from "@/lib/shot-status";
|
import { recalcShotStatus, clearStaleShotApproval } from "@/lib/shot-status";
|
||||||
import { notifyNewVersionUploaded } from "@/lib/notifications";
|
import { notifyNewVersionUploaded } from "@/lib/notifications";
|
||||||
import { slackNotifyVersionUploaded } from "@/lib/slack";
|
import { slackNotifyVersionUploaded } from "@/lib/slack";
|
||||||
|
import { deleteStorageKeys, highResStorageKeys } from "@/lib/render-pipeline/high-res";
|
||||||
|
|
||||||
const createVersionSchema = z.object({
|
const createVersionSchema = z.object({
|
||||||
taskId: z.string().cuid(),
|
taskId: z.string().cuid(),
|
||||||
@@ -185,6 +186,8 @@ export async function deleteVersion(versionId: string) {
|
|||||||
id: true,
|
id: true,
|
||||||
isLatest: true,
|
isLatest: true,
|
||||||
taskId: true,
|
taskId: true,
|
||||||
|
hqFileUrl: true,
|
||||||
|
highResKey: true,
|
||||||
task: { select: { projectId: true, shotId: true } },
|
task: { select: { projectId: true, shotId: true } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -203,6 +206,8 @@ export async function deleteVersion(versionId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await db.version.delete({ where: { id: versionId } });
|
await db.version.delete({ where: { id: versionId } });
|
||||||
|
// Its High quality MP4 and ProRes are large and referenced by nothing else.
|
||||||
|
await deleteStorageKeys(highResStorageKeys(version));
|
||||||
|
|
||||||
const projectId = version.task?.projectId;
|
const projectId = version.task?.projectId;
|
||||||
const shotId = version.task?.shotId;
|
const shotId = version.task?.shotId;
|
||||||
@@ -259,3 +264,35 @@ export async function getVersionComments(versionId: string) {
|
|||||||
orderBy: { frameNumber: "asc" },
|
orderBy: { frameNumber: "asc" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateVersionHandlesSchema = z.object({
|
||||||
|
versionId: z.string().cuid(),
|
||||||
|
/** 0/0 = no handles (every frame is in the edit). */
|
||||||
|
handleHead: z.number().int().min(0).max(1000),
|
||||||
|
handleTail: z.number().int().min(0).max(1000),
|
||||||
|
/** Slate frames before the picture; null = infer from the media. */
|
||||||
|
pictureStartFrame: z.number().int().min(0).max(1000).nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks which frames of a version are handles (past the cut at each end), so
|
||||||
|
* the review player can flag them. Review metadata only — the media and any
|
||||||
|
* delivered files are untouched. Staff only: a client can't redefine the cut.
|
||||||
|
*/
|
||||||
|
export async function updateVersionHandles(data: z.infer<typeof updateVersionHandlesSchema>) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) throw new Error("Unauthorized");
|
||||||
|
if (session.user.role === "CLIENT") throw new Error("Forbidden");
|
||||||
|
|
||||||
|
const parsed = updateVersionHandlesSchema.parse(data);
|
||||||
|
const none = parsed.handleHead === 0 && parsed.handleTail === 0;
|
||||||
|
await db.version.update({
|
||||||
|
where: { id: parsed.versionId },
|
||||||
|
data: {
|
||||||
|
handleHead: none ? null : parsed.handleHead,
|
||||||
|
handleTail: none ? null : parsed.handleTail,
|
||||||
|
pictureStartFrame: parsed.pictureStartFrame,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
revalidatePath(`/review/${parsed.versionId}`);
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export default async function ClientDetailPage({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-5xl mx-auto space-y-6">
|
<div className="p-4 md:p-6 max-w-5xl mx-auto space-y-6">
|
||||||
{/* Back */}
|
{/* Back */}
|
||||||
<Link
|
<Link
|
||||||
href="/clients"
|
href="/clients"
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default async function ClientsPage() {
|
|||||||
const clients = await getClients();
|
const clients = await getClients();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-5xl mx-auto space-y-6">
|
<div className="p-4 md:p-6 max-w-5xl mx-auto space-y-6">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,58 +1,69 @@
|
|||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { StatsCards } from "@/components/dashboard/StatsCards";
|
import { StatsCards } from "@/components/dashboard/StatsCards";
|
||||||
|
import { BlockedQueue } from "@/components/dashboard/BlockedQueue";
|
||||||
|
import { FarmStrip } from "@/components/dashboard/FarmStrip";
|
||||||
|
import { DeliveryCountdown } from "@/components/dashboard/DeliveryCountdown";
|
||||||
|
import { QcQueue } from "@/components/dashboard/QcQueue";
|
||||||
|
import { AwaitingDelivery } from "@/components/dashboard/AwaitingDelivery";
|
||||||
|
import { LogRequestButton } from "@/components/dashboard/LogRequestButton";
|
||||||
|
import { RecentDeliveries } from "@/components/dashboard/RecentDeliveries";
|
||||||
|
import { WhoseCourt } from "@/components/dashboard/WhoseCourt";
|
||||||
import { ShotQueue } from "@/components/dashboard/ShotQueue";
|
import { ShotQueue } from "@/components/dashboard/ShotQueue";
|
||||||
import { RecentActivity } from "@/components/dashboard/RecentActivity";
|
|
||||||
import { TaskWidgets } from "@/components/dashboard/TaskWidgets";
|
import { TaskWidgets } from "@/components/dashboard/TaskWidgets";
|
||||||
import { ScheduleWidgets } from "@/components/dashboard/ScheduleWidgets";
|
import { ScheduleWidgets } from "@/components/dashboard/ScheduleWidgets";
|
||||||
|
import {
|
||||||
|
getAwaitingDelivery,
|
||||||
|
getBlockedExports,
|
||||||
|
getDeliveryCountdown,
|
||||||
|
getFarmStatus,
|
||||||
|
getOpsCounts,
|
||||||
|
getQcQueue,
|
||||||
|
getQcStaleHours,
|
||||||
|
getRecentDeliveries,
|
||||||
|
getWhoseCourt,
|
||||||
|
} from "@/lib/dashboard/ops";
|
||||||
|
import { listDeliveryRequests } from "@/lib/render-pipeline/delivery-requests";
|
||||||
import type { DashboardStats } from "@/types";
|
import type { DashboardStats } from "@/types";
|
||||||
|
|
||||||
export const metadata = { title: "Dashboard" };
|
export const metadata = { title: "Dashboard" };
|
||||||
|
|
||||||
|
// Queue depth and machine state are stale the moment they are cached.
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dashboard answers one question: can we ship what is due, and what is
|
||||||
|
* stopping us? Everything on it is pipeline state — exports, QC, deliveries,
|
||||||
|
* worker heartbeats — rather than anything a person has to maintain by hand.
|
||||||
|
*/
|
||||||
async function getDashboardData(userId: string, role: string) {
|
async function getDashboardData(userId: string, role: string) {
|
||||||
const isArtist = role === "ARTIST";
|
const isArtist = role === "ARTIST";
|
||||||
const isClient = role === "CLIENT";
|
const isClient = role === "CLIENT";
|
||||||
const now = new Date();
|
|
||||||
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
||||||
const todayEnd = new Date(todayStart.getTime() + 86400000);
|
|
||||||
|
|
||||||
const [awaitingReview, needsRevisions, approved, activeProjects,
|
// Producers see the floor; an artist sees the failures that are theirs.
|
||||||
tasksDueToday, tasksInReview, tasksOverdue, myTasksCount] =
|
const [counts, blocked, farm, episodes, qcQueue, qcStaleHours, deliveries, awaitingDelivery, openRequests, court] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.version.count({ where: { approvalStatus: "PENDING_REVIEW" } }),
|
getOpsCounts(isArtist ? userId : undefined),
|
||||||
db.version.count({ where: { approvalStatus: "NEEDS_CHANGES" } }),
|
getBlockedExports(isArtist ? { artistId: userId } : {}),
|
||||||
db.version.count({ where: { approvalStatus: "APPROVED" } }),
|
getFarmStatus(),
|
||||||
db.project.count({ where: { status: "ACTIVE" } }),
|
getDeliveryCountdown(),
|
||||||
db.task.count({
|
isArtist || isClient ? [] : getQcQueue(),
|
||||||
where: {
|
getQcStaleHours(),
|
||||||
dueDate: { gte: todayStart, lt: todayEnd },
|
isArtist || isClient ? [] : getRecentDeliveries(),
|
||||||
status: { not: "DONE" },
|
isArtist || isClient ? [] : getAwaitingDelivery(),
|
||||||
...(isArtist ? { assignedArtistId: userId } : {}),
|
isArtist || isClient ? [] : listDeliveryRequests({ openOnly: true }),
|
||||||
},
|
isArtist || isClient ? null : getWhoseCourt(),
|
||||||
}),
|
|
||||||
db.task.count({
|
|
||||||
where: {
|
|
||||||
status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] },
|
|
||||||
...(isArtist ? { assignedArtistId: userId } : {}),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
db.task.count({
|
|
||||||
where: {
|
|
||||||
dueDate: { lt: todayStart },
|
|
||||||
status: { not: "DONE" },
|
|
||||||
...(isArtist ? { assignedArtistId: userId } : {}),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
db.task.count({
|
|
||||||
where: { assignedArtistId: userId, status: { not: "DONE" } },
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const shotsWhere = isArtist ? { artistId: userId } : {};
|
// An artist's own shots come first; everyone else sees the floor.
|
||||||
const shots = await db.shot.findMany({
|
const shots = await db.shot.findMany({
|
||||||
where: { ...shotsWhere, status: { not: "COMPLETE" } },
|
where: {
|
||||||
|
...(isArtist ? { artistId: userId } : {}),
|
||||||
|
status: { not: "COMPLETE" },
|
||||||
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
|
},
|
||||||
take: 15,
|
take: 15,
|
||||||
orderBy: { updatedAt: "desc" },
|
orderBy: [{ dueDate: { sort: "asc", nulls: "last" } }, { updatedAt: "desc" }],
|
||||||
include: {
|
include: {
|
||||||
artist: { select: { id: true, name: true, image: true, email: true } },
|
artist: { select: { id: true, name: true, image: true, email: true } },
|
||||||
versions: {
|
versions: {
|
||||||
@@ -63,12 +74,8 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// My tasks (for widget)
|
|
||||||
const myTasks = await db.task.findMany({
|
const myTasks = await db.task.findMany({
|
||||||
where: {
|
where: { assignedArtistId: userId, status: { not: "DONE" } },
|
||||||
assignedArtistId: userId,
|
|
||||||
status: { not: "DONE" },
|
|
||||||
},
|
|
||||||
take: 8,
|
take: 8,
|
||||||
orderBy: [{ dueDate: "asc" }, { priority: "desc" }],
|
orderBy: [{ dueDate: "asc" }, { priority: "desc" }],
|
||||||
include: {
|
include: {
|
||||||
@@ -78,7 +85,6 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tasks in review (for supervisors/producers)
|
|
||||||
const reviewTasks = isArtist || isClient ? [] : await db.task.findMany({
|
const reviewTasks = isArtist || isClient ? [] : await db.task.findMany({
|
||||||
where: { status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] } },
|
where: { status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] } },
|
||||||
take: 8,
|
take: 8,
|
||||||
@@ -91,14 +97,8 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const activity = await db.notification.findMany({
|
// Schedule overview (producers/supervisors/admins) — unchanged; it reads the
|
||||||
where: isClient ? { userId } : {},
|
// schedule page's own data rather than anything the pipeline owns.
|
||||||
take: 20,
|
|
||||||
orderBy: { createdAt: "desc" },
|
|
||||||
include: { user: { select: { name: true, image: true } } },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Schedule data (for producers/supervisors/admins)
|
|
||||||
const scheduledTasks =
|
const scheduledTasks =
|
||||||
!isArtist && !isClient
|
!isArtist && !isClient
|
||||||
? await db.task.findMany({
|
? await db.task.findMany({
|
||||||
@@ -119,46 +119,59 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
!isArtist && !isClient
|
!isArtist && !isClient
|
||||||
? await db.user.findMany({
|
? await db.user.findMany({
|
||||||
where: { isActive: true, role: { not: "CLIENT" } },
|
where: { isActive: true, role: { not: "CLIENT" } },
|
||||||
select: {
|
select: { id: true, name: true, email: true, image: true, role: true },
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
email: true,
|
|
||||||
image: true,
|
|
||||||
role: true,
|
|
||||||
},
|
|
||||||
orderBy: { name: "asc" },
|
orderBy: { name: "asc" },
|
||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const stats: DashboardStats = {
|
const stats: DashboardStats = counts;
|
||||||
awaitingReview,
|
|
||||||
needsRevisions,
|
|
||||||
approved,
|
|
||||||
overdue: tasksOverdue,
|
|
||||||
activeProjects,
|
|
||||||
tasksDueToday,
|
|
||||||
tasksInReview,
|
|
||||||
tasksOverdue,
|
|
||||||
myTasksCount,
|
|
||||||
};
|
|
||||||
|
|
||||||
return { stats, shots, activity, myTasks, reviewTasks, scheduledTasks, scheduleArtists };
|
return {
|
||||||
|
stats,
|
||||||
|
blocked,
|
||||||
|
farm,
|
||||||
|
episodes,
|
||||||
|
qcQueue,
|
||||||
|
qcStaleHours,
|
||||||
|
deliveries,
|
||||||
|
awaitingDelivery,
|
||||||
|
openRequests,
|
||||||
|
court,
|
||||||
|
shots,
|
||||||
|
myTasks,
|
||||||
|
reviewTasks,
|
||||||
|
scheduledTasks,
|
||||||
|
scheduleArtists,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function DashboardPage() {
|
export default async function DashboardPage() {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user) return null;
|
if (!session?.user) return null;
|
||||||
|
|
||||||
const { stats, shots, activity, myTasks, reviewTasks, scheduledTasks, scheduleArtists } =
|
|
||||||
await getDashboardData(session.user.id, session.user.role);
|
|
||||||
|
|
||||||
const isClient = session.user.role === "CLIENT";
|
const isClient = session.user.role === "CLIENT";
|
||||||
const canSeeSchedule = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(
|
const isArtistRole = session.user.role === "ARTIST";
|
||||||
session.user.role
|
const canSeeSchedule = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
||||||
);
|
const {
|
||||||
|
stats,
|
||||||
|
blocked,
|
||||||
|
farm,
|
||||||
|
episodes,
|
||||||
|
qcQueue,
|
||||||
|
qcStaleHours,
|
||||||
|
deliveries,
|
||||||
|
awaitingDelivery,
|
||||||
|
openRequests,
|
||||||
|
court,
|
||||||
|
shots,
|
||||||
|
myTasks,
|
||||||
|
reviewTasks,
|
||||||
|
scheduledTasks,
|
||||||
|
scheduleArtists,
|
||||||
|
} = await getDashboardData(session.user.id, session.user.role);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8 space-y-6 max-w-[1600px] mx-auto">
|
<div className="p-4 md:p-8 space-y-6 max-w-[1600px] mx-auto">
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<h1 className="text-3xl font-bold text-white">Dashboard</h1>
|
<h1 className="text-3xl font-bold text-white">Dashboard</h1>
|
||||||
<p className="text-zinc-400 mt-1">
|
<p className="text-zinc-400 mt-1">
|
||||||
@@ -166,7 +179,82 @@ export default async function DashboardPage() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<StatsCards stats={stats} />
|
{!isClient && <StatsCards stats={stats} />}
|
||||||
|
|
||||||
|
{/* Rows only clear by being dealt with; the heading stays so there is
|
||||||
|
always somewhere to log what a client just asked for. */}
|
||||||
|
{!isClient && !isArtistRole && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<h2
|
||||||
|
className={
|
||||||
|
openRequests.length + awaitingDelivery.length > 0
|
||||||
|
? "text-sm font-semibold text-amber-400 uppercase tracking-wide"
|
||||||
|
: "text-sm font-semibold text-muted-foreground uppercase tracking-wide"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Awaiting delivery
|
||||||
|
</h2>
|
||||||
|
{canSeeSchedule && <LogRequestButton />}
|
||||||
|
</div>
|
||||||
|
<AwaitingDelivery requests={openRequests} packages={awaitingDelivery} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isClient && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Delivery countdown
|
||||||
|
</h2>
|
||||||
|
<DeliveryCountdown episodes={episodes} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isClient && (
|
||||||
|
<div id="blocked" className="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start scroll-mt-6">
|
||||||
|
<div className="xl:col-span-2 space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
{isArtistRole ? "Your blocked shots" : "Blocked — needs a human"}
|
||||||
|
</h2>
|
||||||
|
<BlockedQueue blocked={blocked} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Render farm
|
||||||
|
</h2>
|
||||||
|
<FarmStrip farm={farm} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isClient && !isArtistRole && (
|
||||||
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start">
|
||||||
|
<div className="xl:col-span-2 space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
QC queue
|
||||||
|
</h2>
|
||||||
|
<QcQueue entries={qcQueue} staleHours={qcStaleHours} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Deliveries
|
||||||
|
</h2>
|
||||||
|
<RecentDeliveries deliveries={deliveries} />
|
||||||
|
</div>
|
||||||
|
{court && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Whose court
|
||||||
|
</h2>
|
||||||
|
<WhoseCourt court={court} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{!isClient && (
|
{!isClient && (
|
||||||
<TaskWidgets
|
<TaskWidgets
|
||||||
@@ -181,32 +269,18 @@ export default async function DashboardPage() {
|
|||||||
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
Schedule Overview
|
Schedule Overview
|
||||||
</h2>
|
</h2>
|
||||||
<ScheduleWidgets
|
<ScheduleWidgets scheduledTasks={scheduledTasks as any} artists={scheduleArtists} />
|
||||||
scheduledTasks={scheduledTasks as any}
|
|
||||||
artists={scheduleArtists}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
<div className="space-y-3">
|
||||||
<div className="xl:col-span-2 space-y-3">
|
|
||||||
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
Shot Queue
|
{session.user.role === "ARTIST" ? "My shots" : "Shots in flight"}
|
||||||
</h2>
|
</h2>
|
||||||
<div className="rounded-lg border border-border bg-card p-1">
|
<div className="rounded-lg border border-border bg-card p-1">
|
||||||
<ShotQueue shots={shots as any} />
|
<ShotQueue shots={shots as any} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-3">
|
|
||||||
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
||||||
Recent Activity
|
|
||||||
</h2>
|
|
||||||
<div className="rounded-lg border border-border bg-card h-[400px] overflow-hidden">
|
|
||||||
<RecentActivity activities={activity as any} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { auth } from "@/auth";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { Sidebar } from "@/components/layout/Sidebar";
|
import { Sidebar } from "@/components/layout/Sidebar";
|
||||||
import { Header } from "@/components/layout/Header";
|
import { Header } from "@/components/layout/Header";
|
||||||
|
import { MobileNavProvider } from "@/components/layout/MobileNav";
|
||||||
|
|
||||||
export default async function DashboardLayout({
|
export default async function DashboardLayout({
|
||||||
children,
|
children,
|
||||||
@@ -12,6 +13,7 @@ export default async function DashboardLayout({
|
|||||||
if (!session?.user) redirect("/login");
|
if (!session?.user) redirect("/login");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<MobileNavProvider>
|
||||||
<div className="flex h-screen bg-zinc-950 overflow-hidden print:block print:h-auto print:overflow-visible">
|
<div className="flex h-screen bg-zinc-950 overflow-hidden print:block print:h-auto print:overflow-visible">
|
||||||
<div className="print:hidden">
|
<div className="print:hidden">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
@@ -25,5 +27,6 @@ export default async function DashboardLayout({
|
|||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</MobileNavProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { RefreshCw, RotateCcw, XCircle, CheckCircle2, Server, Package } from "lucide-react";
|
import { RefreshCw, RotateCcw, XCircle, CheckCircle2, Server, Package, ChevronLeft, ChevronRight, Search, X } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
import { Progress } from "@/components/ui/progress";
|
import { Progress } from "@/components/ui/progress";
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -51,37 +53,79 @@ interface QueueExport {
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
projects: { id: string; name: string; code: string }[];
|
projects: { id: string; name: string; code: string }[];
|
||||||
|
/** Status to open filtered to, from `?status=` (see page.tsx). */
|
||||||
|
initialStatus?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PipelineQueueClient({ projects }: Props) {
|
const PAGE_SIZE = 25;
|
||||||
|
|
||||||
|
const BLENDER_ACTIVE = ["QUEUED", "CLAIMED", "RUNNING"];
|
||||||
|
|
||||||
|
export function PipelineQueueClient({ projects, initialStatus = "all" }: Props) {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [projectId, setProjectId] = useState<string>("all");
|
const [projectId, setProjectId] = useState<string>("all");
|
||||||
const [statusFilter, setStatusFilter] = useState<string>("all");
|
const [statusFilter, setStatusFilter] = useState<string>(initialStatus);
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [searchInput, setSearchInput] = useState("");
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
const isAdmin = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session?.user?.role ?? "");
|
const isAdmin = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session?.user?.role ?? "");
|
||||||
|
|
||||||
|
// Searched on the server (the table is paged there), so typing is debounced
|
||||||
|
// rather than firing a request per keystroke.
|
||||||
|
useEffect(() => {
|
||||||
|
const next = searchInput.trim();
|
||||||
|
if (next === search) return;
|
||||||
|
const t = setTimeout(() => {
|
||||||
|
setSearch(next);
|
||||||
|
setPage(1);
|
||||||
|
}, 300);
|
||||||
|
return () => clearTimeout(t);
|
||||||
|
}, [searchInput, search]);
|
||||||
|
|
||||||
const { data, isLoading, refetch, isFetching } = useQuery({
|
const { data, isLoading, refetch, isFetching } = useQuery({
|
||||||
queryKey: ["pipeline-queue", projectId, statusFilter],
|
queryKey: ["pipeline-queue", projectId, statusFilter, search, page],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const params = new URLSearchParams({ limit: "200" });
|
const params = new URLSearchParams({ limit: String(PAGE_SIZE), page: String(page) });
|
||||||
if (projectId !== "all") params.set("projectId", projectId);
|
if (projectId !== "all") params.set("projectId", projectId);
|
||||||
if (statusFilter !== "all") params.set("status", statusFilter);
|
if (statusFilter !== "all") params.set("status", statusFilter);
|
||||||
|
if (search) params.set("q", search);
|
||||||
const res = await fetch(`/api/render/queue?${params}`);
|
const res = await fetch(`/api/render/queue?${params}`);
|
||||||
if (!res.ok) throw new Error("Failed to load queue");
|
if (!res.ok) throw new Error("Failed to load queue");
|
||||||
return res.json() as Promise<{ exports: QueueExport[]; pagination: { total: number } }>;
|
return res.json() as Promise<{
|
||||||
|
exports: QueueExport[];
|
||||||
|
pagination: { page: number; total: number; pages: number };
|
||||||
|
statusCounts: Record<string, number>;
|
||||||
|
}>;
|
||||||
|
},
|
||||||
|
refetchInterval: 5000,
|
||||||
|
// Keep the current page on screen while the next one loads, instead of
|
||||||
|
// flashing "Loading…" on every page turn.
|
||||||
|
placeholderData: (previous) => previous,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetched here rather than in the tab so the tab label can say how many are
|
||||||
|
// running: a Blender render must not become invisible by sitting in a tab.
|
||||||
|
const { data: blenderData } = useQuery({
|
||||||
|
queryKey: ["blender-jobs", projectId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const qs = projectId !== "all" ? `?projectId=${encodeURIComponent(projectId)}` : "";
|
||||||
|
const res = await fetch(`/api/render/blender${qs}`);
|
||||||
|
if (!res.ok) throw new Error("Failed to load Blender jobs");
|
||||||
|
return res.json() as Promise<{ jobs: BlenderJobRow[] }>;
|
||||||
},
|
},
|
||||||
refetchInterval: 5000,
|
refetchInterval: 5000,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exports = data?.exports ?? [];
|
const exports = data?.exports ?? [];
|
||||||
const counts = {
|
const pagination = data?.pagination;
|
||||||
queued: exports.filter((e) => e.status === "QUEUED").length,
|
const statusCounts = data?.statusCounts ?? {};
|
||||||
rendering: exports.filter((e) => e.status === "RENDERING").length,
|
const countOf = (statuses: string[]) => statuses.reduce((n, s) => n + (statusCounts[s] ?? 0), 0);
|
||||||
failed: exports.filter((e) => FAILED_STATUSES.includes(e.status)).length,
|
const totalExports = Object.values(statusCounts).reduce((n, c) => n + c, 0);
|
||||||
readyForQc: exports.filter((e) => e.status === "READY_FOR_QC").length,
|
const blenderJobs = blenderData?.jobs ?? [];
|
||||||
readyForDelivery: exports.filter((e) => e.status === "READY_FOR_DELIVERY").length,
|
const blenderActive = blenderJobs.filter((j) => BLENDER_ACTIVE.includes(j.status)).length;
|
||||||
};
|
const blenderFailed = blenderJobs.filter((j) => ["FAILED", "EXPIRED"].includes(j.status)).length;
|
||||||
|
|
||||||
async function action(exportId: string, verb: "retry" | "cancel" | "mark-done") {
|
async function action(exportId: string, verb: "retry" | "cancel" | "mark-done") {
|
||||||
const res = await fetch(`/api/render/exports/${exportId}/${verb}`, { method: "POST" });
|
const res = await fetch(`/api/render/exports/${exportId}/${verb}`, { method: "POST" });
|
||||||
@@ -94,30 +138,56 @@ export function PipelineQueueClient({ projects }: Props) {
|
|||||||
queryClient.invalidateQueries({ queryKey: ["pipeline-queue"] });
|
queryClient.invalidateQueries({ queryKey: ["pipeline-queue"] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const cards: { label: string; value: number; className?: string }[] = [
|
const cards: { label: string; value: number; status?: string; className?: string }[] = [
|
||||||
{ label: "Queued", value: counts.queued },
|
{ label: "Queued", value: countOf(["QUEUED"]), status: "QUEUED" },
|
||||||
{ label: "Rendering", value: counts.rendering, className: "text-blue-400" },
|
{ label: "Rendering", value: countOf(["RENDERING"]), status: "RENDERING", className: "text-blue-400" },
|
||||||
{ label: "Failed", value: counts.failed, className: "text-red-400" },
|
// Several statuses count as failed and the filter takes one, so this card
|
||||||
{ label: "Ready for QC", value: counts.readyForQc, className: "text-amber-400" },
|
// is a figure only.
|
||||||
{ label: "Ready for Delivery", value: counts.readyForDelivery, className: "text-green-400" },
|
{ label: "Failed", value: countOf(FAILED_STATUSES), className: "text-red-400" },
|
||||||
|
{ label: "Ready for QC", value: countOf(["READY_FOR_QC"]), status: "READY_FOR_QC", className: "text-amber-400" },
|
||||||
|
{
|
||||||
|
label: "Ready for Delivery",
|
||||||
|
value: countOf(["READY_FOR_DELIVERY"]),
|
||||||
|
status: "READY_FOR_DELIVERY",
|
||||||
|
className: "text-green-400",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const changeProject = (id: string) => {
|
||||||
|
setProjectId(id);
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
const changeStatus = (status: string) => {
|
||||||
|
setStatusFilter(status);
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const firstRow = pagination && pagination.total > 0 ? (pagination.page - 1) * PAGE_SIZE + 1 : 0;
|
||||||
|
const lastRow = pagination ? Math.min(pagination.page * PAGE_SIZE, pagination.total) : 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-4 md:p-6 space-y-6">
|
||||||
<div className="flex items-center justify-between gap-4 flex-wrap">
|
<div className="flex items-center justify-between gap-4 flex-wrap">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-semibold text-white">Render Queue</h1>
|
<h1 className="text-2xl font-semibold text-white">Render Queue</h1>
|
||||||
<p className="text-sm text-zinc-400 mt-1">
|
<p className="text-sm text-zinc-400 mt-1">
|
||||||
Exports queued from the AE panel — live status, retries and history
|
After Effects exports and Blender renders — live status, retries and history
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<Link href="/pipeline/deliveries">
|
<Select value={projectId} onValueChange={changeProject}>
|
||||||
<Button variant="outline" size="sm">
|
<SelectTrigger className="w-56">
|
||||||
<Package className="h-4 w-4 mr-2" />
|
<SelectValue placeholder="All projects" />
|
||||||
Deliveries
|
</SelectTrigger>
|
||||||
</Button>
|
<SelectContent>
|
||||||
</Link>
|
<SelectItem value="all">All projects</SelectItem>
|
||||||
|
{projects.map((p) => (
|
||||||
|
<SelectItem key={p.id} value={p.id}>
|
||||||
|
{p.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<Link href="/pipeline/deliveries">
|
<Link href="/pipeline/deliveries">
|
||||||
<Button variant="outline" size="sm">
|
<Button variant="outline" size="sm">
|
||||||
<Package className="h-4 w-4 mr-2" />
|
<Package className="h-4 w-4 mr-2" />
|
||||||
@@ -136,32 +206,82 @@ export function PipelineQueueClient({ projects }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Summary cards */}
|
<Tabs defaultValue="exports" className="space-y-4">
|
||||||
|
<TabsList className="bg-zinc-900 border border-zinc-800">
|
||||||
|
<TabsTrigger value="exports">
|
||||||
|
After Effects exports
|
||||||
|
<span className="ml-2 text-xs text-zinc-500">{totalExports}</span>
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="blender">
|
||||||
|
Blender renders
|
||||||
|
{blenderActive > 0 ? (
|
||||||
|
<span className="ml-2 rounded-full bg-blue-500/20 px-1.5 text-xs text-blue-400">
|
||||||
|
{blenderActive} active
|
||||||
|
</span>
|
||||||
|
) : blenderFailed > 0 ? (
|
||||||
|
<span className="ml-2 rounded-full bg-red-500/20 px-1.5 text-xs text-red-400">
|
||||||
|
{blenderFailed} failed
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="ml-2 text-xs text-zinc-500">{blenderJobs.length}</span>
|
||||||
|
)}
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent value="exports" className="space-y-4 mt-0">
|
||||||
|
{/* Summary cards — each one with a status filters the table to what it counts */}
|
||||||
<div className="grid grid-cols-2 sm:grid-cols-5 gap-3">
|
<div className="grid grid-cols-2 sm:grid-cols-5 gap-3">
|
||||||
{cards.map((c) => (
|
{cards.map((c) => {
|
||||||
<div key={c.label} className="rounded-lg border border-zinc-800 bg-zinc-900 px-4 py-3">
|
const selected = c.status !== undefined && statusFilter === c.status;
|
||||||
|
const body = (
|
||||||
|
<>
|
||||||
<div className={cn("text-2xl font-semibold text-white", c.className)}>{c.value}</div>
|
<div className={cn("text-2xl font-semibold text-white", c.className)}>{c.value}</div>
|
||||||
<div className="text-xs text-zinc-400 mt-0.5">{c.label}</div>
|
<div className="text-xs text-zinc-400 mt-0.5">{c.label}</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
return c.status ? (
|
||||||
|
<button
|
||||||
|
key={c.label}
|
||||||
|
type="button"
|
||||||
|
onClick={() => changeStatus(selected ? "all" : c.status!)}
|
||||||
|
className={cn(
|
||||||
|
"rounded-lg border bg-zinc-900 px-4 py-3 text-left transition-colors hover:border-zinc-600",
|
||||||
|
selected ? "border-zinc-500" : "border-zinc-800"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div key={c.label} className="rounded-lg border border-zinc-800 bg-zinc-900 px-4 py-3">
|
||||||
|
{body}
|
||||||
</div>
|
</div>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Filters */}
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<div className="flex items-center gap-3 flex-wrap">
|
<div className="relative w-full sm:w-72">
|
||||||
<Select value={projectId} onValueChange={setProjectId}>
|
<Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-zinc-500" />
|
||||||
<SelectTrigger className="w-56">
|
<Input
|
||||||
<SelectValue placeholder="All projects" />
|
value={searchInput}
|
||||||
</SelectTrigger>
|
onChange={(e) => setSearchInput(e.target.value)}
|
||||||
<SelectContent>
|
onKeyDown={(e) => e.key === "Escape" && setSearchInput("")}
|
||||||
<SelectItem value="all">All projects</SelectItem>
|
placeholder="Search shots, e.g. UNG_114"
|
||||||
{projects.map((p) => (
|
aria-label="Search exports by shot code"
|
||||||
<SelectItem key={p.id} value={p.id}>
|
className="pl-8 pr-8"
|
||||||
{p.name}
|
/>
|
||||||
</SelectItem>
|
{searchInput && (
|
||||||
))}
|
<button
|
||||||
</SelectContent>
|
type="button"
|
||||||
</Select>
|
onClick={() => setSearchInput("")}
|
||||||
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
className="absolute right-2 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-300"
|
||||||
|
aria-label="Clear search"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Select value={statusFilter} onValueChange={changeStatus}>
|
||||||
<SelectTrigger className="w-56">
|
<SelectTrigger className="w-56">
|
||||||
<SelectValue placeholder="All statuses" />
|
<SelectValue placeholder="All statuses" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@@ -176,7 +296,6 @@ export function PipelineQueueClient({ projects }: Props) {
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Table */}
|
|
||||||
<div className="rounded-lg border border-zinc-800 overflow-x-auto">
|
<div className="rounded-lg border border-zinc-800 overflow-x-auto">
|
||||||
<table className="w-full text-sm">
|
<table className="w-full text-sm">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -201,7 +320,11 @@ export function PipelineQueueClient({ projects }: Props) {
|
|||||||
) : exports.length === 0 ? (
|
) : exports.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={8} className="px-4 py-10 text-center text-zinc-500">
|
<td colSpan={8} className="px-4 py-10 text-center text-zinc-500">
|
||||||
No exports yet — queue one from the After Effects panel
|
{search
|
||||||
|
? `No exports match “${search}”`
|
||||||
|
: statusFilter === "all"
|
||||||
|
? "No exports yet — queue one from the After Effects panel"
|
||||||
|
: `No exports are ${statusLabel(statusFilter).toLowerCase()}`}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : (
|
) : (
|
||||||
@@ -244,9 +367,7 @@ export function PipelineQueueClient({ projects }: Props) {
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-4 py-2.5 text-zinc-400">{e.job?.machineName ?? "—"}</td>
|
<td className="px-4 py-2.5 text-zinc-400">{e.job?.machineName ?? "—"}</td>
|
||||||
<td className="px-4 py-2.5 text-zinc-400">
|
<td className="px-4 py-2.5 text-zinc-400">{e.job ? `${e.job.attempt}` : "—"}</td>
|
||||||
{e.job ? `${e.job.attempt}` : "—"}
|
|
||||||
</td>
|
|
||||||
<td className="px-4 py-2.5 text-zinc-500 text-xs whitespace-nowrap">
|
<td className="px-4 py-2.5 text-zinc-500 text-xs whitespace-nowrap">
|
||||||
{new Date(e.createdAt).toLocaleString()}
|
{new Date(e.createdAt).toLocaleString()}
|
||||||
</td>
|
</td>
|
||||||
@@ -281,7 +402,35 @@ export function PipelineQueueClient({ projects }: Props) {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<BlenderQueue projectId={projectId} />
|
{pagination && pagination.pages > 1 && (
|
||||||
|
<div className="flex items-center justify-between text-sm text-zinc-400">
|
||||||
|
<span>
|
||||||
|
{firstRow}–{lastRow} of {pagination.total}
|
||||||
|
</span>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button variant="outline" size="sm" disabled={page <= 1} onClick={() => setPage((p) => p - 1)}>
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<span className="text-xs">
|
||||||
|
Page {pagination.page} of {pagination.pages}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
disabled={page >= pagination.pages}
|
||||||
|
onClick={() => setPage((p) => p + 1)}
|
||||||
|
>
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="blender" className="mt-0">
|
||||||
|
<BlenderQueue jobs={blenderJobs} loaded={blenderData !== undefined} />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -318,24 +467,13 @@ const BLENDER_STATUS_STYLES: Record<string, string> = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Standalone Blender renders. They have no Export behind them, so they cannot
|
* Standalone Blender renders. They have no Export behind them, so they cannot
|
||||||
* appear in the table above — but they share the queue, and a render nobody can
|
* appear in the exports table — but they share the queue, and a render nobody
|
||||||
* see is a render nobody can retry.
|
* can see is a render nobody can retry.
|
||||||
*/
|
*/
|
||||||
function BlenderQueue({ projectId }: { projectId: string }) {
|
function BlenderQueue({ jobs, loaded }: { jobs: BlenderJobRow[]; loaded: boolean }) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const { data } = useQuery({
|
|
||||||
queryKey: ["blender-jobs", projectId],
|
|
||||||
queryFn: async () => {
|
|
||||||
const qs = projectId && projectId !== "all" ? `?projectId=${encodeURIComponent(projectId)}` : "";
|
|
||||||
const res = await fetch(`/api/render/blender${qs}`);
|
|
||||||
if (!res.ok) throw new Error("Failed to load Blender jobs");
|
|
||||||
return res.json() as Promise<{ jobs: BlenderJobRow[] }>;
|
|
||||||
},
|
|
||||||
refetchInterval: 5000,
|
|
||||||
});
|
|
||||||
|
|
||||||
async function jobAction(id: string, verb: "cancel" | "retry") {
|
async function jobAction(id: string, verb: "cancel" | "retry") {
|
||||||
const res = await fetch(`/api/render/blender/${id}?action=${verb}`, { method: "POST" });
|
const res = await fetch(`/api/render/blender/${id}?action=${verb}`, { method: "POST" });
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
@@ -345,14 +483,16 @@ function BlenderQueue({ projectId }: { projectId: string }) {
|
|||||||
queryClient.invalidateQueries({ queryKey: ["blender-jobs"] });
|
queryClient.invalidateQueries({ queryKey: ["blender-jobs"] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobs = data?.jobs ?? [];
|
if (jobs.length === 0) {
|
||||||
if (jobs.length === 0) return null;
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 px-4 py-10 text-center text-sm text-zinc-500">
|
||||||
|
{loaded ? "No Blender renders yet — submit one from the Blender panel" : "Loading…"}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
||||||
<div className="px-4 py-2.5 border-b border-zinc-800 text-sm font-medium text-white">
|
|
||||||
Blender renders
|
|
||||||
</div>
|
|
||||||
<div className="divide-y divide-zinc-800/60">
|
<div className="divide-y divide-zinc-800/60">
|
||||||
{jobs.map((j) => (
|
{jobs.map((j) => (
|
||||||
<div key={j.id} className="px-4 py-3 text-sm">
|
<div key={j.id} className="px-4 py-3 text-sm">
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { ArrowLeft, Package, CheckCircle2, XCircle, RefreshCw } from "lucide-react";
|
import { ArrowLeft, Package, CheckCircle2, XCircle, RefreshCw, Upload } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { handoffStage } from "@/lib/render-pipeline/delivery-handoff";
|
||||||
import { DELIVERY_STATUS_STYLES, statusLabel } from "../status-colors";
|
import { DELIVERY_STATUS_STYLES, statusLabel } from "../status-colors";
|
||||||
|
import { RecordShareDialog, RecordUploadDialog } from "./HandoffDialogs";
|
||||||
|
import { RequestsPanel } from "./RequestsPanel";
|
||||||
|
|
||||||
interface ReadyExport {
|
interface ReadyExport {
|
||||||
exportId: string;
|
exportId: string;
|
||||||
@@ -35,14 +38,25 @@ interface PackageRow {
|
|||||||
rootPath: string | null;
|
rootPath: string | null;
|
||||||
errorMessage: string | null;
|
errorMessage: string | null;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
|
projectCode: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
builtAt: string | null;
|
builtAt: string | null;
|
||||||
|
uploadUrl: string | null;
|
||||||
|
uploadedAt: string | null;
|
||||||
|
uploadedByName: string | null;
|
||||||
|
sharedWith: string | null;
|
||||||
|
sharedNote: string | null;
|
||||||
deliveredAt: string | null;
|
deliveredAt: string | null;
|
||||||
|
deliveredByName: string | null;
|
||||||
itemCount: number;
|
itemCount: number;
|
||||||
verifiedCount: number;
|
verifiedCount: number;
|
||||||
|
exrFileCount: number;
|
||||||
|
movCount: number;
|
||||||
|
totalBytes: number;
|
||||||
items: {
|
items: {
|
||||||
id: string;
|
id: string;
|
||||||
shotCode: string;
|
shotCode: string;
|
||||||
|
clientCode: string | null;
|
||||||
versionString: string;
|
versionString: string;
|
||||||
status: string;
|
status: string;
|
||||||
fileCount: number | null;
|
fileCount: number | null;
|
||||||
@@ -69,6 +83,7 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
const [projectId, setProjectId] = useState<string>("");
|
const [projectId, setProjectId] = useState<string>("");
|
||||||
const [episode, setEpisode] = useState<string>("");
|
const [episode, setEpisode] = useState<string>("");
|
||||||
const [building, setBuilding] = useState(false);
|
const [building, setBuilding] = useState(false);
|
||||||
|
const [handoff, setHandoff] = useState<{ step: "upload" | "share"; packageId: string } | null>(null);
|
||||||
|
|
||||||
const { data: projects } = useQuery({
|
const { data: projects } = useQuery({
|
||||||
queryKey: ["pipeline-projects"],
|
queryKey: ["pipeline-projects"],
|
||||||
@@ -126,21 +141,28 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function packageAction(id: string, verb: "delivered" | "cancel") {
|
function refreshPackages() {
|
||||||
const res = await fetch(`/api/deliveries/${id}/${verb}`, { method: "POST" });
|
|
||||||
const body = await res.json().catch(() => ({}));
|
|
||||||
if (!res.ok) {
|
|
||||||
toast({ title: `${verb} failed`, description: body.error ?? res.statusText, variant: "destructive" });
|
|
||||||
}
|
|
||||||
queryClient.invalidateQueries({ queryKey: ["delivery-packages"] });
|
queryClient.invalidateQueries({ queryKey: ["delivery-packages"] });
|
||||||
queryClient.invalidateQueries({ queryKey: ["delivery-ready"] });
|
queryClient.invalidateQueries({ queryKey: ["delivery-ready"] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cancelPackage(id: string) {
|
||||||
|
const res = await fetch(`/api/deliveries/${id}/cancel`, { method: "POST" });
|
||||||
|
const body = await res.json().catch(() => ({}));
|
||||||
|
if (!res.ok) {
|
||||||
|
toast({ title: "Cancel failed", description: body.error ?? res.statusText, variant: "destructive" });
|
||||||
|
}
|
||||||
|
refreshPackages();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Looked up from the live list so the dialog never acts on a stale row.
|
||||||
|
const handoffPackage = handoff ? packages?.packages.find((p) => p.id === handoff.packageId) : undefined;
|
||||||
|
|
||||||
const episodes = ready?.episodes ?? [];
|
const episodes = ready?.episodes ?? [];
|
||||||
const shown = episode ? episodes.filter((e) => e.episode === episode) : episodes;
|
const shown = episode ? episodes.filter((e) => e.episode === episode) : episodes;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6 max-w-6xl">
|
<div className="p-4 md:p-6 space-y-6 max-w-6xl">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<Link href="/pipeline">
|
<Link href="/pipeline">
|
||||||
<Button variant="ghost" size="icon-sm">
|
<Button variant="ghost" size="icon-sm">
|
||||||
@@ -183,6 +205,8 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<RequestsPanel projectId={projectId} canBuild={canBuild} />
|
||||||
|
|
||||||
{/* Ready to build */}
|
{/* Ready to build */}
|
||||||
{projectId && (
|
{projectId && (
|
||||||
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
||||||
@@ -238,7 +262,9 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
||||||
<div className="px-4 py-2.5 border-b border-zinc-800 text-sm font-medium text-white">Packages</div>
|
<div className="px-4 py-2.5 border-b border-zinc-800 text-sm font-medium text-white">Packages</div>
|
||||||
<div className="divide-y divide-zinc-800/60">
|
<div className="divide-y divide-zinc-800/60">
|
||||||
{(packages?.packages ?? []).map((p) => (
|
{(packages?.packages ?? []).map((p) => {
|
||||||
|
const stage = handoffStage(p);
|
||||||
|
return (
|
||||||
<details key={p.id} className="group">
|
<details key={p.id} className="group">
|
||||||
<summary className="flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-zinc-900/60 flex-wrap">
|
<summary className="flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-zinc-900/60 flex-wrap">
|
||||||
<span className="text-sm text-white font-medium">#{p.packageNumber}</span>
|
<span className="text-sm text-white font-medium">#{p.packageNumber}</span>
|
||||||
@@ -251,10 +277,16 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"rounded-full border px-2 py-0.5 text-xs",
|
"rounded-full border px-2 py-0.5 text-xs",
|
||||||
DELIVERY_STATUS_STYLES[p.status] ?? ""
|
// Built is not delivered: a package still owed to the
|
||||||
|
// client must not read as a green "READY".
|
||||||
|
stage ? "bg-amber-500/15 text-amber-400 border-amber-500/30" : (DELIVERY_STATUS_STYLES[p.status] ?? "")
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{statusLabel(p.status)}
|
{stage === "AWAITING_UPLOAD"
|
||||||
|
? "BUILT — NOT UPLOADED"
|
||||||
|
: stage === "AWAITING_SHARE"
|
||||||
|
? "UPLOADED — LINK NOT SHARED"
|
||||||
|
: statusLabel(p.status)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-zinc-500">
|
<span className="text-xs text-zinc-500">
|
||||||
{p.episode ? `episode ${p.episode} · ` : ""}
|
{p.episode ? `episode ${p.episode} · ` : ""}
|
||||||
@@ -263,17 +295,30 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
<span className="text-xs text-zinc-600">{new Date(p.createdAt).toLocaleDateString()}</span>
|
<span className="text-xs text-zinc-600">{new Date(p.createdAt).toLocaleDateString()}</span>
|
||||||
{p.status === "BUILDING" && <RefreshCw className="h-3.5 w-3.5 text-blue-400 animate-spin" />}
|
{p.status === "BUILDING" && <RefreshCw className="h-3.5 w-3.5 text-blue-400 animate-spin" />}
|
||||||
<span className="ml-auto flex items-center gap-2">
|
<span className="ml-auto flex items-center gap-2">
|
||||||
{canBuild && p.status === "READY" && p.kind === "EXR_DELIVERY" && (
|
{canBuild && stage === "AWAITING_UPLOAD" && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
packageAction(p.id, "delivered");
|
setHandoff({ step: "upload", packageId: p.id });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Upload className="h-4 w-4 mr-2 text-amber-400" />
|
||||||
|
Record upload
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{canBuild && stage === "AWAITING_SHARE" && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setHandoff({ step: "share", packageId: p.id });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CheckCircle2 className="h-4 w-4 mr-2 text-emerald-400" />
|
<CheckCircle2 className="h-4 w-4 mr-2 text-emerald-400" />
|
||||||
Mark delivered
|
Share link
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{canBuild && ["QUEUED", "FAILED", "DRAFT"].includes(p.status) && (
|
{canBuild && ["QUEUED", "FAILED", "DRAFT"].includes(p.status) && (
|
||||||
@@ -282,7 +327,7 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
packageAction(p.id, "cancel");
|
cancelPackage(p.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<XCircle className="h-4 w-4 mr-2 text-red-400" />
|
<XCircle className="h-4 w-4 mr-2 text-red-400" />
|
||||||
@@ -294,9 +339,31 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
<div className="px-4 pb-4 space-y-2">
|
<div className="px-4 pb-4 space-y-2">
|
||||||
{p.rootPath && <div className="text-xs text-zinc-500 break-all">{p.rootPath}</div>}
|
{p.rootPath && <div className="text-xs text-zinc-500 break-all">{p.rootPath}</div>}
|
||||||
{p.errorMessage && <div className="text-xs text-red-400">{p.errorMessage}</div>}
|
{p.errorMessage && <div className="text-xs text-red-400">{p.errorMessage}</div>}
|
||||||
|
{p.uploadedAt && p.uploadUrl && (
|
||||||
|
<div className="text-xs text-zinc-400 break-all">
|
||||||
|
Uploaded {new Date(p.uploadedAt).toLocaleString()}
|
||||||
|
{p.uploadedByName ? ` by ${p.uploadedByName}` : ""} —{" "}
|
||||||
|
<a href={p.uploadUrl} target="_blank" rel="noreferrer" className="text-sky-400 hover:underline">
|
||||||
|
{p.uploadUrl}
|
||||||
|
</a>
|
||||||
|
{canBuild && stage === "AWAITING_SHARE" && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ml-2 text-zinc-500 hover:text-white underline"
|
||||||
|
onClick={() => setHandoff({ step: "upload", packageId: p.id })}
|
||||||
|
>
|
||||||
|
change
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{p.deliveredAt && (
|
{p.deliveredAt && (
|
||||||
<div className="text-xs text-emerald-400">
|
<div className="text-xs text-emerald-400">
|
||||||
Delivered {new Date(p.deliveredAt).toLocaleString()}
|
{p.sharedWith
|
||||||
|
? `Link shared with ${p.sharedWith} ${new Date(p.deliveredAt).toLocaleString()}`
|
||||||
|
: `Delivered ${new Date(p.deliveredAt).toLocaleString()} — before uploads and shares were recorded`}
|
||||||
|
{p.deliveredByName ? ` by ${p.deliveredByName}` : ""}
|
||||||
|
{p.sharedNote ? ` — ${p.sharedNote}` : ""}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-x-6 gap-y-1">
|
<div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-x-6 gap-y-1">
|
||||||
@@ -325,12 +392,24 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
{(packages?.packages ?? []).length === 0 && (
|
{(packages?.packages ?? []).length === 0 && (
|
||||||
<div className="p-4 text-sm text-zinc-500">No packages built yet</div>
|
<div className="p-4 text-sm text-zinc-500">No packages built yet</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{handoff?.step === "upload" && handoffPackage && (
|
||||||
|
<RecordUploadDialog pkg={handoffPackage} onClose={() => setHandoff(null)} onSaved={refreshPackages} />
|
||||||
|
)}
|
||||||
|
{handoff?.step === "share" && handoffPackage?.uploadUrl && (
|
||||||
|
<RecordShareDialog
|
||||||
|
pkg={{ ...handoffPackage, uploadUrl: handoffPackage.uploadUrl }}
|
||||||
|
onClose={() => setHandoff(null)}
|
||||||
|
onSaved={refreshPackages}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Copy } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { buildShareMessage } from "@/lib/render-pipeline/delivery-handoff";
|
||||||
|
|
||||||
|
export interface HandoffPackage {
|
||||||
|
id: string;
|
||||||
|
packageNumber: number;
|
||||||
|
name: string;
|
||||||
|
projectCode: string;
|
||||||
|
episode: string;
|
||||||
|
rootPath: string | null;
|
||||||
|
uploadUrl: string | null;
|
||||||
|
itemCount: number;
|
||||||
|
exrFileCount: number;
|
||||||
|
movCount: number;
|
||||||
|
totalBytes: number;
|
||||||
|
items: { shotCode: string; clientCode: string | null; versionString: string }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSize(bytes: number): string {
|
||||||
|
if (!bytes) return "size unknown";
|
||||||
|
const gb = bytes / 1_073_741_824;
|
||||||
|
return gb >= 1 ? `${gb.toFixed(1)} GB` : `${(bytes / 1_048_576).toFixed(0)} MB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function post(path: string, body: unknown): Promise<string | null> {
|
||||||
|
const res = await fetch(path, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
if (res.ok) return null;
|
||||||
|
const data = await res.json().catch(() => ({}));
|
||||||
|
return data.error ?? res.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Step one: where the folder now lives on the client's side. */
|
||||||
|
export function RecordUploadDialog({
|
||||||
|
pkg,
|
||||||
|
onClose,
|
||||||
|
onSaved,
|
||||||
|
}: {
|
||||||
|
pkg: HandoffPackage;
|
||||||
|
onClose: () => void;
|
||||||
|
onSaved: () => void;
|
||||||
|
}) {
|
||||||
|
const { toast } = useToast();
|
||||||
|
const [uploadUrl, setUploadUrl] = useState(pkg.uploadUrl ?? "");
|
||||||
|
const [confirmed, setConfirmed] = useState(false);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
setSaving(true);
|
||||||
|
const error = await post(`/api/deliveries/${pkg.id}/uploaded`, { uploadUrl, contentsConfirmed: confirmed });
|
||||||
|
setSaving(false);
|
||||||
|
if (error) {
|
||||||
|
toast({ title: "Upload not recorded", description: error, variant: "destructive" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSaved();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open onOpenChange={(open) => !open && onClose()}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>
|
||||||
|
Record upload — #{pkg.packageNumber} {pkg.name}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Paste the link to the folder on the client's portal. The package stays on the dashboard as
|
||||||
|
awaiting delivery until the link has also been shared.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="rounded-md border border-zinc-800 bg-zinc-900/60 p-3 text-xs text-zinc-400 space-y-1">
|
||||||
|
<div className="text-zinc-200">
|
||||||
|
The upload should contain {pkg.itemCount} shot{pkg.itemCount === 1 ? "" : "s"} · {pkg.exrFileCount} EXR
|
||||||
|
frames · {pkg.movCount} MOV{pkg.movCount === 1 ? "" : "s"} · {formatSize(pkg.totalBytes)}
|
||||||
|
</div>
|
||||||
|
{pkg.rootPath && <div className="break-all">Source: {pkg.rootPath}</div>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="upload-url">Upload link</Label>
|
||||||
|
<Input
|
||||||
|
id="upload-url"
|
||||||
|
type="url"
|
||||||
|
placeholder="https://…"
|
||||||
|
value={uploadUrl}
|
||||||
|
onChange={(e) => setUploadUrl(e.target.value)}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label className="flex items-start gap-2 text-sm text-zinc-300">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="mt-1"
|
||||||
|
checked={confirmed}
|
||||||
|
onChange={(e) => setConfirmed(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span>I opened this link and the upload has finished and matches the counts above.</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={save} disabled={saving || !uploadUrl.trim() || !confirmed}>
|
||||||
|
Record upload
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Step two: the link went to a person. This is what makes it delivered. */
|
||||||
|
export function RecordShareDialog({
|
||||||
|
pkg,
|
||||||
|
onClose,
|
||||||
|
onSaved,
|
||||||
|
}: {
|
||||||
|
pkg: HandoffPackage & { uploadUrl: string };
|
||||||
|
onClose: () => void;
|
||||||
|
onSaved: () => void;
|
||||||
|
}) {
|
||||||
|
const { toast } = useToast();
|
||||||
|
const [sharedWith, setSharedWith] = useState("");
|
||||||
|
const [note, setNote] = useState("");
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const message = buildShareMessage(pkg);
|
||||||
|
|
||||||
|
async function copy() {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(message);
|
||||||
|
toast({ title: "Message copied" });
|
||||||
|
} catch {
|
||||||
|
toast({ title: "Could not copy", description: "Select the text and copy it by hand.", variant: "destructive" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
setSaving(true);
|
||||||
|
const error = await post(`/api/deliveries/${pkg.id}/delivered`, { sharedWith, note: note || null });
|
||||||
|
setSaving(false);
|
||||||
|
if (error) {
|
||||||
|
toast({ title: "Not marked delivered", description: error, variant: "destructive" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSaved();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open onOpenChange={(open) => !open && onClose()}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>
|
||||||
|
Share link — #{pkg.packageNumber} {pkg.name}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Send this message to the client, then record who it went to. That marks the package delivered.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label htmlFor="share-message">Message</Label>
|
||||||
|
<Button size="sm" variant="outline" onClick={copy}>
|
||||||
|
<Copy className="h-3.5 w-3.5 mr-2" />
|
||||||
|
Copy message
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Textarea id="share-message" readOnly value={message} rows={8} className="font-mono text-xs" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="shared-with">Sent to</Label>
|
||||||
|
<Input
|
||||||
|
id="shared-with"
|
||||||
|
placeholder="Name, and where — e.g. Sam, production WhatsApp group"
|
||||||
|
value={sharedWith}
|
||||||
|
onChange={(e) => setSharedWith(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="share-note">Note (optional)</Label>
|
||||||
|
<Input id="share-note" value={note} onChange={(e) => setNote(e.target.value)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={save} disabled={saving || !sharedWith.trim()}>
|
||||||
|
Link sent — mark delivered
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Package, Plus, XCircle } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { LogRequestDialog } from "@/components/delivery/LogRequestDialog";
|
||||||
|
import {
|
||||||
|
DELIVERABLE_LABEL,
|
||||||
|
LINE_STAGE_LABEL,
|
||||||
|
type Deliverable,
|
||||||
|
type RequestLineStage,
|
||||||
|
} from "@/lib/render-pipeline/delivery-request-state";
|
||||||
|
|
||||||
|
interface RequestRow {
|
||||||
|
id: string;
|
||||||
|
requestNumber: number;
|
||||||
|
projectId: string;
|
||||||
|
projectCode: string;
|
||||||
|
episode: string;
|
||||||
|
deliverable: string;
|
||||||
|
requestedBy: string;
|
||||||
|
note: string | null;
|
||||||
|
dueDate: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
cancelReason: string | null;
|
||||||
|
state: "OPEN" | "CLOSED" | "CANCELLED";
|
||||||
|
lineCount: number;
|
||||||
|
deliveredCount: number;
|
||||||
|
severity: "normal" | "warning" | "critical";
|
||||||
|
lines: {
|
||||||
|
id: string;
|
||||||
|
shotCode: string;
|
||||||
|
clientCode: string | null;
|
||||||
|
stage: RequestLineStage;
|
||||||
|
readyExportId: string | null;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const SEVERITY_STYLES: Record<RequestRow["severity"], string> = {
|
||||||
|
normal: "bg-zinc-500/15 text-zinc-300 border-zinc-500/30",
|
||||||
|
warning: "bg-amber-500/15 text-amber-400 border-amber-500/30",
|
||||||
|
critical: "bg-red-500/15 text-red-400 border-red-500/30",
|
||||||
|
};
|
||||||
|
|
||||||
|
const STAGE_STYLES: Record<RequestLineStage, string> = {
|
||||||
|
DELIVERED: "text-emerald-400",
|
||||||
|
UPLOADED: "text-amber-400",
|
||||||
|
BUILT: "text-amber-400",
|
||||||
|
BUILDING: "text-blue-400",
|
||||||
|
READY: "text-green-400",
|
||||||
|
IN_QC: "text-zinc-400",
|
||||||
|
NOT_READY: "text-zinc-500",
|
||||||
|
};
|
||||||
|
|
||||||
|
function requestTitle(r: RequestRow): string {
|
||||||
|
const what = DELIVERABLE_LABEL[r.deliverable as Deliverable] ?? r.deliverable;
|
||||||
|
return r.episode ? `${what} for ${r.episode}` : `${what} · ${r.lineCount} shot${r.lineCount === 1 ? "" : "s"}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What clients have asked for. An open request lists every shot with where it
|
||||||
|
* stands, so "did 116 go out?" is answered by the page rather than by memory.
|
||||||
|
*/
|
||||||
|
export function RequestsPanel({ projectId, canBuild }: { projectId: string; canBuild: boolean }) {
|
||||||
|
const { toast } = useToast();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const [logging, setLogging] = useState(false);
|
||||||
|
const [cancelling, setCancelling] = useState<RequestRow | null>(null);
|
||||||
|
const [reason, setReason] = useState("");
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
const { data } = useQuery({
|
||||||
|
queryKey: ["delivery-requests", projectId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await fetch(`/api/delivery-requests${projectId ? `?projectId=${encodeURIComponent(projectId)}` : ""}`);
|
||||||
|
if (!res.ok) throw new Error("Failed to load delivery requests");
|
||||||
|
return res.json() as Promise<{ requests: RequestRow[] }>;
|
||||||
|
},
|
||||||
|
// Lines move as packages build and get shared on this same page.
|
||||||
|
refetchInterval: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const refresh = () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["delivery-requests"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["delivery-packages"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["delivery-ready"] });
|
||||||
|
};
|
||||||
|
|
||||||
|
async function build(request: RequestRow) {
|
||||||
|
const exportIds = request.lines.flatMap((l) => (l.readyExportId ? [l.readyExportId] : []));
|
||||||
|
if (!exportIds.length) return;
|
||||||
|
setBusy(true);
|
||||||
|
const res = await fetch("/api/deliveries", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ projectId: request.projectId, episode: request.episode || null, exportIds }),
|
||||||
|
});
|
||||||
|
const body = await res.json().catch(() => ({}));
|
||||||
|
setBusy(false);
|
||||||
|
if (!res.ok) {
|
||||||
|
toast({ title: "Build failed", description: body.error ?? res.statusText, variant: "destructive" });
|
||||||
|
} else {
|
||||||
|
toast({
|
||||||
|
title: `Package #${body.package.packageNumber} queued`,
|
||||||
|
description: `${body.package.itemCount} shots for request #${request.requestNumber}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cancel() {
|
||||||
|
if (!cancelling) return;
|
||||||
|
setBusy(true);
|
||||||
|
const res = await fetch(`/api/delivery-requests/${cancelling.id}/cancel`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ reason }),
|
||||||
|
});
|
||||||
|
const body = await res.json().catch(() => ({}));
|
||||||
|
setBusy(false);
|
||||||
|
if (!res.ok) {
|
||||||
|
toast({ title: "Not cancelled", description: body.error ?? res.statusText, variant: "destructive" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCancelling(null);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
const requests = data?.requests ?? [];
|
||||||
|
const open = requests.filter((r) => r.state === "OPEN");
|
||||||
|
const past = requests.filter((r) => r.state !== "OPEN");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
||||||
|
<div className="flex items-center justify-between gap-3 px-4 py-2.5 border-b border-zinc-800">
|
||||||
|
<span className="text-sm font-medium text-white">Delivery requests</span>
|
||||||
|
{canBuild && (
|
||||||
|
<Button size="sm" variant="outline" onClick={() => setLogging(true)}>
|
||||||
|
<Plus className="h-3.5 w-3.5 mr-1.5" />
|
||||||
|
Log request
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{open.length === 0 && <div className="p-4 text-sm text-zinc-500">No open requests.</div>}
|
||||||
|
|
||||||
|
<div className="divide-y divide-zinc-800/60">
|
||||||
|
{open.map((r) => {
|
||||||
|
const readyCount = r.lines.filter((l) => l.readyExportId).length;
|
||||||
|
return (
|
||||||
|
<details key={r.id} open className="group">
|
||||||
|
<summary className="flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-zinc-900/60 flex-wrap">
|
||||||
|
<span className="text-sm text-white font-medium">Request #{r.requestNumber}</span>
|
||||||
|
<span className="text-sm text-zinc-300">{requestTitle(r)}</span>
|
||||||
|
<span className={cn("rounded-full border px-2 py-0.5 text-xs", SEVERITY_STYLES[r.severity])}>
|
||||||
|
{r.deliveredCount} of {r.lineCount} delivered
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-zinc-500">
|
||||||
|
{r.projectCode} · asked by {r.requestedBy} · {new Date(r.createdAt).toLocaleDateString()}
|
||||||
|
{r.dueDate ? ` · due ${new Date(r.dueDate).toLocaleDateString()}` : ""}
|
||||||
|
</span>
|
||||||
|
<span className="ml-auto flex items-center gap-2">
|
||||||
|
{canBuild && readyCount > 0 && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
disabled={busy}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
build(r);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Package className="h-4 w-4 mr-2" />
|
||||||
|
Build {readyCount} ready
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{canBuild && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setReason("");
|
||||||
|
setCancelling(r);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<XCircle className="h-4 w-4 mr-2 text-red-400" />
|
||||||
|
Cancel request
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</summary>
|
||||||
|
<div className="px-4 pb-4 space-y-2">
|
||||||
|
{r.note && <div className="text-xs text-zinc-400">{r.note}</div>}
|
||||||
|
<div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-x-6 gap-y-1">
|
||||||
|
{r.lines.map((line) => (
|
||||||
|
<div key={line.id} className="flex items-center gap-2 text-xs">
|
||||||
|
<span className="text-zinc-300">{line.shotCode}</span>
|
||||||
|
{line.clientCode && <span className="text-zinc-600">{line.clientCode}</span>}
|
||||||
|
<span className={STAGE_STYLES[line.stage]}>{LINE_STAGE_LABEL[line.stage]}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{past.length > 0 && (
|
||||||
|
<details className="border-t border-zinc-800">
|
||||||
|
<summary className="px-4 py-2.5 cursor-pointer text-xs text-zinc-500 hover:text-zinc-300">
|
||||||
|
Closed and cancelled ({past.length})
|
||||||
|
</summary>
|
||||||
|
<div className="px-4 pb-3 space-y-1">
|
||||||
|
{past.map((r) => (
|
||||||
|
<div key={r.id} className="text-xs text-zinc-500">
|
||||||
|
<span className="text-zinc-300">Request #{r.requestNumber}</span> {requestTitle(r)} · {r.projectCode} ·
|
||||||
|
asked by {r.requestedBy} ·{" "}
|
||||||
|
{r.state === "CANCELLED" ? (
|
||||||
|
<span className="text-zinc-400">cancelled — {r.cancelReason}</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-emerald-400">all {r.lineCount} delivered</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<LogRequestDialog
|
||||||
|
open={logging}
|
||||||
|
onClose={() => setLogging(false)}
|
||||||
|
onLogged={refresh}
|
||||||
|
defaultProjectId={projectId || undefined}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{cancelling && (
|
||||||
|
<Dialog open onOpenChange={(o) => !o && !busy && setCancelling(null)}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Cancel request #{cancelling.requestNumber}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
{cancelling.lineCount - cancelling.deliveredCount} of {cancelling.lineCount} shots have not been
|
||||||
|
delivered. Cancelling removes the request from Awaiting delivery; it stays in the history with the
|
||||||
|
reason.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<Input
|
||||||
|
aria-label="Reason"
|
||||||
|
placeholder="Why — e.g. client no longer needs 116"
|
||||||
|
value={reason}
|
||||||
|
onChange={(e) => setReason(e.target.value)}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={() => setCancelling(null)} disabled={busy}>
|
||||||
|
Keep request
|
||||||
|
</Button>
|
||||||
|
<Button variant="destructive" onClick={cancel} disabled={busy || !reason.trim()}>
|
||||||
|
Cancel request
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -155,10 +155,10 @@ export function ExportDetailClient({ exportId }: { exportId: string }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoading) return <div className="p-6 text-zinc-500">Loading…</div>;
|
if (isLoading) return <div className="p-4 md:p-6 text-zinc-500">Loading…</div>;
|
||||||
if (error || !data) {
|
if (error || !data) {
|
||||||
return (
|
return (
|
||||||
<div className="p-6 text-red-400">
|
<div className="p-4 md:p-6 text-red-400">
|
||||||
{(error as Error)?.message ?? "Export not found"}
|
{(error as Error)?.message ?? "Export not found"}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -180,7 +180,7 @@ export function ExportDetailClient({ exportId }: { exportId: string }) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6 max-w-5xl">
|
<div className="p-4 md:p-6 space-y-6 max-w-5xl">
|
||||||
<div className="flex items-center justify-between gap-4 flex-wrap">
|
<div className="flex items-center justify-between gap-4 flex-wrap">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<Link href="/pipeline">
|
<Link href="/pipeline">
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export function MachinesClient() {
|
|||||||
const machines = data?.machines ?? [];
|
const machines = data?.machines ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-4 md:p-6 space-y-6">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<Link href="/pipeline">
|
<Link href="/pipeline">
|
||||||
<Button variant="ghost" size="icon-sm">
|
<Button variant="ghost" size="icon-sm">
|
||||||
|
|||||||
@@ -1,20 +1,32 @@
|
|||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { ExportStatus } from "@prisma/client";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { PipelineQueueClient } from "./PipelineQueueClient";
|
import { PipelineQueueClient } from "./PipelineQueueClient";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function PipelinePage() {
|
export default async function PipelinePage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<{ status?: string }>;
|
||||||
|
}) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user) redirect("/login");
|
if (!session?.user) redirect("/login");
|
||||||
if (session.user.role === "CLIENT") redirect("/dashboard");
|
if (session.user.role === "CLIENT") redirect("/dashboard");
|
||||||
|
|
||||||
|
// Lets other pages link straight to a filtered queue — the dashboard's "In
|
||||||
|
// QC" figure is only useful if it leads to the rows it counted. Anything
|
||||||
|
// that is not a real status falls back to the unfiltered queue.
|
||||||
|
const requested = (await searchParams).status;
|
||||||
|
const initialStatus =
|
||||||
|
requested && (Object.values(ExportStatus) as string[]).includes(requested) ? requested : "all";
|
||||||
|
|
||||||
const projects = await db.project.findMany({
|
const projects = await db.project.findMany({
|
||||||
where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
select: { id: true, name: true, code: true },
|
select: { id: true, name: true, code: true },
|
||||||
orderBy: { name: "asc" },
|
orderBy: { name: "asc" },
|
||||||
});
|
});
|
||||||
|
|
||||||
return <PipelineQueueClient projects={projects} />;
|
return <PipelineQueueClient projects={projects} initialStatus={initialStatus} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect, useRef, useCallback } from "react";
|
import { useState, useEffect, useRef, useCallback, useMemo, startTransition } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ReviewPlayer, type ReviewPlayerRef } from "@/components/player/ReviewPlayer";
|
import { ReviewPlayer, type ReviewPlayerRef } from "@/components/player/ReviewPlayer";
|
||||||
|
import { SequencePlayer, type SequenceClip } from "@/components/player/SequencePlayer";
|
||||||
import { useReviewStore } from "@/hooks/use-review-player";
|
import { useReviewStore } from "@/hooks/use-review-player";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
@@ -26,6 +27,8 @@ import {
|
|||||||
ExternalLink,
|
ExternalLink,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
Send,
|
Send,
|
||||||
|
ListVideo,
|
||||||
|
X,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
interface Project {
|
interface Project {
|
||||||
@@ -42,6 +45,12 @@ interface PlaylistVersion {
|
|||||||
thumbnailUrl: string | null;
|
thumbnailUrl: string | null;
|
||||||
posterUrl: string | null;
|
posterUrl: string | null;
|
||||||
fps: number;
|
fps: number;
|
||||||
|
duration?: number | null;
|
||||||
|
frameCount?: number | null;
|
||||||
|
hqFileUrl?: string | null;
|
||||||
|
handleHead?: number | null;
|
||||||
|
handleTail?: number | null;
|
||||||
|
pictureStartFrame?: number | null;
|
||||||
approvalStatus: string;
|
approvalStatus: string;
|
||||||
taskTitle: string;
|
taskTitle: string;
|
||||||
}
|
}
|
||||||
@@ -86,6 +95,10 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
const [activeShot, setActiveShot] = useState<PlaylistShot | null>(null);
|
const [activeShot, setActiveShot] = useState<PlaylistShot | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isActioning, setIsActioning] = useState(false);
|
const [isActioning, setIsActioning] = useState(false);
|
||||||
|
/** Shots checked for the seamless playlist, by shot id. */
|
||||||
|
const [selected, setSelected] = useState<Set<string>>(new Set());
|
||||||
|
const [sequenceMode, setSequenceMode] = useState(false);
|
||||||
|
const lastChecked = useRef<string | null>(null);
|
||||||
|
|
||||||
const canApprove = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(userRole);
|
const canApprove = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(userRole);
|
||||||
|
|
||||||
@@ -112,6 +125,9 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
const list: PlaylistShot[] = data.shots ?? [];
|
const list: PlaylistShot[] = data.shots ?? [];
|
||||||
setShots(list);
|
setShots(list);
|
||||||
|
setSelected(loadSelection(projectId, list));
|
||||||
|
lastChecked.current = null;
|
||||||
|
setSequenceMode(false);
|
||||||
// Auto-select the first shot, or keep the current one if it still exists
|
// Auto-select the first shot, or keep the current one if it still exists
|
||||||
setActiveShot((prev) => {
|
setActiveShot((prev) => {
|
||||||
const stillExists = prev && list.some((s) => s.id === prev.id);
|
const stillExists = prev && list.some((s) => s.id === prev.id);
|
||||||
@@ -134,9 +150,78 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
|
|
||||||
const handleSelectShot = useCallback((shot: PlaylistShot) => {
|
const handleSelectShot = useCallback((shot: PlaylistShot) => {
|
||||||
reset();
|
reset();
|
||||||
|
setSequenceMode(false);
|
||||||
setActiveShot(shot);
|
setActiveShot(shot);
|
||||||
}, [reset]);
|
}, [reset]);
|
||||||
|
|
||||||
|
const updateSelection = useCallback(
|
||||||
|
(next: Set<string>) => {
|
||||||
|
setSelected(next);
|
||||||
|
if (projectId) saveSelection(projectId, next);
|
||||||
|
if (next.size === 0) setSequenceMode(false);
|
||||||
|
},
|
||||||
|
[projectId]
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Toggle one shot; shift-click sets every shot between it and the last one checked. */
|
||||||
|
const toggleChecked = (shot: PlaylistShot, shift: boolean) => {
|
||||||
|
const next = new Set(selected);
|
||||||
|
const on = !selected.has(shot.id);
|
||||||
|
const from = lastChecked.current ? shots.findIndex((s) => s.id === lastChecked.current) : -1;
|
||||||
|
const to = shots.findIndex((s) => s.id === shot.id);
|
||||||
|
const range = shift && from >= 0 ? shots.slice(Math.min(from, to), Math.max(from, to) + 1) : [shot];
|
||||||
|
for (const s of range) {
|
||||||
|
if (on) next.add(s.id);
|
||||||
|
else next.delete(s.id);
|
||||||
|
}
|
||||||
|
lastChecked.current = shot.id;
|
||||||
|
updateSelection(next);
|
||||||
|
};
|
||||||
|
|
||||||
|
const setGroupChecked = (group: PlaylistShot[], on: boolean) => {
|
||||||
|
const next = new Set(selected);
|
||||||
|
for (const s of group) {
|
||||||
|
if (on) next.add(s.id);
|
||||||
|
else next.delete(s.id);
|
||||||
|
}
|
||||||
|
updateSelection(next);
|
||||||
|
};
|
||||||
|
|
||||||
|
// The playlist, in edit order. Keyed on the versions it plays so a refresh
|
||||||
|
// (e.g. after approving a shot) doesn't restart playback.
|
||||||
|
const clipKey = shots
|
||||||
|
.filter((s) => selected.has(s.id))
|
||||||
|
.map((s) => s.latestVersion.id)
|
||||||
|
.join(",");
|
||||||
|
const clips = useMemo<SequenceClip[]>(
|
||||||
|
() =>
|
||||||
|
shots
|
||||||
|
.filter((s) => selected.has(s.id))
|
||||||
|
.map((s) => ({
|
||||||
|
id: s.latestVersion.id,
|
||||||
|
label: s.shotCode,
|
||||||
|
sublabel: `v${String(s.latestVersion.versionNumber).padStart(3, "0")}`,
|
||||||
|
url: s.latestVersion.fileUrl,
|
||||||
|
hqUrl: s.latestVersion.hqFileUrl,
|
||||||
|
fps: s.latestVersion.fps,
|
||||||
|
duration: s.latestVersion.duration,
|
||||||
|
handles: s.latestVersion,
|
||||||
|
})),
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[clipKey]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleClipChange = useCallback(
|
||||||
|
(clip: SequenceClip) => {
|
||||||
|
// A transition, so re-rendering the page (shot list and all) yields to
|
||||||
|
// the video: rendered in one go, it dropped the frame after every cut.
|
||||||
|
startTransition(() => {
|
||||||
|
setActiveShot(shots.find((s) => s.latestVersion.id === clip.id) ?? null);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[shots]
|
||||||
|
);
|
||||||
|
|
||||||
const refreshShots = useCallback(() => {
|
const refreshShots = useCallback(() => {
|
||||||
if (!projectId) return;
|
if (!projectId) return;
|
||||||
fetch(`/api/playlist?projectId=${projectId}`)
|
fetch(`/api/playlist?projectId=${projectId}`)
|
||||||
@@ -215,6 +300,33 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{selected.size > 0 && (
|
||||||
|
sequenceMode ? (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setSequenceMode(false)}
|
||||||
|
className="h-7 text-xs gap-1"
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3" />
|
||||||
|
Exit playlist
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
reset();
|
||||||
|
setSequenceMode(true);
|
||||||
|
}}
|
||||||
|
className="h-7 text-xs gap-1"
|
||||||
|
title="Play the checked shots back to back: cut only, no slate or handles"
|
||||||
|
>
|
||||||
|
<ListVideo className="h-3.5 w-3.5" />
|
||||||
|
Play selection ({selected.size})
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
{activeShot && (
|
{activeShot && (
|
||||||
<div className="flex items-center gap-2 ml-auto">
|
<div className="flex items-center gap-2 ml-auto">
|
||||||
<span className="font-mono text-sm text-white">{activeShot.shotCode}</span>
|
<span className="font-mono text-sm text-white">{activeShot.shotCode}</span>
|
||||||
@@ -267,7 +379,9 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
<div className="flex flex-1 min-h-0 overflow-hidden">
|
<div className="flex flex-1 min-h-0 overflow-hidden">
|
||||||
{/* Player */}
|
{/* Player */}
|
||||||
<div className="flex-1 min-w-0 bg-black flex flex-col">
|
<div className="flex-1 min-w-0 bg-black flex flex-col">
|
||||||
{activeShot ? (
|
{sequenceMode && clips.length > 0 ? (
|
||||||
|
<SequencePlayer clips={clips} onClipChange={handleClipChange} />
|
||||||
|
) : activeShot ? (
|
||||||
<ReviewPlayer
|
<ReviewPlayer
|
||||||
key={activeShot.latestVersion.id}
|
key={activeShot.latestVersion.id}
|
||||||
ref={playerRef}
|
ref={playerRef}
|
||||||
@@ -276,6 +390,8 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
fps={activeShot.latestVersion.fps}
|
fps={activeShot.latestVersion.fps}
|
||||||
comments={[]}
|
comments={[]}
|
||||||
annotations={[]}
|
annotations={[]}
|
||||||
|
handles={activeShot.latestVersion}
|
||||||
|
hqVideoUrl={activeShot.latestVersion.hqFileUrl}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex-1 flex flex-col items-center justify-center gap-3 text-zinc-600">
|
<div className="flex-1 flex flex-col items-center justify-center gap-3 text-zinc-600">
|
||||||
@@ -297,7 +413,26 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
<div className="px-3 py-2.5 border-b border-border shrink-0 flex items-center justify-between">
|
<div className="px-3 py-2.5 border-b border-border shrink-0 flex items-center justify-between">
|
||||||
<span className="text-xs font-medium text-zinc-400 uppercase tracking-wider">Shots</span>
|
<span className="text-xs font-medium text-zinc-400 uppercase tracking-wider">Shots</span>
|
||||||
{shots.length > 0 && (
|
{shots.length > 0 && (
|
||||||
<span className="text-xs text-zinc-600">{shots.length}</span>
|
<div className="flex items-center gap-2 text-xs">
|
||||||
|
{selected.size > 0 ? (
|
||||||
|
<button
|
||||||
|
onClick={() => updateSelection(new Set())}
|
||||||
|
className="text-zinc-500 hover:text-zinc-200"
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
onClick={() => setGroupChecked(shots, true)}
|
||||||
|
className="text-zinc-500 hover:text-zinc-200"
|
||||||
|
>
|
||||||
|
Select all
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<span className="text-zinc-600">
|
||||||
|
{selected.size > 0 ? `${selected.size}/${shots.length}` : shots.length}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -320,16 +455,25 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
<div>
|
<div>
|
||||||
{episodeGroups.map(([episode, episodeShots]) => (
|
{episodeGroups.map(([episode, episodeShots]) => (
|
||||||
<div key={episode}>
|
<div key={episode}>
|
||||||
<div className="px-3 py-1.5 bg-zinc-900/80 sticky top-0 z-10 border-b border-zinc-800">
|
<label className="px-3 py-1.5 bg-zinc-900/80 sticky top-0 z-10 border-b border-zinc-800 flex items-center gap-2 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="h-3 w-3 accent-blue-500 cursor-pointer"
|
||||||
|
checked={episodeShots.every((s) => selected.has(s.id))}
|
||||||
|
onChange={(e) => setGroupChecked(episodeShots, e.target.checked)}
|
||||||
|
title="Select this episode"
|
||||||
|
/>
|
||||||
<span className="text-[10px] font-semibold text-zinc-500 uppercase tracking-wider">
|
<span className="text-[10px] font-semibold text-zinc-500 uppercase tracking-wider">
|
||||||
Ep {episode}
|
Ep {episode}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</label>
|
||||||
{episodeShots.map((shot) => (
|
{episodeShots.map((shot) => (
|
||||||
<ShotThumbnail
|
<ShotThumbnail
|
||||||
key={shot.id}
|
key={shot.id}
|
||||||
shot={shot}
|
shot={shot}
|
||||||
isActive={activeShot?.id === shot.id}
|
isActive={activeShot?.id === shot.id}
|
||||||
|
isChecked={selected.has(shot.id)}
|
||||||
|
onToggle={(shift) => toggleChecked(shot, shift)}
|
||||||
onClick={() => handleSelectShot(shot)}
|
onClick={() => handleSelectShot(shot)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@@ -343,6 +487,8 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
key={shot.id}
|
key={shot.id}
|
||||||
shot={shot}
|
shot={shot}
|
||||||
isActive={activeShot?.id === shot.id}
|
isActive={activeShot?.id === shot.id}
|
||||||
|
isChecked={selected.has(shot.id)}
|
||||||
|
onToggle={(shift) => toggleChecked(shot, shift)}
|
||||||
onClick={() => handleSelectShot(shot)}
|
onClick={() => handleSelectShot(shot)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@@ -358,25 +504,45 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
|||||||
function ShotThumbnail({
|
function ShotThumbnail({
|
||||||
shot,
|
shot,
|
||||||
isActive,
|
isActive,
|
||||||
|
isChecked,
|
||||||
|
onToggle,
|
||||||
onClick,
|
onClick,
|
||||||
}: {
|
}: {
|
||||||
shot: PlaylistShot;
|
shot: PlaylistShot;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
isChecked: boolean;
|
||||||
|
onToggle: (shift: boolean) => void;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
}) {
|
}) {
|
||||||
const thumb = shot.latestVersion.thumbnailUrl ?? shot.latestVersion.posterUrl ?? shot.thumbnailUrl;
|
const thumb = shot.latestVersion.thumbnailUrl ?? shot.latestVersion.posterUrl ?? shot.thumbnailUrl;
|
||||||
const ApprovalIcon = APPROVAL_ICONS[shot.latestVersion.approvalStatus] ?? Clock;
|
const ApprovalIcon = APPROVAL_ICONS[shot.latestVersion.approvalStatus] ?? Clock;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") onClick();
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full flex items-start gap-2.5 px-3 py-2.5 text-left transition-colors border-b border-zinc-800/60 group",
|
"w-full flex items-start gap-2.5 px-3 py-2.5 text-left transition-colors border-b border-zinc-800/60 group cursor-pointer",
|
||||||
isActive
|
isActive
|
||||||
? "bg-blue-500/10 border-l-2 border-l-blue-500"
|
? "bg-blue-500/10 border-l-2 border-l-blue-500"
|
||||||
: "hover:bg-zinc-800/40 border-l-2 border-l-transparent"
|
: "hover:bg-zinc-800/40 border-l-2 border-l-transparent"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={isChecked}
|
||||||
|
onChange={() => {}}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
onToggle(e.shiftKey);
|
||||||
|
}}
|
||||||
|
className="mt-3 h-3.5 w-3.5 shrink-0 accent-blue-500 cursor-pointer"
|
||||||
|
title="Add to playlist (shift-click for a range)"
|
||||||
|
/>
|
||||||
{/* Thumbnail */}
|
{/* Thumbnail */}
|
||||||
<div className="w-20 aspect-[2.39/1] rounded overflow-hidden bg-zinc-800 shrink-0 flex items-center justify-center">
|
<div className="w-20 aspect-[2.39/1] rounded overflow-hidden bg-zinc-800 shrink-0 flex items-center justify-center">
|
||||||
{thumb ? (
|
{thumb ? (
|
||||||
@@ -408,6 +574,28 @@ function ShotThumbnail({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectionKey = (projectId: string) => `playlist:selection:${projectId}`;
|
||||||
|
|
||||||
|
/** The checked shots remembered for this project, minus any no longer listed. */
|
||||||
|
function loadSelection(projectId: string, shots: PlaylistShot[]): Set<string> {
|
||||||
|
try {
|
||||||
|
const ids: unknown = JSON.parse(localStorage.getItem(selectionKey(projectId)) ?? "[]");
|
||||||
|
if (!Array.isArray(ids)) return new Set();
|
||||||
|
const listed = new Set(shots.map((s) => s.id));
|
||||||
|
return new Set(ids.filter((id): id is string => typeof id === "string" && listed.has(id)));
|
||||||
|
} catch {
|
||||||
|
return new Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSelection(projectId: string, selected: Set<string>) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(selectionKey(projectId), JSON.stringify([...selected]));
|
||||||
|
} catch {
|
||||||
|
// Storage unavailable: the selection just isn't remembered.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default async function KanbanPage({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6 max-w-[1800px] mx-auto">
|
<div className="p-4 md:p-6 space-y-6 max-w-[1800px] mx-auto">
|
||||||
{/* Breadcrumb */}
|
{/* Breadcrumb */}
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
<Link href="/projects" className="hover:text-foreground transition-colors">
|
<Link href="/projects" className="hover:text-foreground transition-colors">
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ export default async function ProjectPage({ params }: { params: Promise<{ id: st
|
|||||||
const doneTasks = project.tasks.filter((t) => t.status === "DONE").length;
|
const doneTasks = project.tasks.filter((t) => t.status === "DONE").length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8 space-y-6 max-w-[1600px] mx-auto">
|
<div className="p-4 md:p-8 space-y-6 max-w-[1600px] mx-auto">
|
||||||
{/* Breadcrumb */}
|
{/* Breadcrumb */}
|
||||||
<div className="flex items-center gap-2 text-sm text-zinc-500">
|
<div className="flex items-center gap-2 text-sm text-zinc-500">
|
||||||
<Link href="/projects" className="hover:text-white transition-colors">
|
<Link href="/projects" className="hover:text-white transition-colors">
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ export default function ShotDetailPage() {
|
|||||||
const { Icon: StatusIcon } = statusCfg;
|
const { Icon: StatusIcon } = statusCfg;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6 max-w-[1400px] mx-auto">
|
<div className="p-4 md:p-6 space-y-6 max-w-[1400px] mx-auto">
|
||||||
{/* Breadcrumb */}
|
{/* Breadcrumb */}
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
<Link href="/projects" className="hover:text-foreground transition-colors">
|
<Link href="/projects" className="hover:text-foreground transition-colors">
|
||||||
@@ -245,7 +245,9 @@ export default function ShotDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex items-start gap-6">
|
{/* Phones: back button, then a full-width thumbnail, then the details
|
||||||
|
below it. From md: one row, as on desktop. */}
|
||||||
|
<div className="flex flex-wrap md:flex-nowrap items-start gap-4 md:gap-6">
|
||||||
{/* Thumbnail – cinema scope 2.39:1 */}
|
{/* Thumbnail – cinema scope 2.39:1 */}
|
||||||
<Button variant="ghost" size="icon" asChild className="-ml-2 h-8 w-8">
|
<Button variant="ghost" size="icon" asChild className="-ml-2 h-8 w-8">
|
||||||
<Link href={`/projects/${params.id}`}>
|
<Link href={`/projects/${params.id}`}>
|
||||||
@@ -253,7 +255,7 @@ export default function ShotDetailPage() {
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
{shotThumbnail(shot) && (
|
{shotThumbnail(shot) && (
|
||||||
<div className="relative flex-shrink-0 w-72 aspect-[2.39] rounded-lg overflow-hidden border border-border">
|
<div className="relative flex-shrink-0 w-full md:w-72 aspect-[2.39] rounded-lg overflow-hidden border border-border">
|
||||||
|
|
||||||
<Image
|
<Image
|
||||||
src={shotThumbnail(shot)!}
|
src={shotThumbnail(shot)!}
|
||||||
@@ -263,10 +265,10 @@ export default function ShotDetailPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2 min-w-0 w-full md:w-auto md:min-w-min">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
|
|
||||||
<h1 className="text-2xl font-bold font-mono">{shot.shotCode}</h1>
|
<h1 className="text-2xl font-bold font-mono break-all md:break-normal">{shot.shotCode}</h1>
|
||||||
|
|
||||||
{/* Shot version badge — click to edit for managers */}
|
{/* Shot version badge — click to edit for managers */}
|
||||||
{canManage ? (
|
{canManage ? (
|
||||||
@@ -424,7 +426,7 @@ export default function ShotDetailPage() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{canManage && (
|
{canManage && (
|
||||||
<div className="ml-auto shrink-0 flex items-center gap-2">
|
<div className="ml-auto shrink-0 flex flex-wrap md:flex-nowrap items-center gap-2 w-full md:w-auto">
|
||||||
{/* Internal approval action */}
|
{/* Internal approval action */}
|
||||||
{canInternallyApprove && shot.shotApprovalStatus === "PENDING" && (
|
{canInternallyApprove && shot.shotApprovalStatus === "PENDING" && (
|
||||||
<Button
|
<Button
|
||||||
@@ -510,7 +512,8 @@ export default function ShotDetailPage() {
|
|||||||
|
|
||||||
{/* Tabs */}
|
{/* Tabs */}
|
||||||
<div>
|
<div>
|
||||||
<div className="flex border-b border-border mb-5">
|
{/* Phones: five tabs are wider than the screen, so the bar scrolls sideways. */}
|
||||||
|
<div className="flex border-b border-border mb-5 overflow-x-auto overflow-y-hidden md:overflow-visible [&>button]:shrink-0 [&>button]:whitespace-nowrap">
|
||||||
<button
|
<button
|
||||||
onClick={() => setActiveTab("tasks")}
|
onClick={() => setActiveTab("tasks")}
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
@@ -8,6 +8,7 @@ import { ProjectCard } from "@/components/projects/ProjectCard";
|
|||||||
import { NewProjectDialog } from "@/components/projects/NewProjectDialog";
|
import { NewProjectDialog } from "@/components/projects/NewProjectDialog";
|
||||||
import { Plus, Search, Loader2 } from "lucide-react";
|
import { Plus, Search, Loader2 } from "lucide-react";
|
||||||
import { HIDE_ARCHIVED_KEY } from "@/components/settings/HideArchivedToggle";
|
import { HIDE_ARCHIVED_KEY } from "@/components/settings/HideArchivedToggle";
|
||||||
|
import { useScrollMemory } from "@/hooks/use-scroll-memory";
|
||||||
|
|
||||||
export default function ProjectsPage() {
|
export default function ProjectsPage() {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
@@ -43,22 +44,11 @@ export default function ProjectsPage() {
|
|||||||
|
|
||||||
const visibleProjects = hideArchived ? projects.filter((p: any) => p.status !== "ARCHIVED") : projects;
|
const visibleProjects = hideArchived ? projects.filter((p: any) => p.status !== "ARCHIVED") : projects;
|
||||||
|
|
||||||
const SCROLL_KEY = 'projects-scroll';
|
const pageRef = useRef<HTMLDivElement>(null);
|
||||||
|
useScrollMemory("projects", pageRef, !isLoading);
|
||||||
useEffect(() => {
|
|
||||||
if (!isLoading) {
|
|
||||||
const saved = sessionStorage.getItem(SCROLL_KEY);
|
|
||||||
if (saved) {
|
|
||||||
sessionStorage.removeItem(SCROLL_KEY);
|
|
||||||
requestAnimationFrame(() => window.scrollTo(0, parseInt(saved, 10)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [isLoading]);
|
|
||||||
|
|
||||||
const saveScroll = () => sessionStorage.setItem(SCROLL_KEY, String(window.scrollY));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8 space-y-6 max-w-[1600px] mx-auto">
|
<div ref={pageRef} className="p-4 md:p-8 space-y-6 max-w-[1600px] mx-auto">
|
||||||
<div className="flex items-center justify-between gap-4 mb-8">
|
<div className="flex items-center justify-between gap-4 mb-8">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-3xl font-bold text-white">Projects</h1>
|
<h1 className="text-3xl font-bold text-white">Projects</h1>
|
||||||
@@ -104,9 +94,11 @@ export default function ProjectsPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
// auto-rows-fr keeps every row the same height, so a project with a
|
||||||
|
// long description does not make its whole row taller than the rest.
|
||||||
|
<div className="grid auto-rows-fr grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||||
{visibleProjects.map((project: any) => (
|
{visibleProjects.map((project: any) => (
|
||||||
<div key={project.id} onClick={saveScroll}>
|
<div key={project.id} className="h-full">
|
||||||
<ProjectCard project={project} />
|
<ProjectCard project={project} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ export default function MigrationPage() {
|
|||||||
|
|
||||||
if (fetchError) {
|
if (fetchError) {
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-2xl">
|
<div className="p-4 md:p-6 max-w-2xl">
|
||||||
<div className="flex items-center gap-2 text-sm text-red-400 rounded-md border border-red-500/20 bg-red-500/10 px-3 py-2">
|
<div className="flex items-center gap-2 text-sm text-red-400 rounded-md border border-red-500/20 bg-red-500/10 px-3 py-2">
|
||||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||||
{fetchError}
|
{fetchError}
|
||||||
@@ -200,7 +200,7 @@ export default function MigrationPage() {
|
|||||||
|
|
||||||
if (!hetznerConfigured) {
|
if (!hetznerConfigured) {
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-2xl">
|
<div className="p-4 md:p-6 max-w-2xl">
|
||||||
<div className="flex items-center gap-2 text-sm text-amber-400 rounded-md border border-amber-500/20 bg-amber-500/10 px-3 py-2">
|
<div className="flex items-center gap-2 text-sm text-amber-400 rounded-md border border-amber-500/20 bg-amber-500/10 px-3 py-2">
|
||||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||||
Hetzner object storage is not configured. Set{" "}
|
Hetzner object storage is not configured. Set{" "}
|
||||||
@@ -217,7 +217,7 @@ export default function MigrationPage() {
|
|||||||
const allFilteredSelected = filtered.length > 0 && filtered.every((f) => selected.has(f.key));
|
const allFilteredSelected = filtered.length > 0 && filtered.every((f) => selected.has(f.key));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-4 max-w-5xl">
|
<div className="p-4 md:p-6 space-y-4 max-w-5xl">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex items-start justify-between gap-4">
|
<div className="flex items-start justify-between gap-4">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default async function SettingsPage() {
|
|||||||
const hetznerConfig = isAdmin ? await getHetznerConfig() : null;
|
const hetznerConfig = isAdmin ? await getHetznerConfig() : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6 max-w-2xl mx-auto">
|
<div className="p-4 md:p-6 space-y-6 max-w-2xl mx-auto">
|
||||||
<h1 className="text-2xl font-bold">Account Settings</h1>
|
<h1 className="text-2xl font-bold">Account Settings</h1>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export default function StorageTestPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-3xl space-y-6">
|
<div className="p-4 md:p-6 max-w-3xl space-y-6">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-xl font-semibold">Object Storage Playback Test</h1>
|
<h1 className="text-xl font-semibold">Object Storage Playback Test</h1>
|
||||||
<p className="text-sm text-muted-foreground mt-1">
|
<p className="text-sm text-muted-foreground mt-1">
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import { useState, useTransition, useCallback, useEffect, useRef } from "react";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useScrollMemory } from "@/hooks/use-scroll-memory";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
|
SelectSeparator,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
@@ -28,10 +30,12 @@ import {
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { cn } from "@/lib/utils";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { updateShotNotes, bulkUpdateDueDates, bulkDeleteShots, toggleKeyShot, toggleScaledShot } from "@/actions/shots";
|
import { cn, getInitials } from "@/lib/utils";
|
||||||
|
import { updateShotNotes, bulkUpdateDueDates, bulkAssignArtist, bulkDeleteShots, bulkSetManualDelivery, toggleKeyShot, toggleScaledShot } from "@/actions/shots";
|
||||||
import { previewMovReview, buildMovReview } from "@/actions/deliveries";
|
import { previewMovReview, buildMovReview } from "@/actions/deliveries";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { LogRequestDialog } from "@/components/delivery/LogRequestDialog";
|
||||||
import {
|
import {
|
||||||
Film,
|
Film,
|
||||||
Clock,
|
Clock,
|
||||||
@@ -50,9 +54,13 @@ import {
|
|||||||
ChevronsUpDown,
|
ChevronsUpDown,
|
||||||
Clapperboard,
|
Clapperboard,
|
||||||
Scaling,
|
Scaling,
|
||||||
|
UserPlus,
|
||||||
|
PackageCheck,
|
||||||
|
ClipboardList,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { shotThumbnail } from "@/lib/shot-thumbnail";
|
import { shotThumbnail } from "@/lib/shot-thumbnail";
|
||||||
|
import type { ShotDeliverySummary } from "@/lib/render-pipeline/shot-delivery-summary";
|
||||||
|
|
||||||
type ShotRow = {
|
type ShotRow = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -69,11 +77,21 @@ type ShotRow = {
|
|||||||
description: string | null;
|
description: string | null;
|
||||||
isKeyShot: boolean;
|
isKeyShot: boolean;
|
||||||
isScaled: boolean;
|
isScaled: boolean;
|
||||||
|
manualDeliveredAt: Date | string | null;
|
||||||
|
manualDeliveryNote: string | null;
|
||||||
shotVersion: string | null;
|
shotVersion: string | null;
|
||||||
|
delivery: ShotDeliverySummary;
|
||||||
artist: { id: string; name: string | null; image: string | null; email: string } | null;
|
artist: { id: string; name: string | null; image: string | null; email: string } | null;
|
||||||
shotGroup: { id: string; name: string } | null;
|
shotGroup: { id: string; name: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface Artist {
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
email: string;
|
||||||
|
image: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
interface Project {
|
interface Project {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -87,10 +105,29 @@ interface ShotStatusClientProps {
|
|||||||
selectedProject: Project | null;
|
selectedProject: Project | null;
|
||||||
shots: ShotRow[];
|
shots: ShotRow[];
|
||||||
episodeDueDates: { episode: string; dueDate: Date | string }[];
|
episodeDueDates: { episode: string; dueDate: Date | string }[];
|
||||||
|
artists: Artist[];
|
||||||
canManage: boolean;
|
canManage: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SCROLL_KEY = 'shot-status-scroll';
|
function readStored(key: string): string | null {
|
||||||
|
try {
|
||||||
|
return localStorage.getItem(key);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A saved list of open sections, or null when none was saved (or it is unreadable). */
|
||||||
|
function readStoredList(key: string): string[] | null {
|
||||||
|
const raw = readStored(key);
|
||||||
|
if (!raw) return null;
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw);
|
||||||
|
return Array.isArray(parsed) ? parsed.filter((v): v is string => typeof v === "string") : null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const STATUS_CONFIG: Record<string, { label: string; color: string; icon: React.ElementType }> = {
|
const STATUS_CONFIG: Record<string, { label: string; color: string; icon: React.ElementType }> = {
|
||||||
WAITING: { label: "Waiting", color: "bg-zinc-500/10 text-zinc-400 border-zinc-500/20", icon: Clock },
|
WAITING: { label: "Waiting", color: "bg-zinc-500/10 text-zinc-400 border-zinc-500/20", icon: Clock },
|
||||||
@@ -225,6 +262,257 @@ function BulkDueDateDialog({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── BulkAssignArtistDialog ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const UNASSIGN = "__unassign__";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hand a selection of shots to one artist, or clear the assignment.
|
||||||
|
*
|
||||||
|
* Unassigning is offered as an explicit choice rather than a separate menu
|
||||||
|
* entry — reassignment and hand-back are the same production move, and the
|
||||||
|
* confirm button changes wording so nobody clears a batch by accident.
|
||||||
|
*/
|
||||||
|
function BulkAssignArtistDialog({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onApply,
|
||||||
|
artists,
|
||||||
|
count,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onApply: (artistId: string | null) => Promise<void>;
|
||||||
|
artists: Artist[];
|
||||||
|
count: number;
|
||||||
|
}) {
|
||||||
|
const [value, setValue] = useState("");
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) setValue("");
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const handleApply = () => {
|
||||||
|
if (!value) return;
|
||||||
|
startTransition(async () => {
|
||||||
|
await onApply(value === UNASSIGN ? null : value);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unassigning = value === UNASSIGN;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={(o) => { if (!o && !isPending) onClose(); }}>
|
||||||
|
<DialogContent className="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Assign Artist</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<p className="text-sm text-zinc-400 -mt-1">
|
||||||
|
Applying to <span className="text-white font-medium">{count}</span>{" "}
|
||||||
|
shot{count !== 1 ? "s" : ""}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="space-y-1.5 pt-1">
|
||||||
|
<label className="text-xs font-medium text-zinc-400">Artist</label>
|
||||||
|
<Select value={value} onValueChange={setValue}>
|
||||||
|
<SelectTrigger className="w-full">
|
||||||
|
<SelectValue placeholder="Select an artist..." />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{artists.map((a) => (
|
||||||
|
<SelectItem key={a.id} value={a.id}>
|
||||||
|
<span className="flex items-center gap-2">
|
||||||
|
<Avatar className="h-5 w-5">
|
||||||
|
<AvatarImage src={a.image ?? undefined} />
|
||||||
|
<AvatarFallback className="text-[9px] bg-zinc-700 text-zinc-300">
|
||||||
|
{getInitials(a.name ?? a.email)}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
{a.name ?? a.email}
|
||||||
|
</span>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
<SelectSeparator />
|
||||||
|
<SelectItem value={UNASSIGN}>
|
||||||
|
<span className="text-zinc-400">Unassign</span>
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<p className="text-xs text-zinc-500 pt-1">
|
||||||
|
This replaces whoever is currently on {count === 1 ? "the shot" : "these shots"}.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter className="mt-2">
|
||||||
|
<Button variant="ghost" onClick={onClose} disabled={isPending}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleApply} disabled={!value || isPending}>
|
||||||
|
{isPending && <Loader2 className="h-3.5 w-3.5 mr-1.5 animate-spin" />}
|
||||||
|
{unassigning ? "Unassign" : "Assign"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── ManualDeliveryDialog ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record shots as delivered outside the render pipeline — the ones sent by
|
||||||
|
* hand before packages existed, which have no Export to put in a package.
|
||||||
|
*
|
||||||
|
* The date asked for is when the frames went out, not today: the delivery
|
||||||
|
* countdown's weekly rate reads it, so a backfill stamped with today's date
|
||||||
|
* would claim a week nobody had.
|
||||||
|
*/
|
||||||
|
function ManualDeliveryDialog({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onApply,
|
||||||
|
count,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onApply: (
|
||||||
|
deliveredOn: string | null,
|
||||||
|
note: string,
|
||||||
|
evidence: { uploadUrl: string; sharedWith: string },
|
||||||
|
) => Promise<void>;
|
||||||
|
count: number;
|
||||||
|
}) {
|
||||||
|
const [date, setDate] = useState("");
|
||||||
|
const [note, setNote] = useState("");
|
||||||
|
const [uploadUrl, setUploadUrl] = useState("");
|
||||||
|
const [sharedWith, setSharedWith] = useState("");
|
||||||
|
const [clearing, setClearing] = useState(false);
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setDate("");
|
||||||
|
setNote("");
|
||||||
|
setUploadUrl("");
|
||||||
|
setSharedWith("");
|
||||||
|
setClearing(false);
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const handleApply = () => {
|
||||||
|
if (!clearing && !date) return;
|
||||||
|
startTransition(async () => {
|
||||||
|
await onApply(clearing ? null : date, note, { uploadUrl, sharedWith });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={(o) => { if (!o && !isPending) onClose(); }}>
|
||||||
|
<DialogContent className="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Delivered Outside Pipeline</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<p className="text-sm text-zinc-400 -mt-1">
|
||||||
|
Applying to <span className="text-white font-medium">{count}</span>{" "}
|
||||||
|
shot{count !== 1 ? "s" : ""}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="space-y-4 pt-1">
|
||||||
|
<div className="space-y-2.5">
|
||||||
|
<label className="flex items-center gap-2.5 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="manual-delivery-mode"
|
||||||
|
checked={!clearing}
|
||||||
|
onChange={() => setClearing(false)}
|
||||||
|
className="accent-blue-500 cursor-pointer"
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-zinc-200">Mark as delivered</span>
|
||||||
|
</label>
|
||||||
|
<label className="flex items-center gap-2.5 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="manual-delivery-mode"
|
||||||
|
checked={clearing}
|
||||||
|
onChange={() => setClearing(true)}
|
||||||
|
className="accent-blue-500 cursor-pointer"
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-zinc-200">Clear manual delivery</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!clearing && (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label className="text-xs font-medium text-zinc-400">Date the shots went out</label>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={date}
|
||||||
|
max={format(new Date(), "yyyy-MM-dd")}
|
||||||
|
onChange={(e) => setDate(e.target.value)}
|
||||||
|
className="w-full rounded-md border border-zinc-700 bg-zinc-900 px-3 py-2 text-sm text-zinc-100 [color-scheme:dark] focus:border-zinc-500 focus:outline-none focus:ring-1 focus:ring-zinc-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label className="text-xs font-medium text-zinc-400">Upload link</label>
|
||||||
|
<input
|
||||||
|
type="url"
|
||||||
|
value={uploadUrl}
|
||||||
|
onChange={(e) => setUploadUrl(e.target.value)}
|
||||||
|
placeholder="https://…"
|
||||||
|
className="w-full rounded-md border border-zinc-700 bg-zinc-900 px-3 py-2 text-sm text-zinc-100 placeholder:text-zinc-600 focus:border-zinc-500 focus:outline-none focus:ring-1 focus:ring-zinc-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label className="text-xs font-medium text-zinc-400">Link sent to</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={sharedWith}
|
||||||
|
onChange={(e) => setSharedWith(e.target.value)}
|
||||||
|
placeholder="Name, and where it was sent"
|
||||||
|
className="w-full rounded-md border border-zinc-700 bg-zinc-900 px-3 py-2 text-sm text-zinc-100 placeholder:text-zinc-600 focus:border-zinc-500 focus:outline-none focus:ring-1 focus:ring-zinc-500"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-zinc-500">
|
||||||
|
Both are needed for shots on an open delivery request; a backfill of old deliveries can leave
|
||||||
|
them blank.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label className="text-xs font-medium text-zinc-400">Note (optional)</label>
|
||||||
|
<Textarea
|
||||||
|
value={note}
|
||||||
|
onChange={(e) => setNote(e.target.value)}
|
||||||
|
placeholder="e.g. Aspera upload, turnover 3"
|
||||||
|
className="min-h-[56px] text-sm resize-none bg-zinc-900 border-zinc-700 focus:border-zinc-500 text-zinc-200 placeholder:text-zinc-600"
|
||||||
|
rows={2}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<p className="text-xs text-zinc-500">
|
||||||
|
For shots sent by hand before the render pipeline. They count as delivered on the
|
||||||
|
dashboard; no package is created and nothing is sent.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter className="mt-2">
|
||||||
|
<Button variant="ghost" onClick={onClose} disabled={isPending}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleApply} disabled={(!clearing && !date) || isPending}>
|
||||||
|
{isPending && <Loader2 className="h-3.5 w-3.5 mr-1.5 animate-spin" />}
|
||||||
|
{clearing ? "Clear" : "Mark delivered"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function BulkDeleteDialog({
|
function BulkDeleteDialog({
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
@@ -567,6 +855,56 @@ function ScaledShotToggle({ shot }: { shot: ShotRow }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PENDING_TONE = {
|
||||||
|
progress: "text-blue-300",
|
||||||
|
waiting: "text-amber-300",
|
||||||
|
failed: "text-red-400",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What last reached the client for this shot, with evidence — not what was
|
||||||
|
* rendered or built — plus whatever newer is still on its way.
|
||||||
|
*/
|
||||||
|
function DeliveryCell({ delivery, shotVersion }: { delivery: ShotDeliverySummary; shotVersion: string | null }) {
|
||||||
|
const { sent, review, pending } = delivery;
|
||||||
|
if (!sent && !review && !pending) {
|
||||||
|
return <span className="text-xs text-zinc-600 italic">Never sent</span>;
|
||||||
|
}
|
||||||
|
// The panel's version moving past what was delivered means a newer version
|
||||||
|
// exists that the client has not had, even before it has been exported.
|
||||||
|
const behind = sent?.version && shotVersion && sent.version !== shotVersion && !pending;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-0.5 text-xs leading-tight">
|
||||||
|
{sent ? (
|
||||||
|
<div
|
||||||
|
className="flex items-center gap-1 whitespace-nowrap text-emerald-300"
|
||||||
|
// Who it went to stays in the tooltip: an email address swamps the column.
|
||||||
|
title={[sent.label, sent.to && `sent to ${sent.to}`, sent.note].filter(Boolean).join(" · ")}
|
||||||
|
>
|
||||||
|
<PackageCheck className="h-3 w-3 shrink-0" />
|
||||||
|
{sent.version && <span className="font-mono">{sent.version}</span>}
|
||||||
|
<span className="text-zinc-300">{format(new Date(sent.at), "d MMM")}</span>
|
||||||
|
{sent.via === "MANUAL" && <span className="text-zinc-500">· manual</span>}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="text-zinc-600 italic">Not delivered</div>
|
||||||
|
)}
|
||||||
|
{pending && (
|
||||||
|
<div className={cn("truncate", PENDING_TONE[pending.tone])} title={pending.label}>
|
||||||
|
{pending.version && <span className="font-mono">{pending.version}</span>} {pending.label}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{behind && <div className="text-zinc-500">current is <span className="font-mono">{shotVersion}</span></div>}
|
||||||
|
{review && (
|
||||||
|
<div className="truncate text-zinc-500" title={review.label}>
|
||||||
|
Review MOV <span className="font-mono">{review.version}</span> {format(new Date(review.at), "d MMM")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function ShotTable({
|
function ShotTable({
|
||||||
shots,
|
shots,
|
||||||
canManage,
|
canManage,
|
||||||
@@ -601,7 +939,9 @@ function ShotTable({
|
|||||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Thumb</th>
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Thumb</th>
|
||||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500">Shot</th>
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500">Shot</th>
|
||||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Status</th>
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Status</th>
|
||||||
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-40">Artist</th>
|
||||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Due Date</th>
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Due Date</th>
|
||||||
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-36">Last sent</th>
|
||||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500">Notes</th>
|
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500">Notes</th>
|
||||||
<th className="py-2 px-3 text-xs font-medium text-zinc-500 w-20 text-center">
|
<th className="py-2 px-3 text-xs font-medium text-zinc-500 w-20 text-center">
|
||||||
<span className="flex items-center gap-1 justify-center">
|
<span className="flex items-center gap-1 justify-center">
|
||||||
@@ -671,7 +1011,6 @@ function ShotTable({
|
|||||||
<Link
|
<Link
|
||||||
href={`/projects/${projectId}/shots/${shot.id}`}
|
href={`/projects/${projectId}/shots/${shot.id}`}
|
||||||
className="font-mono text-sm text-white hover:text-blue-400 transition-colors"
|
className="font-mono text-sm text-white hover:text-blue-400 transition-colors"
|
||||||
onClick={() => sessionStorage.setItem(SCROLL_KEY, String(window.scrollY))}
|
|
||||||
>
|
>
|
||||||
{shot.shotCode}
|
{shot.shotCode}
|
||||||
</Link>
|
</Link>
|
||||||
@@ -700,6 +1039,25 @@ function ShotTable({
|
|||||||
</Badge>
|
</Badge>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
{/* Artist */}
|
||||||
|
<td className="py-2 px-3">
|
||||||
|
{shot.artist ? (
|
||||||
|
<span className="flex items-center gap-2 min-w-0">
|
||||||
|
<Avatar className="h-5 w-5 shrink-0">
|
||||||
|
<AvatarImage src={shot.artist.image ?? undefined} />
|
||||||
|
<AvatarFallback className="text-[9px] bg-zinc-700 text-zinc-300">
|
||||||
|
{getInitials(shot.artist.name ?? shot.artist.email)}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<span className="text-xs text-zinc-300 truncate">
|
||||||
|
{shot.artist.name ?? shot.artist.email}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-xs text-zinc-600 italic">Unassigned</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
|
||||||
{/* Due date */}
|
{/* Due date */}
|
||||||
<td className="py-2 px-3">
|
<td className="py-2 px-3">
|
||||||
{dueDate ? (
|
{dueDate ? (
|
||||||
@@ -717,6 +1075,11 @@ function ShotTable({
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
{/* Last delivery, and anything newer on its way */}
|
||||||
|
<td className="py-2 px-3">
|
||||||
|
<DeliveryCell delivery={shot.delivery} shotVersion={shot.shotVersion} />
|
||||||
|
</td>
|
||||||
|
|
||||||
{/* Notes */}
|
{/* Notes */}
|
||||||
<td className="py-2 px-3 min-w-[220px]">
|
<td className="py-2 px-3 min-w-[220px]">
|
||||||
<NotesCell shot={shot} canManage={canManage} />
|
<NotesCell shot={shot} canManage={canManage} />
|
||||||
@@ -745,20 +1108,12 @@ export function ShotStatusClient({
|
|||||||
selectedProject,
|
selectedProject,
|
||||||
shots,
|
shots,
|
||||||
episodeDueDates,
|
episodeDueDates,
|
||||||
|
artists,
|
||||||
canManage,
|
canManage,
|
||||||
}: ShotStatusClientProps) {
|
}: ShotStatusClientProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
// Restore scroll position when shots load
|
|
||||||
useEffect(() => {
|
|
||||||
const saved = sessionStorage.getItem(SCROLL_KEY);
|
|
||||||
if (saved) {
|
|
||||||
sessionStorage.removeItem(SCROLL_KEY);
|
|
||||||
requestAnimationFrame(() => window.scrollTo(0, parseInt(saved, 10)));
|
|
||||||
}
|
|
||||||
}, [shots]);
|
|
||||||
|
|
||||||
// Restore last selected project if no project is currently selected
|
// Restore last selected project if no project is currently selected
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedProjectId) {
|
if (!selectedProjectId) {
|
||||||
@@ -776,35 +1131,51 @@ export function ShotStatusClient({
|
|||||||
const [groupMode, setGroupMode] = useState<"flat" | "scene" | "group">("flat");
|
const [groupMode, setGroupMode] = useState<"flat" | "scene" | "group">("flat");
|
||||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
// Load saved episode expand state when project changes
|
// Which sections were open is restored before the scroll position: until
|
||||||
|
// they are, the page is shorter and the saved offset would not fit.
|
||||||
|
const [expandRestored, setExpandRestored] = useState(false);
|
||||||
|
const pageRef = useRef<HTMLDivElement>(null);
|
||||||
|
useScrollMemory(selectedProjectId ? `shotStatus:${selectedProjectId}` : null, pageRef, expandRestored);
|
||||||
|
|
||||||
|
// Load saved expand state and grouping when the project changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedProjectId) return;
|
if (!selectedProjectId) return;
|
||||||
try {
|
setExpandRestored(false);
|
||||||
const saved = localStorage.getItem(`shotStatus:${selectedProjectId}:episodeExpand`);
|
const mode = (readStored(`shotStatus:${selectedProjectId}:groupMode`) ?? "flat") as "flat" | "scene" | "group";
|
||||||
setExpandedEpisodes(saved ? new Set(JSON.parse(saved) as string[]) : new Set());
|
setGroupMode(mode);
|
||||||
} catch {
|
setExpandedEpisodes(new Set(readStoredList(`shotStatus:${selectedProjectId}:episodeExpand`) ?? []));
|
||||||
setExpandedEpisodes(new Set());
|
// Scenes and groups open fully when their mode is first chosen, so with
|
||||||
}
|
// nothing saved yet they come back that way rather than all collapsed.
|
||||||
try {
|
setExpandedScenes(
|
||||||
const savedGroup = localStorage.getItem(`shotStatus:${selectedProjectId}:groupMode`);
|
new Set(readStoredList(`shotStatus:${selectedProjectId}:sceneExpand`) ?? shots.map((s) => s.scene))
|
||||||
setGroupMode((savedGroup as "flat" | "scene" | "group") ?? "flat");
|
);
|
||||||
} catch {
|
setExpandedGroups(
|
||||||
setGroupMode("flat");
|
new Set(readStoredList(`shotStatus:${selectedProjectId}:groupExpand`) ?? shots.map((s) => s.shotGroup?.id ?? ""))
|
||||||
}
|
);
|
||||||
|
setExpandRestored(true);
|
||||||
|
// Shots are read only for the defaults; a refresh after an edit must not
|
||||||
|
// reset what the user has opened.
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [selectedProjectId]);
|
}, [selectedProjectId]);
|
||||||
|
|
||||||
|
const saveExpanded = (kind: "episodeExpand" | "sceneExpand" | "groupExpand", open: Set<string>) => {
|
||||||
|
if (!selectedProjectId) return;
|
||||||
|
try {
|
||||||
|
localStorage.setItem(`shotStatus:${selectedProjectId}:${kind}`, JSON.stringify([...open]));
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
const [dueDateDialogOpen, setDueDateDialogOpen] = useState(false);
|
const [dueDateDialogOpen, setDueDateDialogOpen] = useState(false);
|
||||||
|
const [assignDialogOpen, setAssignDialogOpen] = useState(false);
|
||||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||||
const [movReviewDialogOpen, setMovReviewDialogOpen] = useState(false);
|
const [movReviewDialogOpen, setMovReviewDialogOpen] = useState(false);
|
||||||
|
const [manualDeliveryDialogOpen, setManualDeliveryDialogOpen] = useState(false);
|
||||||
|
const [requestDialogOpen, setRequestDialogOpen] = useState(false);
|
||||||
|
|
||||||
const toggleEpisode = (ep: string) =>
|
const toggleEpisode = (ep: string) =>
|
||||||
setExpandedEpisodes((prev) => {
|
setExpandedEpisodes((prev) => {
|
||||||
const next = new Set(prev);
|
const next = new Set(prev);
|
||||||
next.has(ep) ? next.delete(ep) : next.add(ep);
|
next.has(ep) ? next.delete(ep) : next.add(ep);
|
||||||
if (selectedProjectId) {
|
saveExpanded("episodeExpand", next);
|
||||||
try {
|
|
||||||
localStorage.setItem(`shotStatus:${selectedProjectId}:episodeExpand`, JSON.stringify([...next]));
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -812,6 +1183,7 @@ export function ShotStatusClient({
|
|||||||
setExpandedScenes((prev) => {
|
setExpandedScenes((prev) => {
|
||||||
const next = new Set(prev);
|
const next = new Set(prev);
|
||||||
next.has(sc) ? next.delete(sc) : next.add(sc);
|
next.has(sc) ? next.delete(sc) : next.add(sc);
|
||||||
|
saveExpanded("sceneExpand", next);
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -819,13 +1191,22 @@ export function ShotStatusClient({
|
|||||||
setExpandedGroups((prev) => {
|
setExpandedGroups((prev) => {
|
||||||
const next = new Set(prev);
|
const next = new Set(prev);
|
||||||
next.has(g) ? next.delete(g) : next.add(g);
|
next.has(g) ? next.delete(g) : next.add(g);
|
||||||
|
saveExpanded("groupExpand", next);
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleGroupMode = (mode: "flat" | "scene" | "group") => {
|
const handleGroupMode = (mode: "flat" | "scene" | "group") => {
|
||||||
setGroupMode(mode);
|
setGroupMode(mode);
|
||||||
if (mode === "scene") setExpandedScenes(new Set(shots.map((s) => s.scene)));
|
if (mode === "scene") {
|
||||||
if (mode === "group") setExpandedGroups(new Set(shots.map((s) => s.shotGroup?.id ?? "")));
|
const all = new Set(shots.map((s) => s.scene));
|
||||||
|
setExpandedScenes(all);
|
||||||
|
saveExpanded("sceneExpand", all);
|
||||||
|
}
|
||||||
|
if (mode === "group") {
|
||||||
|
const all = new Set(shots.map((s) => s.shotGroup?.id ?? ""));
|
||||||
|
setExpandedGroups(all);
|
||||||
|
saveExpanded("groupExpand", all);
|
||||||
|
}
|
||||||
if (selectedProjectId) {
|
if (selectedProjectId) {
|
||||||
try { localStorage.setItem(`shotStatus:${selectedProjectId}:groupMode`, mode); } catch {}
|
try { localStorage.setItem(`shotStatus:${selectedProjectId}:groupMode`, mode); } catch {}
|
||||||
}
|
}
|
||||||
@@ -868,6 +1249,52 @@ export function ShotStatusClient({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBulkAssignArtist = async (artistId: string | null) => {
|
||||||
|
try {
|
||||||
|
const result = await bulkAssignArtist([...selectedIds], artistId);
|
||||||
|
toast({
|
||||||
|
title: result.artistName
|
||||||
|
? `${result.updated} shot${result.updated !== 1 ? "s" : ""} assigned to ${result.artistName}`
|
||||||
|
: `${result.updated} shot${result.updated !== 1 ? "s" : ""} unassigned`,
|
||||||
|
});
|
||||||
|
setAssignDialogOpen(false);
|
||||||
|
clearSelection();
|
||||||
|
router.refresh();
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: "Failed to assign artist",
|
||||||
|
description: e instanceof Error ? e.message : undefined,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleManualDelivery = async (
|
||||||
|
deliveredOn: string | null,
|
||||||
|
note: string,
|
||||||
|
evidence: { uploadUrl: string; sharedWith: string },
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const result = await bulkSetManualDelivery([...selectedIds], deliveredOn, note, evidence);
|
||||||
|
if (!result.success) {
|
||||||
|
// The dialog stays open so the missing link and recipient can be added.
|
||||||
|
toast({ title: "Not marked delivered", description: result.error, variant: "destructive" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const n =`${result.updated} shot${result.updated !== 1 ? "s" : ""}`;
|
||||||
|
toast({ title: deliveredOn ? `${n} marked delivered` : `Manual delivery cleared on ${n}` });
|
||||||
|
setManualDeliveryDialogOpen(false);
|
||||||
|
clearSelection();
|
||||||
|
router.refresh();
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: "Failed to update delivery",
|
||||||
|
description: e instanceof Error ? e.message : undefined,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleBulkDelete = async () => {
|
const handleBulkDelete = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await bulkDeleteShots([...selectedIds]);
|
const result = await bulkDeleteShots([...selectedIds]);
|
||||||
@@ -942,7 +1369,7 @@ export function ShotStatusClient({
|
|||||||
const selectionCount = selectedIds.size;
|
const selectionCount = selectedIds.size;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8 space-y-6 max-w-[1600px] mx-auto">
|
<div ref={pageRef} className="p-4 md:p-8 space-y-6 max-w-[1600px] mx-auto">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-3xl font-bold text-white">Shot Status</h1>
|
<h1 className="text-3xl font-bold text-white">Shot Status</h1>
|
||||||
@@ -950,10 +1377,12 @@ export function ShotStatusClient({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Project selector */}
|
{/* Project selector */}
|
||||||
<div className="flex items-center gap-3">
|
{/* Phones: the picker fills the row and "Group by" wraps onto its own
|
||||||
|
line. From md: one row, as on desktop. */}
|
||||||
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
<label className="text-sm text-zinc-400 shrink-0">Project:</label>
|
<label className="text-sm text-zinc-400 shrink-0">Project:</label>
|
||||||
<Select value={selectedProjectId ?? ""} onValueChange={handleProjectChange}>
|
<Select value={selectedProjectId ?? ""} onValueChange={handleProjectChange}>
|
||||||
<SelectTrigger className="w-72">
|
<SelectTrigger className="flex-1 min-w-0 md:flex-none md:w-72">
|
||||||
<SelectValue placeholder="Select a project..." />
|
<SelectValue placeholder="Select a project..." />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@@ -966,7 +1395,7 @@ export function ShotStatusClient({
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
{selectedProject && !isEpisodic && (
|
{selectedProject && !isEpisodic && (
|
||||||
<>
|
<div className="flex w-full md:w-auto items-center gap-3">
|
||||||
<span className="text-sm text-zinc-500">Group by:</span>
|
<span className="text-sm text-zinc-500">Group by:</span>
|
||||||
{(["flat", "scene", "group"] as const).map((mode) => (
|
{(["flat", "scene", "group"] as const).map((mode) => (
|
||||||
<button
|
<button
|
||||||
@@ -982,7 +1411,7 @@ export function ShotStatusClient({
|
|||||||
{mode === "flat" ? "None" : mode === "scene" ? "Scene" : "Group"}
|
{mode === "flat" ? "None" : mode === "scene" ? "Scene" : "Group"}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1040,10 +1469,22 @@ export function ShotStatusClient({
|
|||||||
<CalendarDays className="h-3.5 w-3.5 mr-2" />
|
<CalendarDays className="h-3.5 w-3.5 mr-2" />
|
||||||
Change Due Date
|
Change Due Date
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setAssignDialogOpen(true)}>
|
||||||
|
<UserPlus className="h-3.5 w-3.5 mr-2" />
|
||||||
|
Assign Artist
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setMovReviewDialogOpen(true)}>
|
<DropdownMenuItem onClick={() => setMovReviewDialogOpen(true)}>
|
||||||
<Clapperboard className="h-3.5 w-3.5 mr-2" />
|
<Clapperboard className="h-3.5 w-3.5 mr-2" />
|
||||||
Build MOV Review Package
|
Build MOV Review Package
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setRequestDialogOpen(true)}>
|
||||||
|
<ClipboardList className="h-3.5 w-3.5 mr-2" />
|
||||||
|
Log Delivery Request
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setManualDeliveryDialogOpen(true)}>
|
||||||
|
<PackageCheck className="h-3.5 w-3.5 mr-2" />
|
||||||
|
Delivered Outside Pipeline
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => setDeleteDialogOpen(true)}
|
onClick={() => setDeleteDialogOpen(true)}
|
||||||
@@ -1249,6 +1690,33 @@ export function ShotStatusClient({
|
|||||||
count={selectionCount}
|
count={selectionCount}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Bulk artist assignment dialog */}
|
||||||
|
<BulkAssignArtistDialog
|
||||||
|
open={assignDialogOpen}
|
||||||
|
onClose={() => setAssignDialogOpen(false)}
|
||||||
|
onApply={handleBulkAssignArtist}
|
||||||
|
artists={artists}
|
||||||
|
count={selectionCount}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Manual (pre-pipeline) delivery dialog */}
|
||||||
|
<ManualDeliveryDialog
|
||||||
|
open={manualDeliveryDialogOpen}
|
||||||
|
onClose={() => setManualDeliveryDialogOpen(false)}
|
||||||
|
onApply={handleManualDelivery}
|
||||||
|
count={selectionCount}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* A client asked for the selected shots */}
|
||||||
|
{selectedProjectId && (
|
||||||
|
<LogRequestDialog
|
||||||
|
open={requestDialogOpen}
|
||||||
|
onClose={() => setRequestDialogOpen(false)}
|
||||||
|
onLogged={clearSelection}
|
||||||
|
preset={{ projectId: selectedProjectId, shotIds: [...selectedIds] }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Bulk delete dialog */}
|
{/* Bulk delete dialog */}
|
||||||
<BulkDeleteDialog
|
<BulkDeleteDialog
|
||||||
open={deleteDialogOpen}
|
open={deleteDialogOpen}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { db } from "@/lib/db";
|
|||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { ShotStatusClient } from "./ShotStatusClient";
|
import { ShotStatusClient } from "./ShotStatusClient";
|
||||||
|
import { summariseShotDelivery } from "@/lib/render-pipeline/shot-delivery-summary";
|
||||||
|
|
||||||
async function getProjects() {
|
async function getProjects() {
|
||||||
return db.project.findMany({
|
return db.project.findMany({
|
||||||
@@ -19,8 +20,17 @@ async function getEpisodeDueDatesForProject(projectId: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Everyone a shot can be handed to — clients and deactivated accounts excluded. */
|
||||||
|
async function getAssignableArtists() {
|
||||||
|
return db.user.findMany({
|
||||||
|
where: { isActive: true, role: { not: "CLIENT" } },
|
||||||
|
select: { id: true, name: true, email: true, image: true },
|
||||||
|
orderBy: { name: "asc" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function getShotsForProject(projectId: string) {
|
async function getShotsForProject(projectId: string) {
|
||||||
return db.shot.findMany({
|
const shots = await db.shot.findMany({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{ episode: { sort: "asc", nulls: "last" } },
|
{ episode: { sort: "asc", nulls: "last" } },
|
||||||
@@ -42,13 +52,57 @@ async function getShotsForProject(projectId: string) {
|
|||||||
description: true,
|
description: true,
|
||||||
isKeyShot: true,
|
isKeyShot: true,
|
||||||
isScaled: true,
|
isScaled: true,
|
||||||
|
manualDeliveredAt: true,
|
||||||
|
manualDeliveryNote: true,
|
||||||
|
manualDeliverySharedWith: true,
|
||||||
// The shot-level version the panel burns into overlays and queueExport
|
// The shot-level version the panel burns into overlays and queueExport
|
||||||
// renders under — not the count of review Versions uploaded.
|
// renders under — not the count of review Versions uploaded.
|
||||||
shotVersion: true,
|
shotVersion: true,
|
||||||
artist: { select: { id: true, name: true, image: true, email: true } },
|
artist: { select: { id: true, name: true, image: true, email: true } },
|
||||||
shotGroup: { select: { id: true, name: true } },
|
shotGroup: { select: { id: true, name: true } },
|
||||||
|
// Every export, for the packages each went into; the newest live one
|
||||||
|
// is what is on its way.
|
||||||
|
exports: {
|
||||||
|
orderBy: [{ versionNumber: "desc" }, { createdAt: "desc" }],
|
||||||
|
select: {
|
||||||
|
versionString: true,
|
||||||
|
status: true,
|
||||||
|
deliveryItems: {
|
||||||
|
select: {
|
||||||
|
versionString: true,
|
||||||
|
package: {
|
||||||
|
select: {
|
||||||
|
kind: true,
|
||||||
|
status: true,
|
||||||
|
packageNumber: true,
|
||||||
|
createdAt: true,
|
||||||
|
builtAt: true,
|
||||||
|
uploadedAt: true,
|
||||||
|
deliveredAt: true,
|
||||||
|
sharedWith: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return shots.map(({ exports, ...shot }) => ({
|
||||||
|
...shot,
|
||||||
|
delivery: summariseShotDelivery({
|
||||||
|
packages: exports.flatMap((e) =>
|
||||||
|
e.deliveryItems.map((item) => ({ ...item.package, versionString: item.versionString }))
|
||||||
|
),
|
||||||
|
manual: {
|
||||||
|
deliveredAt: shot.manualDeliveredAt,
|
||||||
|
sharedWith: shot.manualDeliverySharedWith,
|
||||||
|
note: shot.manualDeliveryNote,
|
||||||
|
},
|
||||||
|
latestExport: exports.find((e) => e.status !== "CANCELLED" && e.status !== "ARCHIVED") ?? null,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function ShotStatusPage({
|
export default async function ShotStatusPage({
|
||||||
@@ -62,10 +116,11 @@ export default async function ShotStatusPage({
|
|||||||
const { projectId } = await searchParams;
|
const { projectId } = await searchParams;
|
||||||
const canManage = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
const canManage = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
||||||
|
|
||||||
const [projects, shots, episodeDueDates] = await Promise.all([
|
const [projects, shots, episodeDueDates, artists] = await Promise.all([
|
||||||
getProjects(),
|
getProjects(),
|
||||||
projectId ? getShotsForProject(projectId) : Promise.resolve([]),
|
projectId ? getShotsForProject(projectId) : Promise.resolve([]),
|
||||||
projectId ? getEpisodeDueDatesForProject(projectId) : Promise.resolve([]),
|
projectId ? getEpisodeDueDatesForProject(projectId) : Promise.resolve([]),
|
||||||
|
canManage ? getAssignableArtists() : Promise.resolve([]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const selectedProject = projects.find((p) => p.id === projectId) ?? null;
|
const selectedProject = projects.find((p) => p.id === projectId) ?? null;
|
||||||
@@ -77,6 +132,7 @@ export default async function ShotStatusPage({
|
|||||||
selectedProject={selectedProject}
|
selectedProject={selectedProject}
|
||||||
shots={shots as any}
|
shots={shots as any}
|
||||||
episodeDueDates={episodeDueDates}
|
episodeDueDates={episodeDueDates}
|
||||||
|
artists={artists}
|
||||||
canManage={canManage}
|
canManage={canManage}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export function TasksPageClient({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-5xl mx-auto space-y-6">
|
<div className="p-4 md:p-6 max-w-5xl mx-auto space-y-6">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export default async function UsersPage() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 max-w-5xl mx-auto space-y-6">
|
<div className="p-4 md:p-6 max-w-5xl mx-auto space-y-6">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div className="w-10 h-10 rounded-lg bg-amber-500/10 border border-amber-500/20 flex items-center justify-center shrink-0">
|
<div className="w-10 h-10 rounded-lg bg-amber-500/10 border border-amber-500/20 flex items-center justify-center shrink-0">
|
||||||
<Users className="h-5 w-5 text-amber-400" />
|
<Users className="h-5 w-5 text-amber-400" />
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { auth } from "@/auth";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { PLATE_EXTS, parsePlateFilename } from "@/lib/batch-upload-parser";
|
||||||
|
|
||||||
|
export type PlatePreviewItemStatus =
|
||||||
|
| "match" // shot found → a new footage plate will be added
|
||||||
|
| "duplicate" // the shot already has a plate with this exact filename
|
||||||
|
| "no-match" // no shot in this project matches the filename
|
||||||
|
| "unsupported"; // extension is not an accepted video format
|
||||||
|
|
||||||
|
export interface PlatePreviewItem {
|
||||||
|
fileName: string;
|
||||||
|
shotCode: string | null;
|
||||||
|
shotId: string | null;
|
||||||
|
/** Label the new plate will be created with */
|
||||||
|
label: string;
|
||||||
|
status: PlatePreviewItemStatus;
|
||||||
|
/** Number of plates the matched shot already has */
|
||||||
|
existingPlateCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/batch-upload/plates
|
||||||
|
* Body: { projectId: string; fileNames: string[] }
|
||||||
|
*
|
||||||
|
* Previews which shot each footage plate file will be attached to, derived
|
||||||
|
* from the filename. e.g. "DH2_VFX_058_120_REF.mov" → shot "DH2_VFX_058_120"
|
||||||
|
* with the label "REF". Nothing is uploaded.
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
|
||||||
|
let body: unknown;
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { projectId, fileNames } = body as { projectId?: unknown; fileNames?: unknown };
|
||||||
|
|
||||||
|
if (!projectId || typeof projectId !== "string" || !Array.isArray(fileNames)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "projectId and fileNames[] are required" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const shots = await db.shot.findMany({
|
||||||
|
where: { projectId },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
shotCode: true,
|
||||||
|
footagePlates: { select: { fileName: true } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const shotCodes = shots.map((s) => s.shotCode);
|
||||||
|
const shotByCode = new Map(shots.map((s) => [s.shotCode, s]));
|
||||||
|
|
||||||
|
// Several files in one batch can land on the same shot, so keep a running
|
||||||
|
// count per shot to number the "Plate N" fallback labels correctly.
|
||||||
|
const allocated = new Map<string, number>();
|
||||||
|
|
||||||
|
const items: PlatePreviewItem[] = fileNames.map((fileName: string) => {
|
||||||
|
const parsed = parsePlateFilename(fileName, shotCodes);
|
||||||
|
|
||||||
|
if (!PLATE_EXTS.has(parsed.ext)) {
|
||||||
|
return {
|
||||||
|
fileName,
|
||||||
|
shotCode: null,
|
||||||
|
shotId: null,
|
||||||
|
label: "",
|
||||||
|
status: "unsupported" as const,
|
||||||
|
existingPlateCount: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const shot = parsed.shotCode ? shotByCode.get(parsed.shotCode) ?? null : null;
|
||||||
|
if (!shot) {
|
||||||
|
return {
|
||||||
|
fileName,
|
||||||
|
shotCode: null,
|
||||||
|
shotId: null,
|
||||||
|
label: "",
|
||||||
|
status: "no-match" as const,
|
||||||
|
existingPlateCount: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingPlateCount = shot.footagePlates.length;
|
||||||
|
|
||||||
|
// Re-running a batch shouldn't silently pile up identical plates.
|
||||||
|
const isDuplicate = shot.footagePlates.some(
|
||||||
|
(p) => p.fileName.toLowerCase() === fileName.toLowerCase()
|
||||||
|
);
|
||||||
|
if (isDuplicate) {
|
||||||
|
return {
|
||||||
|
fileName,
|
||||||
|
shotCode: shot.shotCode,
|
||||||
|
shotId: shot.id,
|
||||||
|
label: parsed.label,
|
||||||
|
status: "duplicate" as const,
|
||||||
|
existingPlateCount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const takenSoFar = allocated.get(shot.id) ?? 0;
|
||||||
|
allocated.set(shot.id, takenSoFar + 1);
|
||||||
|
|
||||||
|
return {
|
||||||
|
fileName,
|
||||||
|
shotCode: shot.shotCode,
|
||||||
|
shotId: shot.id,
|
||||||
|
label: parsed.label || `Plate ${existingPlateCount + takenSoFar + 1}`,
|
||||||
|
status: "match" as const,
|
||||||
|
existingPlateCount,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({ items });
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { auth } from "@/auth";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
|
||||||
|
export const maxDuration = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/batch-upload/plates/upload
|
||||||
|
* Body: { projectId, shotId, key, fileName, fileSize?, label? }
|
||||||
|
*
|
||||||
|
* Commits a footage plate whose bytes were already uploaded straight to
|
||||||
|
* Hetzner via POST /api/upload/presign, so large .mov plates never pass
|
||||||
|
* through this server or the reverse proxy.
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||||
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
let body: unknown;
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { projectId, shotId, key, fileName, fileSize, label } = body as {
|
||||||
|
projectId?: unknown;
|
||||||
|
shotId?: unknown;
|
||||||
|
key?: unknown;
|
||||||
|
fileName?: unknown;
|
||||||
|
fileSize?: unknown;
|
||||||
|
label?: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof projectId !== "string" ||
|
||||||
|
typeof shotId !== "string" ||
|
||||||
|
typeof key !== "string" ||
|
||||||
|
typeof fileName !== "string" ||
|
||||||
|
!projectId ||
|
||||||
|
!shotId ||
|
||||||
|
!key ||
|
||||||
|
!fileName
|
||||||
|
) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "projectId, shotId, key and fileName are required" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The key must be one this app handed out via /api/upload/presign.
|
||||||
|
if (!key.startsWith("videos/")) {
|
||||||
|
return NextResponse.json({ error: "Invalid storage key" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const shot = await db.shot.findFirst({
|
||||||
|
where: { id: shotId, projectId },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
if (!shot) return NextResponse.json({ error: "Shot not found" }, { status: 404 });
|
||||||
|
|
||||||
|
const last = await db.footagePlate.findFirst({
|
||||||
|
where: { shotId },
|
||||||
|
orderBy: { sortOrder: "desc" },
|
||||||
|
select: { sortOrder: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const size = typeof fileSize === "number" && Number.isFinite(fileSize) && fileSize > 0
|
||||||
|
? BigInt(Math.round(fileSize))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const plate = await db.footagePlate.create({
|
||||||
|
data: {
|
||||||
|
shotId,
|
||||||
|
fileUrl: `/api/files/${key}`,
|
||||||
|
fileKey: key,
|
||||||
|
fileName,
|
||||||
|
fileSize: size,
|
||||||
|
label: typeof label === "string" ? label.trim().slice(0, 100) : "",
|
||||||
|
sortOrder: (last?.sortOrder ?? -1) + 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
revalidatePath(`/projects/${projectId}`);
|
||||||
|
revalidatePath(`/projects/${projectId}/shots/${shotId}`);
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
plateId: plate.id,
|
||||||
|
label: plate.label,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -48,6 +48,7 @@ export async function GET(
|
|||||||
clientCode: true,
|
clientCode: true,
|
||||||
episode: true,
|
episode: true,
|
||||||
sequence: true,
|
sequence: true,
|
||||||
|
scene: true,
|
||||||
description: true,
|
description: true,
|
||||||
status: true,
|
status: true,
|
||||||
shotApprovalStatus: true,
|
shotApprovalStatus: true,
|
||||||
@@ -124,9 +125,13 @@ export async function GET(
|
|||||||
// code by convention ("UNG_106_010_020_cmp_TT_v004"). The internal code is
|
// code by convention ("UNG_106_010_020_cmp_TT_v004"). The internal code is
|
||||||
// not sent at all — there is nothing here for it to be useful for, and
|
// not sent at all — there is nothing here for it to be useful for, and
|
||||||
// leaking it invites the client to quote it back at us.
|
// leaking it invites the client to quote it back at us.
|
||||||
shots: shots.map(({ generatedThumbnailUrl, clientCode, ...shot }) => ({
|
// The scene is our numbering too, and an alias does not have to share it
|
||||||
|
// (SNV's "SNV_101_0463_CP_VFX" is our scene 001), so an aliased shot goes
|
||||||
|
// out without one rather than with a number the client never used.
|
||||||
|
shots: shots.map(({ generatedThumbnailUrl, clientCode, scene, ...shot }) => ({
|
||||||
...shot,
|
...shot,
|
||||||
shotCode: clientShotCode({ ...shot, clientCode }),
|
shotCode: clientShotCode({ ...shot, clientCode }),
|
||||||
|
scene: clientShotCode({ ...shot, clientCode }) === shot.shotCode ? scene || null : null,
|
||||||
thumbnailUrl: shotThumbnail({ ...shot, generatedThumbnailUrl }),
|
thumbnailUrl: shotThumbnail({ ...shot, generatedThumbnailUrl }),
|
||||||
tasks: shot.tasks.map((task) => ({
|
tasks: shot.tasks.map((task) => ({
|
||||||
...task,
|
...task,
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { validateReviewToken } from "@/lib/review-auth";
|
||||||
|
import { generateHetznerDownloadUrl } from "@/lib/storage";
|
||||||
|
import { clientHighResFilename } from "@/lib/shot-code";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/client/[token]/versions/[versionId]/highres/download
|
||||||
|
* The version's ProRes, for a client reviewer: same visibility rule as the
|
||||||
|
* version itself (GET ../route.ts), and named with the client's shot code.
|
||||||
|
*/
|
||||||
|
export async function GET(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ token: string; versionId: string }> }
|
||||||
|
) {
|
||||||
|
const { token, versionId } = await params;
|
||||||
|
|
||||||
|
const result = await validateReviewToken(token, req);
|
||||||
|
if (result.type !== "ok") {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const version = await db.version.findUnique({
|
||||||
|
where: { id: versionId },
|
||||||
|
select: {
|
||||||
|
highResKey: true,
|
||||||
|
highResFilename: true,
|
||||||
|
isClientVisible: true,
|
||||||
|
shot: { select: { projectId: true, shotCode: true, clientCode: true } },
|
||||||
|
task: {
|
||||||
|
select: {
|
||||||
|
projectId: true,
|
||||||
|
shot: { select: { shotCode: true, clientCode: true } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const projectId = version?.shot?.projectId ?? version?.task?.projectId;
|
||||||
|
if (!version || projectId !== result.session.projectId) {
|
||||||
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
// Task-only versions need explicit sharing, as in the version route
|
||||||
|
if (!version.shot && !version.isClientVisible) {
|
||||||
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
if (!version.highResKey) {
|
||||||
|
return NextResponse.json({ error: "No high-res file available" }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const shot = version.shot ?? version.task?.shot ?? null;
|
||||||
|
const url = await generateHetznerDownloadUrl(
|
||||||
|
version.highResKey,
|
||||||
|
clientHighResFilename(version.highResFilename ?? "high-res.mov", shot)
|
||||||
|
);
|
||||||
|
return NextResponse.json({ url });
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { validateReviewToken, findReviewUser, ownsComment } from "@/lib/review-auth";
|
import { validateReviewToken, findReviewUser, ownsComment } from "@/lib/review-auth";
|
||||||
import { clientShotCode, clientTaskTitle } from "@/lib/shot-code";
|
import { clientHighResFilename, clientShotCode, clientTaskTitle } from "@/lib/shot-code";
|
||||||
|
|
||||||
/** GET /api/client/[token]/versions/[versionId] — returns version + comments for client portal */
|
/** GET /api/client/[token]/versions/[versionId] — returns version + comments for client portal */
|
||||||
export async function GET(
|
export async function GET(
|
||||||
@@ -95,13 +95,21 @@ export async function GET(
|
|||||||
// The shot the title and breadcrumb are drawn from — either relation.
|
// The shot the title and breadcrumb are drawn from — either relation.
|
||||||
const namingShot = version.shot ?? ((version.task as any)?.shot ?? null);
|
const namingShot = version.shot ?? ((version.task as any)?.shot ?? null);
|
||||||
|
|
||||||
|
// High Res: this version's own ProRes (uploaded by the render worker) wins;
|
||||||
|
// the shot's manually uploaded file is the fallback for older versions.
|
||||||
|
const versionHighRes = !!version.highResKey;
|
||||||
const serializedVersion = {
|
const serializedVersion = {
|
||||||
...version,
|
...version,
|
||||||
fileSize: version.fileSize?.toString() ?? null,
|
fileSize: version.fileSize?.toString() ?? null,
|
||||||
|
highResKey: undefined, // never expose a storage key
|
||||||
|
highResSize: version.highResSize?.toString() ?? null,
|
||||||
// Top-level high-res fields so the client works for both shot and task versions
|
// Top-level high-res fields so the client works for both shot and task versions
|
||||||
hasHighRes: !!(highResShot?.highResKey),
|
hasHighRes: versionHighRes || !!(highResShot?.highResKey),
|
||||||
highResShotId: highResShot?.highResKey ? (highResShot.id ?? null) : null,
|
highResSource: versionHighRes ? "version" : highResShot?.highResKey ? "shot" : null,
|
||||||
highResFilename: highResShot?.highResFilename ?? null,
|
highResShotId: !versionHighRes && highResShot?.highResKey ? (highResShot.id ?? null) : null,
|
||||||
|
highResFilename: versionHighRes
|
||||||
|
? clientHighResFilename(version.highResFilename ?? "high-res.mov", namingShot)
|
||||||
|
: highResShot?.highResFilename ?? null,
|
||||||
// Expose only whether a high-res file exists on the shot relation, never the storage key
|
// Expose only whether a high-res file exists on the shot relation, never the storage key
|
||||||
shot: version.shot
|
shot: version.shot
|
||||||
? {
|
? {
|
||||||
|
|||||||
@@ -2,20 +2,30 @@ import { NextRequest, NextResponse } from "next/server";
|
|||||||
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||||
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
||||||
import { markDelivered } from "@/lib/render-pipeline/deliveries";
|
import { markDelivered } from "@/lib/render-pipeline/deliveries";
|
||||||
|
import { recordShareSchema } from "@/lib/render-pipeline/delivery-handoff";
|
||||||
|
|
||||||
// ── POST /api/deliveries/{id}/delivered (E19) ────────────────────────────────
|
// ── POST /api/deliveries/{id}/delivered (E19) ────────────────────────────────
|
||||||
//
|
//
|
||||||
// The folder has been uploaded to the client. Moves every packaged export to
|
// The upload link has been sent to the client. Takes who it was sent to, and
|
||||||
// DELIVERED — the end of the pipeline.
|
// moves every packaged export to DELIVERED — the end of the pipeline.
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
_req: NextRequest,
|
req: NextRequest,
|
||||||
{ params }: { params: Promise<{ packageId: string }> }
|
{ params }: { params: Promise<{ packageId: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const user = await requirePipelineAdmin();
|
const user = await requirePipelineAdmin();
|
||||||
const { packageId } = await params;
|
const { packageId } = await params;
|
||||||
const result = await markDelivered(packageId, user.id);
|
|
||||||
|
const parsed = recordShareSchema.safeParse(await req.json().catch(() => null));
|
||||||
|
if (!parsed.success) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||||
|
{ status: 422 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await markDelivered(packageId, parsed.data, user.id);
|
||||||
return NextResponse.json(result);
|
return NextResponse.json(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const { body, status } = toErrorResponse(err);
|
const { body, status } = toErrorResponse(err);
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||||
|
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
||||||
|
import { markUploaded } from "@/lib/render-pipeline/deliveries";
|
||||||
|
import { recordUploadSchema } from "@/lib/render-pipeline/delivery-handoff";
|
||||||
|
|
||||||
|
// ── POST /api/deliveries/{id}/uploaded ───────────────────────────────────────
|
||||||
|
//
|
||||||
|
// The folder is on the client's portal. Records where, so the package shows as
|
||||||
|
// waiting to be shared rather than waiting to be uploaded.
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ packageId: string }> }
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const user = await requirePipelineAdmin();
|
||||||
|
const { packageId } = await params;
|
||||||
|
|
||||||
|
const parsed = recordUploadSchema.safeParse(await req.json().catch(() => null));
|
||||||
|
if (!parsed.success) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||||
|
{ status: 422 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await markUploaded(packageId, parsed.data, user.id);
|
||||||
|
return NextResponse.json(result);
|
||||||
|
} catch (err) {
|
||||||
|
const { body, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(body, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||||
|
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
||||||
|
import { cancelDeliveryRequest } from "@/lib/render-pipeline/delivery-requests";
|
||||||
|
import { cancelRequestSchema } from "@/lib/render-pipeline/delivery-request-state";
|
||||||
|
|
||||||
|
// ── POST /api/delivery-requests/{id}/cancel ──────────────────────────────────
|
||||||
|
//
|
||||||
|
// The only way a request leaves the awaiting list without being delivered, and
|
||||||
|
// it has to say why.
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ requestId: string }> }
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const user = await requirePipelineAdmin();
|
||||||
|
const { requestId } = await params;
|
||||||
|
|
||||||
|
const parsed = cancelRequestSchema.safeParse(await req.json().catch(() => null));
|
||||||
|
if (!parsed.success) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||||
|
{ status: 422 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await cancelDeliveryRequest(requestId, parsed.data.reason, user.id);
|
||||||
|
return NextResponse.json(result);
|
||||||
|
} catch (err) {
|
||||||
|
const { body, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(body, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||||
|
import { requirePipelineUser } from "@/lib/render-pipeline/session-auth";
|
||||||
|
import { getRequestOptions } from "@/lib/render-pipeline/delivery-requests";
|
||||||
|
|
||||||
|
// ── GET /api/delivery-requests/options?projectId= ────────────────────────────
|
||||||
|
//
|
||||||
|
// The episodes a request can be logged against.
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
await requirePipelineUser();
|
||||||
|
const projectId = new URL(req.url).searchParams.get("projectId");
|
||||||
|
if (!projectId) {
|
||||||
|
return NextResponse.json({ error: "projectId is required" }, { status: 400 });
|
||||||
|
}
|
||||||
|
return NextResponse.json(await getRequestOptions(projectId));
|
||||||
|
} catch (err) {
|
||||||
|
const { body, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(body, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||||
|
import { requirePipelineAdmin, requirePipelineUser } from "@/lib/render-pipeline/session-auth";
|
||||||
|
import { createDeliveryRequest, listDeliveryRequests } from "@/lib/render-pipeline/delivery-requests";
|
||||||
|
import { createRequestSchema } from "@/lib/render-pipeline/delivery-request-state";
|
||||||
|
|
||||||
|
// ── GET /api/delivery-requests · POST /api/delivery-requests ─────────────────
|
||||||
|
//
|
||||||
|
// What clients have asked for, and how much of each ask has gone out.
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
await requirePipelineUser();
|
||||||
|
const { searchParams } = new URL(req.url);
|
||||||
|
const requests = await listDeliveryRequests({
|
||||||
|
projectId: searchParams.get("projectId") ?? undefined,
|
||||||
|
openOnly: searchParams.get("open") === "1",
|
||||||
|
});
|
||||||
|
return NextResponse.json({ requests });
|
||||||
|
} catch (err) {
|
||||||
|
const { body, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(body, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const user = await requirePipelineAdmin();
|
||||||
|
|
||||||
|
const parsed = createRequestSchema.safeParse(await req.json().catch(() => null));
|
||||||
|
if (!parsed.success) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||||
|
{ status: 422 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await createDeliveryRequest(parsed.data, user.id);
|
||||||
|
return NextResponse.json(result, { status: 201 });
|
||||||
|
} catch (err) {
|
||||||
|
const { body, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(body, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth";
|
||||||
|
import { toErrorResponse, PipelineError } from "@/lib/render-pipeline/errors";
|
||||||
|
import { isArtifactKey } from "@/lib/render-pipeline/artifact-kinds";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { abortHetznerMultipartUpload, completeHetznerMultipartUpload } from "@/lib/storage";
|
||||||
|
|
||||||
|
// ── POST /api/ext/render/jobs/{jobId}/artifact-complete (E20b) ───────────────
|
||||||
|
//
|
||||||
|
// Closes a multipart upload started by artifact-presign: stitches the parts
|
||||||
|
// (by part number + ETag) into the final object, or with `abort: true` throws
|
||||||
|
// the stored parts away after the worker gave up.
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ jobId: string }> }
|
||||||
|
) {
|
||||||
|
if (!isExtAuthorized(req)) {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
const { jobId } = await params;
|
||||||
|
let body: {
|
||||||
|
machineId?: string;
|
||||||
|
key?: string;
|
||||||
|
uploadId?: string;
|
||||||
|
parts?: { partNumber?: number; etag?: string }[];
|
||||||
|
abort?: boolean;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (!body.machineId) throw new PipelineError(400, "machineId is required");
|
||||||
|
if (!body.key || !isArtifactKey(body.key)) throw new PipelineError(422, "key is not a worker artifact key");
|
||||||
|
if (!body.uploadId) throw new PipelineError(400, "uploadId is required");
|
||||||
|
|
||||||
|
const job = await db.renderJob.findUnique({ where: { id: jobId }, select: { machineId: true } });
|
||||||
|
if (!job) throw new PipelineError(404, "Render job not found");
|
||||||
|
if (job.machineId !== body.machineId) {
|
||||||
|
throw new PipelineError(409, "Job is not held by this machine (lease reassigned?)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body.abort) {
|
||||||
|
await abortHetznerMultipartUpload(body.key, body.uploadId);
|
||||||
|
return NextResponse.json({ ok: true, aborted: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = (body.parts ?? []).filter(
|
||||||
|
(p): p is { partNumber: number; etag: string } =>
|
||||||
|
typeof p.partNumber === "number" && typeof p.etag === "string" && p.etag.length > 0
|
||||||
|
);
|
||||||
|
if (parts.length === 0) throw new PipelineError(422, "parts are required");
|
||||||
|
|
||||||
|
await completeHetznerMultipartUpload(body.key, body.uploadId, parts);
|
||||||
|
return NextResponse.json({ ok: true, key: body.key, url: `/api/files/${body.key}` });
|
||||||
|
} catch (err) {
|
||||||
|
const { body: errBody, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(errBody, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,20 +3,29 @@ import { randomUUID } from "crypto";
|
|||||||
import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth";
|
import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth";
|
||||||
import { toErrorResponse, PipelineError } from "@/lib/render-pipeline/errors";
|
import { toErrorResponse, PipelineError } from "@/lib/render-pipeline/errors";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { generateHetznerPresignedUploadUrl, sanitizeFileName } from "@/lib/storage";
|
import { ARTIFACT_KIND_FOLDERS } from "@/lib/render-pipeline/artifact-kinds";
|
||||||
|
import {
|
||||||
|
createHetznerMultipartUpload,
|
||||||
|
generateHetznerPresignedUploadUrl,
|
||||||
|
sanitizeFileName,
|
||||||
|
} from "@/lib/storage";
|
||||||
|
|
||||||
// ── POST /api/ext/render/jobs/{jobId}/artifact-presign (E20) ─────────────────
|
// ── POST /api/ext/render/jobs/{jobId}/artifact-presign (E20) ─────────────────
|
||||||
//
|
//
|
||||||
// Presigned upload URL for worker artifacts. Kinds map to the existing object
|
// Presigned upload URL for worker artifacts. Kinds map to the existing object
|
||||||
// storage folder layout: preview → videos/, thumbnail → image/,
|
// storage folder layout: preview → videos/, thumbnail → image/,
|
||||||
// metadata/log → renders/.
|
// metadata/log → renders/, highres (the delivery MOV) → highres/ beside the
|
||||||
|
// manually uploaded High Res files.
|
||||||
|
//
|
||||||
|
// `multipart: true` + `size` (worker ≥ 1.7.2) returns an S3 multipart upload
|
||||||
|
// instead — an uploadId and one presigned URL per part — which the worker
|
||||||
|
// fills in parallel and closes with artifact-complete (E20b). A single PUT
|
||||||
|
// from the studio is capped near 0.1 MB/s; parallel parts scale with the
|
||||||
|
// number of connections. Older workers never ask and get the single PUT.
|
||||||
|
|
||||||
const KIND_FOLDERS: Record<string, string> = {
|
const KIND_FOLDERS = ARTIFACT_KIND_FOLDERS;
|
||||||
preview: "videos",
|
const MIN_PART = 8 * 1024 * 1024;
|
||||||
thumbnail: "image",
|
const MAX_PARTS = 10000; // S3 limit
|
||||||
metadata: "renders",
|
|
||||||
log: "renders",
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
@@ -26,7 +35,14 @@ export async function POST(
|
|||||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
const { jobId } = await params;
|
const { jobId } = await params;
|
||||||
let body: { machineId?: string; kind?: string; fileName?: string; contentType?: string };
|
let body: {
|
||||||
|
machineId?: string;
|
||||||
|
kind?: string;
|
||||||
|
fileName?: string;
|
||||||
|
contentType?: string;
|
||||||
|
multipart?: boolean;
|
||||||
|
size?: number;
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
body = await req.json();
|
body = await req.json();
|
||||||
} catch {
|
} catch {
|
||||||
@@ -48,6 +64,14 @@ export async function POST(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const key = `${folder}/${randomUUID()}-${sanitizeFileName(body.fileName)}`;
|
const key = `${folder}/${randomUUID()}-${sanitizeFileName(body.fileName)}`;
|
||||||
|
|
||||||
|
if (body.multipart && typeof body.size === "number" && body.size > MIN_PART) {
|
||||||
|
const partSize = Math.max(MIN_PART, Math.ceil(body.size / MAX_PARTS));
|
||||||
|
const partCount = Math.ceil(body.size / partSize);
|
||||||
|
const { uploadId, partUrls } = await createHetznerMultipartUpload(key, body.contentType, partCount);
|
||||||
|
return NextResponse.json({ key, url: `/api/files/${key}`, uploadId, partSize, partUrls });
|
||||||
|
}
|
||||||
|
|
||||||
const presignedUrl = await generateHetznerPresignedUploadUrl(key, body.contentType);
|
const presignedUrl = await generateHetznerPresignedUploadUrl(key, body.contentType);
|
||||||
return NextResponse.json({ presignedUrl, key, url: `/api/files/${key}` });
|
return NextResponse.json({ presignedUrl, key, url: `/api/files/${key}` });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth";
|
||||||
|
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||||
|
import { attachHighRes, type AttachHighResInput } from "@/lib/render-pipeline/preview";
|
||||||
|
|
||||||
|
// ── POST /api/ext/render/jobs/{jobId}/attach-highres (E13b) ──────────────────
|
||||||
|
//
|
||||||
|
// The preview's ProRes MOV, uploaded in the background after finalize (worker
|
||||||
|
// ≥ 1.7.1). Attaches it to the version as its High Res download, or records on
|
||||||
|
// the export timeline that the upload failed.
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ jobId: string }> }
|
||||||
|
) {
|
||||||
|
if (!isExtAuthorized(req)) {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
const { jobId } = await params;
|
||||||
|
|
||||||
|
let body: AttachHighResInput & { machineId?: string };
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
|
||||||
|
}
|
||||||
|
if (!body.machineId) {
|
||||||
|
return NextResponse.json({ error: "machineId is required" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await attachHighRes(jobId, body.machineId, body);
|
||||||
|
return NextResponse.json(result);
|
||||||
|
} catch (err) {
|
||||||
|
const { body: errBody, status } = toErrorResponse(err);
|
||||||
|
return NextResponse.json(errBody, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,12 @@ export async function GET(req: NextRequest) {
|
|||||||
thumbnailUrl: true,
|
thumbnailUrl: true,
|
||||||
posterUrl: true,
|
posterUrl: true,
|
||||||
fps: true,
|
fps: true,
|
||||||
|
duration: true,
|
||||||
|
frameCount: true,
|
||||||
|
hqFileUrl: true,
|
||||||
|
handleHead: true,
|
||||||
|
handleTail: true,
|
||||||
|
pictureStartFrame: true,
|
||||||
approvalStatus: true,
|
approvalStatus: true,
|
||||||
mimeType: true,
|
mimeType: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
@@ -85,6 +91,12 @@ export async function GET(req: NextRequest) {
|
|||||||
thumbnailUrl: latest.thumbnailUrl,
|
thumbnailUrl: latest.thumbnailUrl,
|
||||||
posterUrl: latest.posterUrl,
|
posterUrl: latest.posterUrl,
|
||||||
fps: latest.fps,
|
fps: latest.fps,
|
||||||
|
duration: latest.duration,
|
||||||
|
frameCount: latest.frameCount,
|
||||||
|
hqFileUrl: latest.hqFileUrl,
|
||||||
|
handleHead: latest.handleHead,
|
||||||
|
handleTail: latest.handleTail,
|
||||||
|
pictureStartFrame: latest.pictureStartFrame,
|
||||||
approvalStatus: latest.approvalStatus,
|
approvalStatus: latest.approvalStatus,
|
||||||
taskTitle: latest.taskTitle,
|
taskTitle: latest.taskTitle,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
import { getProjectPosters } from "@/lib/project-poster";
|
||||||
|
|
||||||
export async function GET(req: Request) {
|
export async function GET(req: Request) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
@@ -53,9 +54,13 @@ export async function GET(req: Request) {
|
|||||||
statsMap.set(row.projectId, existing);
|
statsMap.set(row.projectId, existing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// One still per project for the card art, chosen from the shots themselves.
|
||||||
|
const posters = await getProjectPosters(projects.map((p) => p.id));
|
||||||
|
|
||||||
const projectsWithStats = projects.map((p) => ({
|
const projectsWithStats = projects.map((p) => ({
|
||||||
...p,
|
...p,
|
||||||
shotStats: statsMap.get(p.id) ?? { total: 0, approved: 0, inProgress: 0 },
|
shotStats: statsMap.get(p.id) ?? { total: 0, approved: 0, inProgress: 0 },
|
||||||
|
poster: posters.get(p.id) ?? null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return NextResponse.json({ projects: projectsWithStats });
|
return NextResponse.json({ projects: projectsWithStats });
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { listExports } from "@/lib/render-pipeline/exports";
|
|||||||
// ── GET /api/render/queue (E21) ──────────────────────────────────────────────
|
// ── GET /api/render/queue (E21) ──────────────────────────────────────────────
|
||||||
//
|
//
|
||||||
// Exports list for the Render Queue page. Optional filters: projectId,
|
// Exports list for the Render Queue page. Optional filters: projectId,
|
||||||
// episode, status; standard pagination. Defaults to all statuses so the queue
|
// episode, status, q (shot/client code search); standard pagination. Defaults to all statuses so the queue
|
||||||
// page can show history too — the UI filters live states client-side.
|
// page can show history too — the UI filters live states client-side.
|
||||||
|
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
@@ -19,6 +19,7 @@ export async function GET(req: NextRequest) {
|
|||||||
projectId: searchParams.get("projectId") ?? undefined,
|
projectId: searchParams.get("projectId") ?? undefined,
|
||||||
episode: searchParams.get("episode") ?? undefined,
|
episode: searchParams.get("episode") ?? undefined,
|
||||||
shotId: searchParams.get("shotId") ?? undefined,
|
shotId: searchParams.get("shotId") ?? undefined,
|
||||||
|
search: searchParams.get("q")?.slice(0, 100) || undefined,
|
||||||
status:
|
status:
|
||||||
status && (Object.values(ExportStatus) as string[]).includes(status)
|
status && (Object.values(ExportStatus) as string[]).includes(status)
|
||||||
? (status as ExportStatus)
|
? (status as ExportStatus)
|
||||||
|
|||||||
@@ -73,6 +73,40 @@ export async function POST(req: NextRequest) {
|
|||||||
return NextResponse.json({ session: reviewSession, portalUrl }, { status: 201 });
|
return NextResponse.json({ session: reviewSession, portalUrl }, { status: 201 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reactivate a review link: push its expiry `expiresInDays` from now and turn
|
||||||
|
* it back on. The token is unchanged, so a URL the client already has works
|
||||||
|
* again rather than a new one having to be sent.
|
||||||
|
*/
|
||||||
|
export async function PATCH(req: NextRequest) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role as string)) {
|
||||||
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = req.nextUrl.searchParams.get("id");
|
||||||
|
if (!id) return NextResponse.json({ error: "id required" }, { status: 400 });
|
||||||
|
|
||||||
|
const body = await req.json().catch(() => ({}));
|
||||||
|
const expiresInDays = Number(body.expiresInDays ?? 30);
|
||||||
|
if (!Number.isInteger(expiresInDays) || expiresInDays < 1 || expiresInDays > 365) {
|
||||||
|
return NextResponse.json({ error: "expiresInDays must be 1–365" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await db.reviewSession.findUnique({ where: { id }, select: { id: true } });
|
||||||
|
if (!existing) return NextResponse.json({ error: "Review link not found" }, { status: 404 });
|
||||||
|
|
||||||
|
const reviewSession = await db.reviewSession.update({
|
||||||
|
where: { id },
|
||||||
|
data: { expiresAt: addDays(new Date(), expiresInDays), isActive: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({ session: reviewSession });
|
||||||
|
}
|
||||||
|
|
||||||
export async function DELETE(req: NextRequest) {
|
export async function DELETE(req: NextRequest) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ export async function GET(
|
|||||||
session.user.role as string
|
session.user.role as string
|
||||||
);
|
);
|
||||||
|
|
||||||
// Serialize BigInt fields (fileSize) so JSON.stringify doesn't throw
|
// Serialize BigInt fields (fileSize, highResSize) so JSON.stringify doesn't throw
|
||||||
const shotSerialized = {
|
const shotSerialized = {
|
||||||
...shot,
|
...shot,
|
||||||
footagePlates: shot.footagePlates.map((p) => ({
|
footagePlates: shot.footagePlates.map((p) => ({
|
||||||
@@ -92,6 +92,7 @@ export async function GET(
|
|||||||
versions: shot.versions.map((v) => ({
|
versions: shot.versions.map((v) => ({
|
||||||
...v,
|
...v,
|
||||||
fileSize: v.fileSize != null ? v.fileSize.toString() : null,
|
fileSize: v.fileSize != null ? v.fileSize.toString() : null,
|
||||||
|
highResSize: v.highResSize != null ? v.highResSize.toString() : null,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { auth } from "@/auth";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { generateHetznerDownloadUrl } from "@/lib/storage";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/versions/[versionId]/highres/download — short-lived presigned URL
|
||||||
|
* for this version's ProRes (the delivery MOV the render worker uploaded).
|
||||||
|
*/
|
||||||
|
export async function GET(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ versionId: string }> }
|
||||||
|
) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user) {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { versionId } = await params;
|
||||||
|
const version = await db.version.findUnique({
|
||||||
|
where: { id: versionId },
|
||||||
|
select: { highResKey: true, highResFilename: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!version?.highResKey) {
|
||||||
|
return NextResponse.json({ error: "No high-res file available" }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = await generateHetznerDownloadUrl(
|
||||||
|
version.highResKey,
|
||||||
|
version.highResFilename ?? "high-res.mov"
|
||||||
|
);
|
||||||
|
return NextResponse.json({ url });
|
||||||
|
}
|
||||||
+238
-153
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useRef, useEffect } from 'react';
|
||||||
|
import { useScrollMemory } from '@/hooks/use-scroll-memory';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import {
|
import {
|
||||||
@@ -18,6 +19,7 @@ import {
|
|||||||
Check,
|
Check,
|
||||||
Search,
|
Search,
|
||||||
X,
|
X,
|
||||||
|
Layers,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { Montserrat } from 'next/font/google';
|
import { Montserrat } from 'next/font/google';
|
||||||
@@ -51,6 +53,7 @@ interface ClientShot {
|
|||||||
shotCode: string;
|
shotCode: string;
|
||||||
episode: string | null;
|
episode: string | null;
|
||||||
sequence: string | null;
|
sequence: string | null;
|
||||||
|
scene: string | null;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
status: string;
|
status: string;
|
||||||
thumbnailUrl: string | null;
|
thumbnailUrl: string | null;
|
||||||
@@ -127,7 +130,6 @@ const TASK_TYPE_LABELS: Record<string, string> = {
|
|||||||
GENERAL: 'Task',
|
GENERAL: 'Task',
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCROLL_KEY = 'client-portal-scroll';
|
|
||||||
const QUEUE_KEY = 'client-portal-queue';
|
const QUEUE_KEY = 'client-portal-queue';
|
||||||
const STATE_KEY = 'client-portal-state';
|
const STATE_KEY = 'client-portal-state';
|
||||||
const PREFS_KEY_PREFIX = 'client-portal-prefs-';
|
const PREFS_KEY_PREFIX = 'client-portal-prefs-';
|
||||||
@@ -136,6 +138,26 @@ function getLatestVersion(task: ClientTask): ClientVersion | undefined {
|
|||||||
return task.versions[0];
|
return task.versions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NO_SCENE = '__none__';
|
||||||
|
|
||||||
|
/** Shots split into scenes in scene order, with unscened shots last. */
|
||||||
|
function groupShotsByScene<T extends ClientShot>(shots: T[]): [string, T[]][] {
|
||||||
|
const map = new Map<string, T[]>();
|
||||||
|
for (const shot of shots) {
|
||||||
|
const key = shot.scene || NO_SCENE;
|
||||||
|
if (!map.has(key)) map.set(key, []);
|
||||||
|
map.get(key)!.push(shot);
|
||||||
|
}
|
||||||
|
return Array.from(map.entries()).sort(([a], [b]) => {
|
||||||
|
if (a === NO_SCENE) return 1;
|
||||||
|
if (b === NO_SCENE) return -1;
|
||||||
|
return a.localeCompare(b, undefined, { numeric: true });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Collapse key for a scene, kept in the same set as the episodes. */
|
||||||
|
const sceneKey = (episode: string, scene: string) => `${episode}::${scene}`;
|
||||||
|
|
||||||
export default function ClientPortalPage({
|
export default function ClientPortalPage({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
@@ -152,8 +174,14 @@ export default function ClientPortalPage({
|
|||||||
const [collapsedEpisodes, setCollapsedEpisodes] = useState<Set<string>>(new Set());
|
const [collapsedEpisodes, setCollapsedEpisodes] = useState<Set<string>>(new Set());
|
||||||
const [statusFilter, setStatusFilter] = useState<string | null>(null);
|
const [statusFilter, setStatusFilter] = useState<string | null>(null);
|
||||||
const [sortMode, setSortMode] = useState<'episode' | 'recent'>('episode');
|
const [sortMode, setSortMode] = useState<'episode' | 'recent'>('episode');
|
||||||
|
const [groupByScene, setGroupByScene] = useState(false);
|
||||||
const [searchQuery, setSearchQuery] = useState<string>('');
|
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||||
const [episodeFilter, setEpisodeFilter] = useState<string | null>(null);
|
const [episodeFilter, setEpisodeFilter] = useState<string | null>(null);
|
||||||
|
// Filters and collapsed episodes set the page height, so the scroll
|
||||||
|
// position is restored only once they are back.
|
||||||
|
const [viewRestored, setViewRestored] = useState(false);
|
||||||
|
const pageRef = useRef<HTMLDivElement>(null);
|
||||||
|
useScrollMemory(token ? `clientPortal:${token}` : null, pageRef, viewRestored);
|
||||||
|
|
||||||
const toggleEpisode = (ep: string) => {
|
const toggleEpisode = (ep: string) => {
|
||||||
setCollapsedEpisodes((prev) => {
|
setCollapsedEpisodes((prev) => {
|
||||||
@@ -189,9 +217,10 @@ export default function ClientPortalPage({
|
|||||||
if (savedState) {
|
if (savedState) {
|
||||||
sessionStorage.removeItem(STATE_KEY);
|
sessionStorage.removeItem(STATE_KEY);
|
||||||
try {
|
try {
|
||||||
const { statusFilter: sf, sortMode: sm, searchQuery: sq, episodeFilter: ef, collapsedEpisodes: ce } = JSON.parse(savedState);
|
const { statusFilter: sf, sortMode: sm, groupByScene: gs, searchQuery: sq, episodeFilter: ef, collapsedEpisodes: ce } = JSON.parse(savedState);
|
||||||
if (sf !== undefined) setStatusFilter(sf);
|
if (sf !== undefined) setStatusFilter(sf);
|
||||||
if (sm !== undefined) setSortMode(sm);
|
if (sm !== undefined) setSortMode(sm);
|
||||||
|
if (gs !== undefined) setGroupByScene(gs);
|
||||||
if (sq !== undefined) setSearchQuery(sq ?? '');
|
if (sq !== undefined) setSearchQuery(sq ?? '');
|
||||||
if (ef !== undefined) setEpisodeFilter(ef);
|
if (ef !== undefined) setEpisodeFilter(ef);
|
||||||
if (ce !== undefined) setCollapsedEpisodes(new Set(ce));
|
if (ce !== undefined) setCollapsedEpisodes(new Set(ce));
|
||||||
@@ -200,22 +229,17 @@ export default function ClientPortalPage({
|
|||||||
try {
|
try {
|
||||||
const prefs = localStorage.getItem(PREFS_KEY_PREFIX + token);
|
const prefs = localStorage.getItem(PREFS_KEY_PREFIX + token);
|
||||||
if (prefs) {
|
if (prefs) {
|
||||||
const { statusFilter: sf, sortMode: sm, searchQuery: sq, episodeFilter: ef, collapsedEpisodes: ce } = JSON.parse(prefs);
|
const { statusFilter: sf, sortMode: sm, groupByScene: gs, searchQuery: sq, episodeFilter: ef, collapsedEpisodes: ce } = JSON.parse(prefs);
|
||||||
if (sf !== undefined) setStatusFilter(sf);
|
if (sf !== undefined) setStatusFilter(sf);
|
||||||
if (sm !== undefined) setSortMode(sm);
|
if (sm !== undefined) setSortMode(sm);
|
||||||
|
if (gs !== undefined) setGroupByScene(gs);
|
||||||
if (sq !== undefined) setSearchQuery(sq ?? '');
|
if (sq !== undefined) setSearchQuery(sq ?? '');
|
||||||
if (ef !== undefined) setEpisodeFilter(ef);
|
if (ef !== undefined) setEpisodeFilter(ef);
|
||||||
if (ce !== undefined) setCollapsedEpisodes(new Set(ce));
|
if (ce !== undefined) setCollapsedEpisodes(new Set(ce));
|
||||||
}
|
}
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
}
|
}
|
||||||
const saved = sessionStorage.getItem(SCROLL_KEY);
|
setViewRestored(true);
|
||||||
if (saved) {
|
|
||||||
sessionStorage.removeItem(SCROLL_KEY);
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
window.scrollTo(0, parseInt(saved, 10));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [loading, token]);
|
}, [loading, token]);
|
||||||
|
|
||||||
@@ -227,13 +251,14 @@ export default function ClientPortalPage({
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
statusFilter,
|
statusFilter,
|
||||||
sortMode,
|
sortMode,
|
||||||
|
groupByScene,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
episodeFilter,
|
episodeFilter,
|
||||||
collapsedEpisodes: Array.from(collapsedEpisodes),
|
collapsedEpisodes: Array.from(collapsedEpisodes),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
}, [token, statusFilter, sortMode, searchQuery, episodeFilter, collapsedEpisodes, loading]);
|
}, [token, statusFilter, sortMode, groupByScene, searchQuery, episodeFilter, collapsedEpisodes, loading]);
|
||||||
|
|
||||||
const loadProject = (t: string) => {
|
const loadProject = (t: string) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -310,6 +335,8 @@ export default function ClientPortalPage({
|
|||||||
|
|
||||||
// Group shots by episode; null episode → "Shots"
|
// Group shots by episode; null episode → "Shots"
|
||||||
const isEpisodic = shots.some((s) => s.episode != null);
|
const isEpisodic = shots.some((s) => s.episode != null);
|
||||||
|
const hasScenes = shots.some((s) => s.scene);
|
||||||
|
const showScenes = groupByScene && hasScenes;
|
||||||
const shotsByEpisode = shots.reduce<Record<string, ClientShot[]>>(
|
const shotsByEpisode = shots.reduce<Record<string, ClientShot[]>>(
|
||||||
(acc, shot) => {
|
(acc, shot) => {
|
||||||
const key = shot.episode ?? 'Shots';
|
const key = shot.episode ?? 'Shots';
|
||||||
@@ -410,10 +437,11 @@ export default function ClientPortalPage({
|
|||||||
Object.entries(shotsByEpisode)
|
Object.entries(shotsByEpisode)
|
||||||
.filter(([episode]) => episodeFilter === null || episodeFilter === episode)
|
.filter(([episode]) => episodeFilter === null || episodeFilter === episode)
|
||||||
.forEach(([, epShots]) => {
|
.forEach(([, epShots]) => {
|
||||||
epShots
|
const visible = epShots
|
||||||
.map((shot) => ({ ...shot, tasks: shot.tasks.filter(taskMatchesFilter) }))
|
.map((shot) => ({ ...shot, tasks: shot.tasks.filter(taskMatchesFilter) }))
|
||||||
.filter((shot) => shot.tasks.length > 0)
|
.filter((shot) => shot.tasks.length > 0)
|
||||||
.filter(shotMatchesSearch)
|
.filter(shotMatchesSearch);
|
||||||
|
(showScenes ? groupShotsByScene(visible).flatMap(([, sc]) => sc) : visible)
|
||||||
.forEach((shot) => {
|
.forEach((shot) => {
|
||||||
shot.tasks.forEach((task) => {
|
shot.tasks.forEach((task) => {
|
||||||
const ver = getLatestVersion(task);
|
const ver = getLatestVersion(task);
|
||||||
@@ -429,13 +457,13 @@ export default function ClientPortalPage({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleReviewClick = () => {
|
const handleReviewClick = () => {
|
||||||
sessionStorage.setItem(SCROLL_KEY, String(window.scrollY));
|
|
||||||
sessionStorage.setItem(QUEUE_KEY, JSON.stringify(getReviewQueue()));
|
sessionStorage.setItem(QUEUE_KEY, JSON.stringify(getReviewQueue()));
|
||||||
sessionStorage.setItem(
|
sessionStorage.setItem(
|
||||||
STATE_KEY,
|
STATE_KEY,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
statusFilter,
|
statusFilter,
|
||||||
sortMode,
|
sortMode,
|
||||||
|
groupByScene,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
episodeFilter,
|
episodeFilter,
|
||||||
collapsedEpisodes: Array.from(collapsedEpisodes),
|
collapsedEpisodes: Array.from(collapsedEpisodes),
|
||||||
@@ -443,8 +471,149 @@ export default function ClientPortalPage({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Approved / needs changes / awaiting counts for an episode or scene header.
|
||||||
|
const statusPills = (tasks: ClientTask[]) => {
|
||||||
|
const nApproved = tasks.filter(
|
||||||
|
(t) => getLatestVersion(t)?.approvalStatus === 'APPROVED',
|
||||||
|
).length;
|
||||||
|
const nChanges = tasks.filter((t) =>
|
||||||
|
['REJECTED', 'NEEDS_CHANGES'].includes(
|
||||||
|
getLatestVersion(t)?.approvalStatus ?? '',
|
||||||
|
),
|
||||||
|
).length;
|
||||||
|
const nPending = tasks.length - nApproved - nChanges;
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-zinc-950 text-white">
|
<div className="flex items-center gap-2 shrink-0">
|
||||||
|
{nApproved > 0 && (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-900/40 border border-emerald-800/40 text-emerald-400 text-xs">
|
||||||
|
<CheckCircle2 className="h-3 w-3" />
|
||||||
|
{nApproved}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{nChanges > 0 && (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-red-900/30 border border-red-800/30 text-red-400 text-xs">
|
||||||
|
<AlertCircle className="h-3 w-3" />
|
||||||
|
{nChanges}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{nPending > 0 && (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-amber-900/20 border border-amber-800/20 text-amber-400 text-xs">
|
||||||
|
<Clock className="h-3 w-3" />
|
||||||
|
{nPending}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderShot = (shot: ClientShot) => (
|
||||||
|
<div key={shot.id} className="px-5 py-4 space-y-2">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{shot.thumbnailUrl && (
|
||||||
|
<div className="relative flex-shrink-0 w-32 aspect-[2.39] rounded overflow-hidden border border-zinc-800">
|
||||||
|
<Image
|
||||||
|
src={shot.thumbnailUrl}
|
||||||
|
alt={shot.shotCode}
|
||||||
|
fill
|
||||||
|
className="object-cover"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex items-center gap-1.5 group/shotcode">
|
||||||
|
<p className="font-mono text-sm font-semibold text-zinc-300">
|
||||||
|
{shot.shotCode}
|
||||||
|
{shot.description && (
|
||||||
|
<span className="font-sans font-normal text-zinc-500 ml-2">
|
||||||
|
{shot.description}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={() => copyToClipboard(shot.shotCode, `shot-${shot.id}`)}
|
||||||
|
className="shrink-0 p-0.5 rounded opacity-0 group-hover/shotcode:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
||||||
|
title="Copy shot code"
|
||||||
|
>
|
||||||
|
{copiedId === `shot-${shot.id}` ? (
|
||||||
|
<Check className="h-3 w-3 text-emerald-400" />
|
||||||
|
) : (
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1.5 pl-3 border-l border-zinc-800">
|
||||||
|
{shot.tasks.map((task) => {
|
||||||
|
const ver = getLatestVersion(task);
|
||||||
|
const approvalKey =
|
||||||
|
ver?.approvalStatus ?? 'PENDING_REVIEW';
|
||||||
|
const approval =
|
||||||
|
APPROVAL_STYLES[approvalKey] ??
|
||||||
|
APPROVAL_STYLES.PENDING_REVIEW;
|
||||||
|
const ApprovalIcon = approval.Icon;
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={task.id}
|
||||||
|
href={ver ? `/client/${token}/review/${ver.id}` : '#'}
|
||||||
|
onClick={handleReviewClick}
|
||||||
|
className={cn(
|
||||||
|
'flex flex-wrap sm:flex-nowrap items-center gap-x-4 gap-y-2 p-3 sm:p-4 rounded-xl border transition-all group',
|
||||||
|
'bg-zinc-900 border-zinc-800 hover:border-zinc-600 hover:bg-zinc-800/70',
|
||||||
|
!ver && 'pointer-events-none opacity-40',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="min-w-0 w-full sm:w-auto sm:flex-1">
|
||||||
|
<div className="flex items-center gap-1.5">
|
||||||
|
<p className="text-sm font-medium text-white min-w-0 break-words">
|
||||||
|
{task.title}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={(e) => { e.preventDefault(); e.stopPropagation(); copyToClipboard(task.title, `task-${task.id}`); }}
|
||||||
|
className="hidden sm:block shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
||||||
|
title="Copy task name"
|
||||||
|
>
|
||||||
|
{copiedId === `task-${task.id}` ? (
|
||||||
|
<Check className="h-3 w-3 text-emerald-400" />
|
||||||
|
) : (
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-zinc-500">
|
||||||
|
{TASK_TYPE_LABELS[task.type] ?? task.type}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{ver ? (
|
||||||
|
<div className="flex items-center gap-3 shrink-0">
|
||||||
|
{ver.createdAt && (
|
||||||
|
<span className="text-xs text-zinc-600 hidden sm:block">
|
||||||
|
{formatDate(ver.createdAt)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full border text-xs font-medium',
|
||||||
|
approval.className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ApprovalIcon className="h-3 w-3" />
|
||||||
|
{approval.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<span className="text-xs text-zinc-600 shrink-0">
|
||||||
|
No versions yet
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<ChevronRight className="h-4 w-4 text-zinc-600 group-hover:text-zinc-400 shrink-0 transition-colors ml-auto sm:ml-0" />
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={pageRef} className="min-h-screen bg-zinc-950 text-white">
|
||||||
<header className="border-b border-zinc-800 bg-zinc-900">
|
<header className="border-b border-zinc-800 bg-zinc-900">
|
||||||
<div className="max-w-5xl mx-auto px-6 py-4 flex items-center justify-between">
|
<div className="max-w-5xl mx-auto px-6 py-4 flex items-center justify-between">
|
||||||
{/* Logo */}
|
{/* Logo */}
|
||||||
@@ -454,7 +623,7 @@ export default function ClientPortalPage({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={montserrat.className}>
|
<div className={montserrat.className}>
|
||||||
<span className="block text-2xl font-light text-white leading-none">
|
<span className="block text-2xl font-light text-white leading-none whitespace-nowrap">
|
||||||
TWO TALES
|
TWO TALES
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -464,7 +633,7 @@ export default function ClientPortalPage({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{sessionLabel && (
|
{sessionLabel && (
|
||||||
<span className="text-sm text-zinc-400">{sessionLabel}</span>
|
<span className="ml-4 min-w-0 truncate text-right text-sm text-zinc-400" title={sessionLabel}>{sessionLabel}</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -620,6 +789,20 @@ export default function ClientPortalPage({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
|
{hasScenes && sortMode === 'episode' && (
|
||||||
|
<button
|
||||||
|
onClick={() => setGroupByScene((prev) => !prev)}
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-all',
|
||||||
|
groupByScene
|
||||||
|
? 'bg-amber-500/10 border-amber-500/30 text-amber-400'
|
||||||
|
: 'bg-zinc-800 border-zinc-700 text-zinc-400 hover:text-zinc-300',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Layers className="h-3 w-3" />
|
||||||
|
{groupByScene ? 'Grouped by Scene' : 'Group by Scene'}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setSortMode((prev) => (prev === 'episode' ? 'recent' : 'episode'))
|
setSortMode((prev) => (prev === 'episode' ? 'recent' : 'episode'))
|
||||||
@@ -687,7 +870,7 @@ export default function ClientPortalPage({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex items-center gap-1.5 group/itemlabel">
|
<div className="flex min-w-0 items-center gap-1.5 group/itemlabel">
|
||||||
<p className="font-mono text-xs text-zinc-500">
|
<p className="font-mono text-xs text-zinc-500">
|
||||||
{item.label}
|
{item.label}
|
||||||
{item.description && (
|
{item.description && (
|
||||||
@@ -698,7 +881,7 @@ export default function ClientPortalPage({
|
|||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => copyToClipboard(item.label, `label-${task.id}`)}
|
onClick={() => copyToClipboard(item.label, `label-${task.id}`)}
|
||||||
className="shrink-0 p-0.5 rounded opacity-0 group-hover/itemlabel:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
className="hidden sm:block shrink-0 p-0.5 rounded opacity-0 group-hover/itemlabel:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
||||||
title="Copy name"
|
title="Copy name"
|
||||||
>
|
>
|
||||||
{copiedId === `label-${task.id}` ? (
|
{copiedId === `label-${task.id}` ? (
|
||||||
@@ -709,7 +892,7 @@ export default function ClientPortalPage({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{ver?.createdAt && (
|
{ver?.createdAt && (
|
||||||
<p className="ml-auto text-xs text-zinc-600">
|
<p className="ml-auto shrink-0 whitespace-nowrap text-xs text-zinc-600">
|
||||||
{formatDate(ver.createdAt)}
|
{formatDate(ver.createdAt)}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -718,19 +901,19 @@ export default function ClientPortalPage({
|
|||||||
href={ver ? `/client/${token}/review/${ver.id}` : '#'}
|
href={ver ? `/client/${token}/review/${ver.id}` : '#'}
|
||||||
onClick={handleReviewClick}
|
onClick={handleReviewClick}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-center gap-4 p-4 rounded-xl border transition-all group',
|
'flex flex-wrap sm:flex-nowrap items-center gap-x-4 gap-y-2 p-3 sm:p-4 rounded-xl border transition-all group',
|
||||||
'bg-zinc-900 border-zinc-800 hover:border-zinc-600 hover:bg-zinc-800/70',
|
'bg-zinc-900 border-zinc-800 hover:border-zinc-600 hover:bg-zinc-800/70',
|
||||||
!ver && 'pointer-events-none opacity-40',
|
!ver && 'pointer-events-none opacity-40',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="min-w-0 w-full sm:w-auto sm:flex-1">
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<p className="text-sm font-medium text-white">
|
<p className="text-sm font-medium text-white min-w-0 break-words">
|
||||||
{task.title}
|
{task.title}
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); copyToClipboard(task.title, `task-${task.id}`); }}
|
onClick={(e) => { e.preventDefault(); e.stopPropagation(); copyToClipboard(task.title, `task-${task.id}`); }}
|
||||||
className="shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
className="hidden sm:block shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
||||||
title="Copy task name"
|
title="Copy task name"
|
||||||
>
|
>
|
||||||
{copiedId === `task-${task.id}` ? (
|
{copiedId === `task-${task.id}` ? (
|
||||||
@@ -759,7 +942,7 @@ export default function ClientPortalPage({
|
|||||||
No versions yet
|
No versions yet
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<ChevronRight className="h-4 w-4 text-zinc-600 group-hover:text-zinc-400 shrink-0 transition-colors" />
|
<ChevronRight className="h-4 w-4 text-zinc-600 group-hover:text-zinc-400 shrink-0 transition-colors ml-auto sm:ml-0" />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -780,15 +963,6 @@ export default function ClientPortalPage({
|
|||||||
|
|
||||||
const isCollapsed = collapsedEpisodes.has(episode);
|
const isCollapsed = collapsedEpisodes.has(episode);
|
||||||
const epTasks = filteredEpShots.flatMap((s) => s.tasks);
|
const epTasks = filteredEpShots.flatMap((s) => s.tasks);
|
||||||
const epApproved = epTasks.filter(
|
|
||||||
(t) => getLatestVersion(t)?.approvalStatus === 'APPROVED',
|
|
||||||
).length;
|
|
||||||
const epChanges = epTasks.filter((t) =>
|
|
||||||
['REJECTED', 'NEEDS_CHANGES'].includes(
|
|
||||||
getLatestVersion(t)?.approvalStatus ?? '',
|
|
||||||
),
|
|
||||||
).length;
|
|
||||||
const epPending = epTasks.length - epApproved - epChanges;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={episode} className="rounded-xl border border-zinc-800 overflow-hidden">
|
<div key={episode} className="rounded-xl border border-zinc-800 overflow-hidden">
|
||||||
@@ -812,137 +986,48 @@ export default function ClientPortalPage({
|
|||||||
{filteredEpShots.length === 1 ? 'shot' : 'shots'}
|
{filteredEpShots.length === 1 ? 'shot' : 'shots'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{/* Per-episode progress pills */}
|
{statusPills(epTasks)}
|
||||||
<div className="flex items-center gap-2 shrink-0">
|
|
||||||
{epApproved > 0 && (
|
|
||||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-900/40 border border-emerald-800/40 text-emerald-400 text-xs">
|
|
||||||
<CheckCircle2 className="h-3 w-3" />
|
|
||||||
{epApproved}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{epChanges > 0 && (
|
|
||||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-red-900/30 border border-red-800/30 text-red-400 text-xs">
|
|
||||||
<AlertCircle className="h-3 w-3" />
|
|
||||||
{epChanges}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{epPending > 0 && (
|
|
||||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-amber-900/20 border border-amber-800/20 text-amber-400 text-xs">
|
|
||||||
<Clock className="h-3 w-3" />
|
|
||||||
{epPending}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Collapsible shot list */}
|
{/* Collapsible shot list */}
|
||||||
{!isCollapsed && (
|
{!isCollapsed && (
|
||||||
<div className="divide-y divide-zinc-800/60 bg-zinc-950/40">
|
<div className="divide-y divide-zinc-800/60 bg-zinc-950/40">
|
||||||
{filteredEpShots.map((shot) => (
|
{showScenes
|
||||||
<div key={shot.id} className="px-5 py-4 space-y-2">
|
? groupShotsByScene(filteredEpShots).map(([scene, sceneShots]) => {
|
||||||
<div className="flex items-center gap-3">
|
const key = sceneKey(episode, scene);
|
||||||
{shot.thumbnailUrl && (
|
const sceneCollapsed = collapsedEpisodes.has(key);
|
||||||
<div className="relative flex-shrink-0 w-32 aspect-[2.39] rounded overflow-hidden border border-zinc-800">
|
|
||||||
<Image
|
|
||||||
src={shot.thumbnailUrl}
|
|
||||||
alt={shot.shotCode}
|
|
||||||
fill
|
|
||||||
className="object-cover"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="flex items-center gap-1.5 group/shotcode">
|
|
||||||
<p className="font-mono text-sm font-semibold text-zinc-300">
|
|
||||||
{shot.shotCode}
|
|
||||||
{shot.description && (
|
|
||||||
<span className="font-sans font-normal text-zinc-500 ml-2">
|
|
||||||
{shot.description}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
<button
|
|
||||||
onClick={() => copyToClipboard(shot.shotCode, `shot-${shot.id}`)}
|
|
||||||
className="shrink-0 p-0.5 rounded opacity-0 group-hover/shotcode:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
|
||||||
title="Copy shot code"
|
|
||||||
>
|
|
||||||
{copiedId === `shot-${shot.id}` ? (
|
|
||||||
<Check className="h-3 w-3 text-emerald-400" />
|
|
||||||
) : (
|
|
||||||
<Copy className="h-3 w-3" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1.5 pl-3 border-l border-zinc-800">
|
|
||||||
{shot.tasks.map((task) => {
|
|
||||||
const ver = getLatestVersion(task);
|
|
||||||
const approvalKey =
|
|
||||||
ver?.approvalStatus ?? 'PENDING_REVIEW';
|
|
||||||
const approval =
|
|
||||||
APPROVAL_STYLES[approvalKey] ??
|
|
||||||
APPROVAL_STYLES.PENDING_REVIEW;
|
|
||||||
const ApprovalIcon = approval.Icon;
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<div key={key}>
|
||||||
key={task.id}
|
|
||||||
href={ver ? `/client/${token}/review/${ver.id}` : '#'}
|
|
||||||
onClick={handleReviewClick}
|
|
||||||
className={cn(
|
|
||||||
'flex items-center gap-4 p-4 rounded-xl border transition-all group',
|
|
||||||
'bg-zinc-900 border-zinc-800 hover:border-zinc-600 hover:bg-zinc-800/70',
|
|
||||||
!ver && 'pointer-events-none opacity-40',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<div className="flex items-center gap-1.5">
|
|
||||||
<p className="text-sm font-medium text-white">
|
|
||||||
{task.title}
|
|
||||||
</p>
|
|
||||||
<button
|
<button
|
||||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); copyToClipboard(task.title, `task-${task.id}`); }}
|
className="w-full flex items-center gap-3 px-5 py-2.5 bg-zinc-900/60 hover:bg-zinc-800/60 transition-colors text-left"
|
||||||
className="shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
onClick={() => toggleEpisode(key)}
|
||||||
title="Copy task name"
|
|
||||||
>
|
>
|
||||||
{copiedId === `task-${task.id}` ? (
|
<ChevronDown
|
||||||
<Check className="h-3 w-3 text-emerald-400" />
|
|
||||||
) : (
|
|
||||||
<Copy className="h-3 w-3" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-zinc-500">
|
|
||||||
{TASK_TYPE_LABELS[task.type] ?? task.type}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{ver ? (
|
|
||||||
<div className="flex items-center gap-3 shrink-0">
|
|
||||||
{ver.createdAt && (
|
|
||||||
<span className="text-xs text-zinc-600 hidden sm:block">
|
|
||||||
{formatDate(ver.createdAt)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<span
|
|
||||||
className={cn(
|
className={cn(
|
||||||
'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full border text-xs font-medium',
|
'h-3.5 w-3.5 text-zinc-500 shrink-0 transition-transform duration-200',
|
||||||
approval.className,
|
sceneCollapsed && '-rotate-90',
|
||||||
)}
|
)}
|
||||||
>
|
/>
|
||||||
<ApprovalIcon className="h-3 w-3" />
|
<div className="flex-1 min-w-0">
|
||||||
{approval.label}
|
<span className="text-xs font-medium uppercase tracking-wider text-zinc-400">
|
||||||
|
{scene === NO_SCENE ? 'No scene' : `Scene ${scene}`}
|
||||||
|
</span>
|
||||||
|
<span className="ml-3 text-xs text-zinc-600">
|
||||||
|
{sceneShots.length}{' '}
|
||||||
|
{sceneShots.length === 1 ? 'shot' : 'shots'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
{statusPills(sceneShots.flatMap((s) => s.tasks))}
|
||||||
<span className="text-xs text-zinc-600 shrink-0">
|
</button>
|
||||||
No versions yet
|
{!sceneCollapsed && (
|
||||||
</span>
|
<div className="divide-y divide-zinc-800/60 border-t border-zinc-800/60">
|
||||||
|
{sceneShots.map(renderShot)}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
<ChevronRight className="h-4 w-4 text-zinc-600 group-hover:text-zinc-400 shrink-0 transition-colors" />
|
</div>
|
||||||
</Link>
|
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
</div>
|
: filteredEpShots.map(renderShot)}
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -1007,7 +1092,7 @@ export default function ClientPortalPage({
|
|||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); copyToClipboard(task.title, `task-${task.id}`); }}
|
onClick={(e) => { e.preventDefault(); e.stopPropagation(); copyToClipboard(task.title, `task-${task.id}`); }}
|
||||||
className="shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
className="hidden sm:block shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 text-zinc-600 hover:text-zinc-300 transition-all"
|
||||||
title="Copy task name"
|
title="Copy task name"
|
||||||
>
|
>
|
||||||
{copiedId === `task-${task.id}` ? (
|
{copiedId === `task-${task.id}` ? (
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import {
|
|||||||
Clock,
|
Clock,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
Copy,
|
Copy,
|
||||||
Check,
|
Check,
|
||||||
Download,
|
Download,
|
||||||
@@ -36,6 +38,7 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useReviewStore } from "@/hooks/use-review-player";
|
import { useReviewStore } from "@/hooks/use-review-player";
|
||||||
import { ReviewPasswordGate } from "@/components/clients/ReviewPasswordGate";
|
import { ReviewPasswordGate } from "@/components/clients/ReviewPasswordGate";
|
||||||
|
import { HandleBadge } from "@/components/player/HandleBadge";
|
||||||
|
|
||||||
interface Comment {
|
interface Comment {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -56,6 +59,14 @@ interface Version {
|
|||||||
fileUrl: string;
|
fileUrl: string;
|
||||||
fps: number;
|
fps: number;
|
||||||
duration: number | null;
|
duration: number | null;
|
||||||
|
frameCount?: number | null;
|
||||||
|
/** High quality review MP4 — the player's quality switch. */
|
||||||
|
hqFileUrl?: string | null;
|
||||||
|
/** Where the High Res download comes from: this version's ProRes, or the shot's legacy file. */
|
||||||
|
highResSource?: "version" | "shot" | null;
|
||||||
|
handleHead?: number | null;
|
||||||
|
handleTail?: number | null;
|
||||||
|
pictureStartFrame?: number | null;
|
||||||
approvalStatus: string;
|
approvalStatus: string;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
// Top-level high-res flags (normalised from either shot or task.shot)
|
// Top-level high-res flags (normalised from either shot or task.shot)
|
||||||
@@ -274,10 +285,17 @@ export default function ClientReviewPage({
|
|||||||
|
|
||||||
const handleDownloadHighRes = async () => {
|
const handleDownloadHighRes = async () => {
|
||||||
const shotId = version?.highResShotId ?? version?.shot?.id;
|
const shotId = version?.highResShotId ?? version?.shot?.id;
|
||||||
if (!shotId || !token) return;
|
if (!version || !token) return;
|
||||||
|
const endpoint =
|
||||||
|
version.highResSource === "version"
|
||||||
|
? `/api/client/${token}/versions/${version.id}/highres/download`
|
||||||
|
: shotId
|
||||||
|
? `/api/client/${token}/shots/${shotId}/highres/download`
|
||||||
|
: null;
|
||||||
|
if (!endpoint) return;
|
||||||
setDownloadingHighRes(true);
|
setDownloadingHighRes(true);
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/client/${token}/shots/${shotId}/highres/download`);
|
const res = await fetch(endpoint);
|
||||||
if (!res.ok) throw new Error("Could not get download link");
|
if (!res.ok) throw new Error("Could not get download link");
|
||||||
const { url } = await res.json();
|
const { url } = await res.json();
|
||||||
// Open the presigned URL — the Content-Disposition header forces a download
|
// Open the presigned URL — the Content-Disposition header forces a download
|
||||||
@@ -357,9 +375,11 @@ export default function ClientReviewPage({
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-screen bg-zinc-950 text-white overflow-hidden">
|
<div className="flex flex-col h-screen bg-zinc-950 text-white overflow-hidden">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<header className="grid grid-cols-[1fr_auto_1fr] items-center gap-2 px-4 py-2.5 border-b border-zinc-800 bg-zinc-900 shrink-0">
|
{/* Phones: back + shot + prev/next on the first row, status and decision
|
||||||
|
buttons on a second full-width row. From md: the three-column grid. */}
|
||||||
|
<header className="flex flex-wrap items-center gap-2 md:grid md:grid-cols-[1fr_auto_1fr] px-4 py-2.5 border-b border-zinc-800 bg-zinc-900 shrink-0">
|
||||||
{/* Left: back + shot path */}
|
{/* Left: back + shot path */}
|
||||||
<div className="flex items-center gap-3 min-w-0">
|
<div className="flex items-center gap-3 min-w-0 flex-1 md:flex-none">
|
||||||
<Link
|
<Link
|
||||||
href={`/client/${token}`}
|
href={`/client/${token}`}
|
||||||
className="text-zinc-400 hover:text-white transition-colors flex items-center gap-1.5 text-sm shrink-0"
|
className="text-zinc-400 hover:text-white transition-colors flex items-center gap-1.5 text-sm shrink-0"
|
||||||
@@ -387,7 +407,7 @@ export default function ClientReviewPage({
|
|||||||
<span className="text-xs text-zinc-500 hidden sm:block">{project?.code}</span>
|
<span className="text-xs text-zinc-500 hidden sm:block">{project?.code}</span>
|
||||||
<span className="text-zinc-600">/</span>
|
<span className="text-zinc-600">/</span>
|
||||||
{contextCode && (
|
{contextCode && (
|
||||||
<span className="font-mono font-semibold">{contextCode}</span>
|
<span className="font-mono font-semibold truncate">{contextCode}</span>
|
||||||
)}
|
)}
|
||||||
{taskName && (
|
{taskName && (
|
||||||
<>
|
<>
|
||||||
@@ -417,11 +437,11 @@ export default function ClientReviewPage({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Center: status badge + decision buttons */}
|
{/* Center: status badge + decision buttons (their own row on phones) */}
|
||||||
<div className="flex items-center gap-2 shrink-0">
|
<div className="order-last md:order-none flex w-full md:w-auto items-center gap-2 shrink-0">
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-xs px-2.5 py-1 rounded-full border hidden sm:inline-flex items-center gap-1 shrink-0",
|
"text-xs px-2.5 py-1 rounded-full border inline-flex items-center gap-1 shrink-0 mr-auto md:mr-0",
|
||||||
approvalStyle
|
approvalStyle
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -509,6 +529,11 @@ export default function ClientReviewPage({
|
|||||||
comments={comments as any}
|
comments={comments as any}
|
||||||
versionId={version.id}
|
versionId={version.id}
|
||||||
onAddComment={handlePlayerAddComment}
|
onAddComment={handlePlayerAddComment}
|
||||||
|
handles={version}
|
||||||
|
hqVideoUrl={version.hqFileUrl}
|
||||||
|
// The director watches the cut as cut; handles are still one
|
||||||
|
// toggle away, and flagged whenever the playhead is in one.
|
||||||
|
defaultEditRangeOnly
|
||||||
saveAnnotationFn={async (data) => {
|
saveAnnotationFn={async (data) => {
|
||||||
const res = await fetch(`/api/client/${token}/annotation`, {
|
const res = await fetch(`/api/client/${token}/annotation`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -542,10 +567,17 @@ export default function ClientReviewPage({
|
|||||||
className="flex items-center justify-center h-10 w-full border-b border-zinc-800 hover:bg-zinc-800/60 transition-colors shrink-0"
|
className="flex items-center justify-center h-10 w-full border-b border-zinc-800 hover:bg-zinc-800/60 transition-colors shrink-0"
|
||||||
title={commentsOpen ? "Collapse notes" : "Expand notes"}
|
title={commentsOpen ? "Collapse notes" : "Expand notes"}
|
||||||
>
|
>
|
||||||
|
{/* Below the video on phones, so down/up there and right/left from md. */}
|
||||||
{commentsOpen ? (
|
{commentsOpen ? (
|
||||||
<ChevronRight className="h-4 w-4 text-zinc-400" />
|
<>
|
||||||
|
<ChevronDown className="h-4 w-4 text-zinc-400 md:hidden" />
|
||||||
|
<ChevronRight className="h-4 w-4 text-zinc-400 hidden md:block" />
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<ChevronLeft className="h-4 w-4 text-zinc-400" />
|
<>
|
||||||
|
<ChevronUp className="h-4 w-4 text-zinc-400 md:hidden" />
|
||||||
|
<ChevronLeft className="h-4 w-4 text-zinc-400 hidden md:block" />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{!commentsOpen && (
|
{!commentsOpen && (
|
||||||
<MessageSquare className="h-4 w-4 text-zinc-400 mt-1" />
|
<MessageSquare className="h-4 w-4 text-zinc-400 mt-1" />
|
||||||
@@ -633,6 +665,7 @@ export default function ClientReviewPage({
|
|||||||
<span className="ml-auto font-mono text-xs text-amber-400/80">
|
<span className="ml-auto font-mono text-xs text-amber-400/80">
|
||||||
{frameToTimecode(comment.frameNumber, version.fps)}
|
{frameToTimecode(comment.frameNumber, version.fps)}
|
||||||
</span>
|
</span>
|
||||||
|
<HandleBadge frame={comment.frameNumber} />
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-zinc-200 leading-relaxed">{comment.text}</p>
|
<p className="text-sm text-zinc-200 leading-relaxed">{comment.text}</p>
|
||||||
{comment.canEdit && (
|
{comment.canEdit && (
|
||||||
@@ -681,8 +714,9 @@ export default function ClientReviewPage({
|
|||||||
|
|
||||||
{commentsOpen && commentFrame !== null ? (
|
{commentsOpen && commentFrame !== null ? (
|
||||||
<div className="border-t border-zinc-800 p-3 space-y-2">
|
<div className="border-t border-zinc-800 p-3 space-y-2">
|
||||||
<p className="text-xs text-zinc-500 font-mono">
|
<p className="flex items-center gap-2 text-xs text-zinc-500 font-mono">
|
||||||
Frame {commentFrame} · {frameToTimecode(commentFrame, version.fps)}
|
Frame {commentFrame} · {frameToTimecode(commentFrame, version.fps)}
|
||||||
|
<HandleBadge frame={commentFrame} />
|
||||||
</p>
|
</p>
|
||||||
<Textarea
|
<Textarea
|
||||||
placeholder="Add your note..."
|
placeholder="Add your note..."
|
||||||
|
|||||||
@@ -28,17 +28,20 @@ import { submitApproval } from "@/actions/approvals";
|
|||||||
import { internallyApproveShot } from "@/actions/shots";
|
import { internallyApproveShot } from "@/actions/shots";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { ShareWithClientButton } from "@/components/versions/ShareWithClientButton";
|
import { ShareWithClientButton } from "@/components/versions/ShareWithClientButton";
|
||||||
|
import { VersionHandlesButton } from "@/components/versions/VersionHandlesButton";
|
||||||
import {
|
import {
|
||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
XCircle,
|
XCircle,
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
Film,
|
Film,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
MessageSquare,
|
MessageSquare,
|
||||||
|
Download,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
interface ReviewPageClientProps {
|
interface ReviewPageClientProps {
|
||||||
@@ -49,12 +52,21 @@ interface ReviewPageClientProps {
|
|||||||
fps: number;
|
fps: number;
|
||||||
duration: number | null;
|
duration: number | null;
|
||||||
frameCount: number | null;
|
frameCount: number | null;
|
||||||
|
handleHead: number | null;
|
||||||
|
handleTail: number | null;
|
||||||
|
pictureStartFrame: number | null;
|
||||||
|
hqFileUrl: string | null;
|
||||||
|
highResKey: string | null;
|
||||||
|
highResFilename: string | null;
|
||||||
|
highResSize: bigint | number | null;
|
||||||
approvalStatus: string;
|
approvalStatus: string;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
isClientVisible: boolean;
|
isClientVisible: boolean;
|
||||||
shot?: {
|
shot?: {
|
||||||
id: string;
|
id: string;
|
||||||
shotCode: string;
|
shotCode: string;
|
||||||
|
shotApprovalStatus: string;
|
||||||
|
sharedWithClient: boolean;
|
||||||
project: { id: string; name: string; code: string };
|
project: { id: string; name: string; code: string };
|
||||||
versions: {
|
versions: {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -72,7 +84,7 @@ interface ReviewPageClientProps {
|
|||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
project: { id: string; name: string; code: string };
|
project: { id: string; name: string; code: string };
|
||||||
shot?: { id: string; shotCode: string } | null;
|
shot?: { id: string; shotCode: string; shotApprovalStatus: string; sharedWithClient: boolean } | null;
|
||||||
asset?: { id: string; assetCode: string; name: string } | null;
|
asset?: { id: string; assetCode: string; name: string } | null;
|
||||||
versions: {
|
versions: {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -96,6 +108,11 @@ interface ReviewPageClientProps {
|
|||||||
userRole?: string;
|
userRole?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatBytes(bytes: number): string {
|
||||||
|
if (bytes >= 1e9) return `${(bytes / 1e9).toFixed(1)} GB`;
|
||||||
|
return `${Math.max(1, Math.round(bytes / 1e6))} MB`;
|
||||||
|
}
|
||||||
|
|
||||||
const APPROVAL_STATUS_STYLES: Record<string, string> = {
|
const APPROVAL_STATUS_STYLES: Record<string, string> = {
|
||||||
PENDING_REVIEW: "bg-amber-500/10 text-amber-400 border-amber-500/20",
|
PENDING_REVIEW: "bg-amber-500/10 text-amber-400 border-amber-500/20",
|
||||||
APPROVED: "bg-emerald-500/10 text-emerald-400 border-emerald-500/20",
|
APPROVED: "bg-emerald-500/10 text-emerald-400 border-emerald-500/20",
|
||||||
@@ -124,11 +141,31 @@ export function ReviewPageClient({
|
|||||||
const [isInternallyApproving, setIsInternallyApproving] = useState(false);
|
const [isInternallyApproving, setIsInternallyApproving] = useState(false);
|
||||||
const [showVersions, setShowVersions] = useState(false);
|
const [showVersions, setShowVersions] = useState(false);
|
||||||
const [commentsOpen, setCommentsOpen] = useState(true);
|
const [commentsOpen, setCommentsOpen] = useState(true);
|
||||||
|
const [downloadingProRes, setDownloadingProRes] = useState(false);
|
||||||
|
|
||||||
const playerRef = useRef<ReviewPlayerRef>(null);
|
const playerRef = useRef<ReviewPlayerRef>(null);
|
||||||
|
|
||||||
|
// The shot this version belongs to, directly or through its task. Approval
|
||||||
|
// and client sharing are shot-level: the client portal only lists shots
|
||||||
|
// marked sharedWithClient, so sharing has to go through the shot.
|
||||||
|
const reviewShot = version.shot ?? version.task?.shot ?? null;
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleDownloadProRes = async () => {
|
||||||
|
setDownloadingProRes(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/versions/${version.id}/highres/download`);
|
||||||
|
if (!res.ok) throw new Error("Could not get download link");
|
||||||
|
const { url } = await res.json();
|
||||||
|
window.open(url, "_blank", "noopener,noreferrer");
|
||||||
|
} catch {
|
||||||
|
toast({ title: "Download failed", variant: "destructive" });
|
||||||
|
} finally {
|
||||||
|
setDownloadingProRes(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleAddComment = useCallback(() => {
|
const handleAddComment = useCallback(() => {
|
||||||
// Pause player first
|
// Pause player first
|
||||||
playerRef.current?.pause();
|
playerRef.current?.pause();
|
||||||
@@ -193,7 +230,7 @@ export function ReviewPageClient({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleInternalApprove = async () => {
|
const handleInternalApprove = async () => {
|
||||||
const shotId = version.shot?.id;
|
const shotId = reviewShot?.id;
|
||||||
if (!shotId) return;
|
if (!shotId) return;
|
||||||
setIsInternallyApproving(true);
|
setIsInternallyApproving(true);
|
||||||
try {
|
try {
|
||||||
@@ -231,8 +268,9 @@ export function ReviewPageClient({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-screen bg-background overflow-hidden">
|
<div className="flex flex-col h-screen bg-background overflow-hidden">
|
||||||
{/* Top bar */}
|
{/* Top bar — phones: shot + version on the first row, actions wrap to a
|
||||||
<div className="flex items-center gap-3 px-4 py-2 border-b border-border bg-card shrink-0">
|
second row. From md: one row. */}
|
||||||
|
<div className="flex flex-wrap md:flex-nowrap items-center gap-x-3 gap-y-2 px-4 py-2 border-b border-border bg-card shrink-0">
|
||||||
<Link
|
<Link
|
||||||
href={backHref}
|
href={backHref}
|
||||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||||
@@ -240,14 +278,14 @@ export function ReviewPageClient({
|
|||||||
<ArrowLeft className="h-4 w-4" />
|
<ArrowLeft className="h-4 w-4" />
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 flex-1 min-w-0">
|
<div className="flex items-center gap-2 flex-1 min-w-0 overflow-hidden">
|
||||||
<span className="text-xs text-muted-foreground hidden sm:block">
|
<span className="text-xs text-muted-foreground hidden sm:block">
|
||||||
{project?.code}
|
{project?.code}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-muted-foreground">/</span>
|
<span className="text-muted-foreground">/</span>
|
||||||
{contextCode && (
|
{contextCode && (
|
||||||
<>
|
<>
|
||||||
<span className="font-mono text-sm font-semibold">{contextCode}</span>
|
<span className="font-mono text-sm font-semibold truncate">{contextCode}</span>
|
||||||
<span className="text-muted-foreground">/</span>
|
<span className="text-muted-foreground">/</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -274,6 +312,38 @@ export function ReviewPageClient({
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* ProRes — this version's delivery MOV, uploaded by the render worker */}
|
||||||
|
{version.highResKey && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-7 shrink-0 gap-1 text-xs text-sky-400"
|
||||||
|
disabled={downloadingProRes}
|
||||||
|
onClick={handleDownloadProRes}
|
||||||
|
title={
|
||||||
|
(version.highResFilename ?? "ProRes") +
|
||||||
|
(version.highResSize ? ` · ${formatBytes(Number(version.highResSize))}` : "")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Download className="h-3 w-3" />
|
||||||
|
<span className="hidden lg:inline">{downloadingProRes ? "Getting link…" : "ProRes"}</span>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Handles — outside the breadcrumb so it never gets squeezed */}
|
||||||
|
{userRole !== "CLIENT" && (
|
||||||
|
<div className="shrink-0">
|
||||||
|
<VersionHandlesButton
|
||||||
|
key={version.id}
|
||||||
|
versionId={version.id}
|
||||||
|
handleHead={version.handleHead}
|
||||||
|
handleTail={version.handleTail}
|
||||||
|
pictureStartFrame={version.pictureStartFrame}
|
||||||
|
onSaved={() => router.refresh()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Approval status */}
|
{/* Approval status */}
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -284,12 +354,17 @@ export function ReviewPageClient({
|
|||||||
{version.approvalStatus.replace("_", " ")}
|
{version.approvalStatus.replace("_", " ")}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
{/* Actions: their own full-width row on phones; md:contents puts them
|
||||||
|
back in the top bar's single row, exactly as before. */}
|
||||||
|
{(canShare || canApprove) && (
|
||||||
|
<div className="flex w-full items-center justify-end gap-3 md:contents">
|
||||||
{/* Share with Client */}
|
{/* Share with Client */}
|
||||||
{canShare && (
|
{canShare && (
|
||||||
<ShareWithClientButton
|
<ShareWithClientButton
|
||||||
versionId={version.id}
|
versionId={version.id}
|
||||||
isAlreadyShared={version.isClientVisible}
|
isAlreadyShared={version.isClientVisible}
|
||||||
onShared={() => {/* router.refresh() handled inside component */}}
|
shot={reviewShot}
|
||||||
|
onShared={() => router.refresh()}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -314,7 +389,8 @@ export function ReviewPageClient({
|
|||||||
<XCircle className="h-3 w-3" />
|
<XCircle className="h-3 w-3" />
|
||||||
<span className="hidden sm:inline">Reject</span>
|
<span className="hidden sm:inline">Reject</span>
|
||||||
</Button>
|
</Button>
|
||||||
{version.shot?.id && (
|
{/* Same rule as the shot page: only while the shot awaits internal approval. */}
|
||||||
|
{reviewShot?.shotApprovalStatus === "PENDING" && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
className="h-7 text-xs gap-1 bg-sky-600 hover:bg-sky-500 text-white"
|
className="h-7 text-xs gap-1 bg-sky-600 hover:bg-sky-500 text-white"
|
||||||
@@ -330,9 +406,11 @@ export function ReviewPageClient({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Main content — player + comments */}
|
{/* Main content — player + comments: stacked on phones, side by side from md */}
|
||||||
<div className="flex flex-1 overflow-hidden">
|
<div className="flex flex-col md:flex-row flex-1 overflow-hidden">
|
||||||
{/* Player — 70% */}
|
{/* Player — 70% */}
|
||||||
<div className="flex-1 min-w-0 min-h-0 overflow-hidden flex flex-col bg-black">
|
<div className="flex-1 min-w-0 min-h-0 overflow-hidden flex flex-col bg-black">
|
||||||
<ReviewPlayer
|
<ReviewPlayer
|
||||||
@@ -344,26 +422,35 @@ export function ReviewPageClient({
|
|||||||
versionId={version.id}
|
versionId={version.id}
|
||||||
onAddComment={handleAddComment}
|
onAddComment={handleAddComment}
|
||||||
onAnnotationSaved={handleAnnotationSaved}
|
onAnnotationSaved={handleAnnotationSaved}
|
||||||
|
handles={version}
|
||||||
|
hqVideoUrl={version.hqFileUrl}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Comment panel — collapsible */}
|
{/* Comment panel — collapsible */}
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"shrink-0 flex flex-col border-l border-border transition-all duration-200",
|
"shrink-0 flex flex-col border-t md:border-t-0 md:border-l border-border transition-all duration-200",
|
||||||
commentsOpen ? "w-80 xl:w-96" : "w-10"
|
commentsOpen ? "h-[45%] md:h-auto md:w-80 xl:w-96" : "h-10 md:h-auto md:w-10"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* Collapse toggle */}
|
{/* Collapse toggle — the panel sits below the video on phones, so
|
||||||
|
the arrow points down/up there and right/left from md. */}
|
||||||
<button
|
<button
|
||||||
onClick={() => setCommentsOpen((o) => !o)}
|
onClick={() => setCommentsOpen((o) => !o)}
|
||||||
className="flex items-center justify-center h-10 w-full border-b border-border hover:bg-muted/50 transition-colors shrink-0"
|
className="flex items-center justify-center h-10 w-full border-b border-border hover:bg-muted/50 transition-colors shrink-0"
|
||||||
title={commentsOpen ? "Collapse comments" : "Expand comments"}
|
title={commentsOpen ? "Collapse comments" : "Expand comments"}
|
||||||
>
|
>
|
||||||
{commentsOpen ? (
|
{commentsOpen ? (
|
||||||
<ChevronRight className="h-4 w-4 text-muted-foreground" />
|
<>
|
||||||
|
<ChevronDown className="h-4 w-4 text-muted-foreground md:hidden" />
|
||||||
|
<ChevronRight className="h-4 w-4 text-muted-foreground hidden md:block" />
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<ChevronLeft className="h-4 w-4 text-muted-foreground" />
|
<>
|
||||||
|
<ChevronUp className="h-4 w-4 text-muted-foreground md:hidden" />
|
||||||
|
<ChevronLeft className="h-4 w-4 text-muted-foreground hidden md:block" />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{!commentsOpen && (
|
{!commentsOpen && (
|
||||||
<MessageSquare className="h-4 w-4 text-muted-foreground mt-1" />
|
<MessageSquare className="h-4 w-4 text-muted-foreground mt-1" />
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ async function getReviewData(versionId: string) {
|
|||||||
task: {
|
task: {
|
||||||
include: {
|
include: {
|
||||||
project: { select: { id: true, name: true, code: true } },
|
project: { select: { id: true, name: true, code: true } },
|
||||||
shot: { select: { id: true, shotCode: true } },
|
shot: { select: { id: true, shotCode: true, shotApprovalStatus: true, sharedWithClient: true } },
|
||||||
asset: { select: { id: true, assetCode: true, name: true } },
|
asset: { select: { id: true, assetCode: true, name: true } },
|
||||||
versions: {
|
versions: {
|
||||||
orderBy: { versionNumber: "desc" },
|
orderBy: { versionNumber: "desc" },
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
useCallback,
|
useCallback,
|
||||||
MouseEvent,
|
MouseEvent,
|
||||||
|
type RefObject,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useReviewStore } from "@/hooks/use-review-player";
|
import { useReviewStore } from "@/hooks/use-review-player";
|
||||||
import { saveAnnotation } from "@/actions/annotations";
|
import { saveAnnotation } from "@/actions/annotations";
|
||||||
import { addComment } from "@/actions/comments";
|
import { addComment } from "@/actions/comments";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { letterboxRect } from "@/lib/aspect-overlays";
|
||||||
import type { AnnotationShape, AnnotationDrawingData, AnnotationPoint } from "@/types";
|
import type { AnnotationShape, AnnotationDrawingData, AnnotationPoint } from "@/types";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
@@ -30,6 +32,8 @@ interface AddCommentData {
|
|||||||
|
|
||||||
interface AnnotationCanvasProps {
|
interface AnnotationCanvasProps {
|
||||||
versionId: string;
|
versionId: string;
|
||||||
|
/** The video under the canvas — the canvas is sized to its displayed picture. */
|
||||||
|
videoRef: RefObject<HTMLVideoElement | null>;
|
||||||
frameNumber: number;
|
frameNumber: number;
|
||||||
fps: number;
|
fps: number;
|
||||||
isAnnotating: boolean;
|
isAnnotating: boolean;
|
||||||
@@ -42,6 +46,20 @@ interface AnnotationCanvasProps {
|
|||||||
addCommentFn?: (data: AddCommentData) => Promise<void>;
|
addCommentFn?: (data: AddCommentData) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A shape as held in memory. Legacy (v1.0) shapes keep their points relative to
|
||||||
|
* the player box they were drawn in; `legacyBox` is that box, used to map them
|
||||||
|
* onto the picture once the video's intrinsic size is known.
|
||||||
|
*/
|
||||||
|
type LoadedShape = AnnotationShape & { legacyBox?: { w: number; h: number } };
|
||||||
|
|
||||||
|
function shapesOf(drawingData: AnnotationDrawingData | undefined): LoadedShape[] {
|
||||||
|
const shapes = drawingData?.shapes ?? [];
|
||||||
|
if (!drawingData || drawingData.version === "2.0") return shapes;
|
||||||
|
const legacyBox = { w: drawingData.canvasWidth, h: drawingData.canvasHeight };
|
||||||
|
return shapes.map((s) => ({ ...s, legacyBox }));
|
||||||
|
}
|
||||||
|
|
||||||
type DrawingState = {
|
type DrawingState = {
|
||||||
isDrawing: boolean;
|
isDrawing: boolean;
|
||||||
currentShape: AnnotationShape | null;
|
currentShape: AnnotationShape | null;
|
||||||
@@ -50,6 +68,7 @@ type DrawingState = {
|
|||||||
|
|
||||||
export function AnnotationCanvas({
|
export function AnnotationCanvas({
|
||||||
versionId,
|
versionId,
|
||||||
|
videoRef,
|
||||||
frameNumber,
|
frameNumber,
|
||||||
fps,
|
fps,
|
||||||
isAnnotating,
|
isAnnotating,
|
||||||
@@ -73,10 +92,10 @@ export function AnnotationCanvas({
|
|||||||
|
|
||||||
// Per-frame saved shapes — persists across frame navigation so annotations
|
// Per-frame saved shapes — persists across frame navigation so annotations
|
||||||
// remain visible without depending on a parent API refetch.
|
// remain visible without depending on a parent API refetch.
|
||||||
const [savedShapesByFrame, setSavedShapesByFrame] = useState<Record<number, AnnotationShape[]>>(() => {
|
const [savedShapesByFrame, setSavedShapesByFrame] = useState<Record<number, LoadedShape[]>>(() => {
|
||||||
const map: Record<number, AnnotationShape[]> = {};
|
const map: Record<number, LoadedShape[]> = {};
|
||||||
for (const a of (existingAnnotations as { frameNumber: number; drawingData: AnnotationDrawingData }[])) {
|
for (const a of (existingAnnotations as { frameNumber: number; drawingData: AnnotationDrawingData }[])) {
|
||||||
const shapes = a.drawingData?.shapes ?? [];
|
const shapes = shapesOf(a.drawingData);
|
||||||
map[a.frameNumber] = [...(map[a.frameNumber] ?? []), ...shapes];
|
map[a.frameNumber] = [...(map[a.frameNumber] ?? []), ...shapes];
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
@@ -114,10 +133,10 @@ export function AnnotationCanvas({
|
|||||||
|
|
||||||
setSavedShapesByFrame((prev) => {
|
setSavedShapesByFrame((prev) => {
|
||||||
// Build map from server data
|
// Build map from server data
|
||||||
const serverMap: Record<number, AnnotationShape[]> = {};
|
const serverMap: Record<number, LoadedShape[]> = {};
|
||||||
const serverShapeIds = new Set<string>();
|
const serverShapeIds = new Set<string>();
|
||||||
for (const a of (existingAnnotations as { frameNumber: number; drawingData: AnnotationDrawingData }[])) {
|
for (const a of (existingAnnotations as { frameNumber: number; drawingData: AnnotationDrawingData }[])) {
|
||||||
const shapes = a.drawingData?.shapes ?? [];
|
const shapes = shapesOf(a.drawingData);
|
||||||
serverMap[a.frameNumber] = [...(serverMap[a.frameNumber] ?? []), ...shapes];
|
serverMap[a.frameNumber] = [...(serverMap[a.frameNumber] ?? []), ...shapes];
|
||||||
for (const s of shapes) serverShapeIds.add(s.id);
|
for (const s of shapes) serverShapeIds.add(s.id);
|
||||||
}
|
}
|
||||||
@@ -145,6 +164,65 @@ export function AnnotationCanvas({
|
|||||||
}, [existingAnnotations]);
|
}, [existingAnnotations]);
|
||||||
|
|
||||||
|
|
||||||
|
// ── Picture rect ─────────────────────────────────────────────────────────
|
||||||
|
// The canvas is laid exactly over the displayed picture (not the letterboxed
|
||||||
|
// player box), so normalized points are fractions of the image itself and
|
||||||
|
// stay locked to it at any player size. Same measurement as AspectOverlay;
|
||||||
|
// clientWidth/Height ignore the zoom transform, which the canvas shares.
|
||||||
|
const [pictureRect, setPictureRect] = useState<{
|
||||||
|
left: number;
|
||||||
|
top: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!video) return;
|
||||||
|
const measure = () => {
|
||||||
|
const rect = letterboxRect(
|
||||||
|
video.clientWidth,
|
||||||
|
video.clientHeight,
|
||||||
|
video.videoWidth,
|
||||||
|
video.videoHeight
|
||||||
|
);
|
||||||
|
setPictureRect((prev) =>
|
||||||
|
prev &&
|
||||||
|
rect &&
|
||||||
|
prev.left === rect.left &&
|
||||||
|
prev.top === rect.top &&
|
||||||
|
prev.width === rect.width &&
|
||||||
|
prev.height === rect.height
|
||||||
|
? prev
|
||||||
|
: rect
|
||||||
|
);
|
||||||
|
};
|
||||||
|
measure();
|
||||||
|
const observer = new ResizeObserver(measure);
|
||||||
|
observer.observe(video);
|
||||||
|
video.addEventListener("loadedmetadata", measure);
|
||||||
|
return () => {
|
||||||
|
observer.disconnect();
|
||||||
|
video.removeEventListener("loadedmetadata", measure);
|
||||||
|
};
|
||||||
|
}, [videoRef]);
|
||||||
|
|
||||||
|
/** A shape's points as fractions of the picture (maps legacy box-relative ones). */
|
||||||
|
const pictureSpacePoints = useCallback(
|
||||||
|
(shape: LoadedShape): AnnotationPoint[] => {
|
||||||
|
const box = shape.legacyBox;
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!box || !video) return shape.points;
|
||||||
|
const r = letterboxRect(box.w, box.h, video.videoWidth, video.videoHeight);
|
||||||
|
if (!r) return shape.points; // no metadata yet — best effort
|
||||||
|
return shape.points.map((p) => ({
|
||||||
|
x: (p.x * box.w - r.left) / r.width,
|
||||||
|
y: (p.y * box.h - r.top) / r.height,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
[videoRef]
|
||||||
|
);
|
||||||
|
|
||||||
// ── Coordinate normalization ─────────────────────────────────────────────
|
// ── Coordinate normalization ─────────────────────────────────────────────
|
||||||
const toNormalized = (e: MouseEvent): AnnotationPoint => {
|
const toNormalized = (e: MouseEvent): AnnotationPoint => {
|
||||||
const canvas = canvasRef.current!;
|
const canvas = canvasRef.current!;
|
||||||
@@ -164,7 +242,7 @@ export function AnnotationCanvas({
|
|||||||
const renderShape = useCallback(
|
const renderShape = useCallback(
|
||||||
(
|
(
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
shape: AnnotationShape,
|
shape: LoadedShape,
|
||||||
w: number,
|
w: number,
|
||||||
h: number
|
h: number
|
||||||
) => {
|
) => {
|
||||||
@@ -176,7 +254,7 @@ export function AnnotationCanvas({
|
|||||||
ctx.lineJoin = "round";
|
ctx.lineJoin = "round";
|
||||||
ctx.globalAlpha = 0.85;
|
ctx.globalAlpha = 0.85;
|
||||||
|
|
||||||
const pts = shape.points.map((p) => toPixel(p, w, h));
|
const pts = pictureSpacePoints(shape).map((p) => toPixel(p, w, h));
|
||||||
|
|
||||||
switch (shape.tool) {
|
switch (shape.tool) {
|
||||||
case "freehand": {
|
case "freehand": {
|
||||||
@@ -244,7 +322,7 @@ export function AnnotationCanvas({
|
|||||||
}
|
}
|
||||||
ctx.globalAlpha = 1;
|
ctx.globalAlpha = 1;
|
||||||
},
|
},
|
||||||
[]
|
[pictureSpacePoints]
|
||||||
);
|
);
|
||||||
|
|
||||||
const redraw = useCallback(() => {
|
const redraw = useCallback(() => {
|
||||||
@@ -352,7 +430,7 @@ export function AnnotationCanvas({
|
|||||||
shapes: [finishedShape],
|
shapes: [finishedShape],
|
||||||
canvasWidth: canvas?.offsetWidth ?? 1920,
|
canvasWidth: canvas?.offsetWidth ?? 1920,
|
||||||
canvasHeight: canvas?.offsetHeight ?? 1080,
|
canvasHeight: canvas?.offsetHeight ?? 1080,
|
||||||
version: "1.0",
|
version: "2.0",
|
||||||
};
|
};
|
||||||
|
|
||||||
const doSaveAnnotation = saveAnnotationFn
|
const doSaveAnnotation = saveAnnotationFn
|
||||||
@@ -447,6 +525,12 @@ export function AnnotationCanvas({
|
|||||||
ref={canvasRef}
|
ref={canvasRef}
|
||||||
className={`annotation-canvas-overlay ${isAnnotating ? "is-annotating" : ""}`}
|
className={`annotation-canvas-overlay ${isAnnotating ? "is-annotating" : ""}`}
|
||||||
style={{
|
style={{
|
||||||
|
...(pictureRect && {
|
||||||
|
left: pictureRect.left,
|
||||||
|
top: pictureRect.top,
|
||||||
|
width: pictureRect.width,
|
||||||
|
height: pictureRect.height,
|
||||||
|
}),
|
||||||
cursor: isAnnotating ? "crosshair" : "default",
|
cursor: isAnnotating ? "crosshair" : "default",
|
||||||
touchAction: isAnnotating ? "none" : "auto",
|
touchAction: isAnnotating ? "none" : "auto",
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -21,11 +21,14 @@ import {
|
|||||||
ArrowRight,
|
ArrowRight,
|
||||||
RotateCcw,
|
RotateCcw,
|
||||||
ImageIcon,
|
ImageIcon,
|
||||||
|
Film,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { PLATE_EXTS, plateContentType } from "@/lib/batch-upload-parser";
|
||||||
import type { PreviewItem, PreviewItemStatus } from "@/app/api/batch-upload/preview/route";
|
import type { PreviewItem, PreviewItemStatus } from "@/app/api/batch-upload/preview/route";
|
||||||
import type { ThumbnailPreviewItem } from "@/app/api/batch-upload/thumbnails/route";
|
import type { ThumbnailPreviewItem } from "@/app/api/batch-upload/thumbnails/route";
|
||||||
|
import type { PlatePreviewItem } from "@/app/api/batch-upload/plates/route";
|
||||||
|
|
||||||
interface Project {
|
interface Project {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -40,6 +43,12 @@ interface UploadState {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Footage plates are large, so they also carry per-file upload progress. */
|
||||||
|
interface PlateUploadState extends UploadState {
|
||||||
|
/** 0–1, only meaningful while status is "uploading" */
|
||||||
|
progress?: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface BatchUploadClientProps {
|
interface BatchUploadClientProps {
|
||||||
projects: Project[];
|
projects: Project[];
|
||||||
}
|
}
|
||||||
@@ -76,6 +85,25 @@ export function BatchUploadClient({ projects }: BatchUploadClientProps) {
|
|||||||
setThumbUploadComplete(false);
|
setThumbUploadComplete(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ── Footage plate upload state ─────────────────────────────────────────────
|
||||||
|
const plateInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [plateFiles, setPlateFiles] = useState<File[]>([]);
|
||||||
|
const [plateIsDragging, setPlateIsDragging] = useState(false);
|
||||||
|
const [platePreview, setPlatePreview] = useState<PlatePreviewItem[] | null>(null);
|
||||||
|
const [plateLoadingPreview, setPlateLoadingPreview] = useState(false);
|
||||||
|
const [plateUploadStates, setPlateUploadStates] = useState<Record<string, PlateUploadState>>({});
|
||||||
|
const [plateIsUploading, setPlateIsUploading] = useState(false);
|
||||||
|
const [plateUploadComplete, setPlateUploadComplete] = useState(false);
|
||||||
|
|
||||||
|
const acceptPlate = (f: File) => PLATE_EXTS.has(f.name.split(".").pop()?.toLowerCase() ?? "");
|
||||||
|
|
||||||
|
const resetPlates = () => {
|
||||||
|
setPlateFiles([]);
|
||||||
|
setPlatePreview(null);
|
||||||
|
setPlateUploadStates({});
|
||||||
|
setPlateUploadComplete(false);
|
||||||
|
};
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
setFiles([]);
|
setFiles([]);
|
||||||
setPreview(null);
|
setPreview(null);
|
||||||
@@ -324,6 +352,136 @@ export function BatchUploadClient({ projects }: BatchUploadClientProps) {
|
|||||||
setThumbUploadComplete(true);
|
setThumbUploadComplete(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ── Footage plate handlers ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const handlePlateDrop = useCallback((e: React.DragEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setPlateIsDragging(false);
|
||||||
|
const dropped = Array.from(e.dataTransfer.files).filter(acceptPlate);
|
||||||
|
if (dropped.length > 0) {
|
||||||
|
setPlateFiles(dropped);
|
||||||
|
setPlatePreview(null);
|
||||||
|
setPlateUploadStates({});
|
||||||
|
setPlateUploadComplete(false);
|
||||||
|
} else {
|
||||||
|
toast({
|
||||||
|
title: "No supported files",
|
||||||
|
description: "Only .mov, .mp4, .mxf, .avi, .mkv and .webm files are accepted.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [toast]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
const handlePlateInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const selected = Array.from(e.target.files ?? []).filter(acceptPlate);
|
||||||
|
if (selected.length > 0) {
|
||||||
|
setPlateFiles(selected);
|
||||||
|
setPlatePreview(null);
|
||||||
|
setPlateUploadStates({});
|
||||||
|
setPlateUploadComplete(false);
|
||||||
|
}
|
||||||
|
e.target.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchPlatePreview = async () => {
|
||||||
|
if (!projectId || plateFiles.length === 0) return;
|
||||||
|
setPlateLoadingPreview(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/batch-upload/plates", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ projectId, fileNames: plateFiles.map((f) => f.name) }),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error("Preview failed");
|
||||||
|
const data = await res.json();
|
||||||
|
setPlatePreview(data.items);
|
||||||
|
const states: Record<string, PlateUploadState> = {};
|
||||||
|
for (const item of data.items as PlatePreviewItem[]) states[item.fileName] = { status: "pending" };
|
||||||
|
setPlateUploadStates(states);
|
||||||
|
} catch {
|
||||||
|
toast({ title: "Preview failed", variant: "destructive" });
|
||||||
|
} finally {
|
||||||
|
setPlateLoadingPreview(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startPlateUpload = async () => {
|
||||||
|
if (!platePreview || !projectId) return;
|
||||||
|
setPlateIsUploading(true);
|
||||||
|
|
||||||
|
const matched = platePreview.filter((i) => i.status === "match");
|
||||||
|
|
||||||
|
for (const item of matched) {
|
||||||
|
const file = plateFiles.find((f) => f.name === item.fileName);
|
||||||
|
if (!file) continue;
|
||||||
|
|
||||||
|
setPlateUploadStates((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[item.fileName]: { status: "uploading", progress: 0 },
|
||||||
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Step 1 — presigned PUT URL. Plates are multi-GB, so the bytes go
|
||||||
|
// straight to Hetzner and never touch this server or the proxy.
|
||||||
|
const presignRes = await fetch("/api/upload/presign", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
fileName: file.name,
|
||||||
|
contentType: plateContentType(file.name),
|
||||||
|
folder: "videos",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!presignRes.ok) {
|
||||||
|
const d = await presignRes.json().catch(() => ({ error: "Failed to get upload URL" }));
|
||||||
|
throw new Error((d as { error?: string }).error ?? "Failed to get upload URL");
|
||||||
|
}
|
||||||
|
const { presignedUrl, key } = (await presignRes.json()) as {
|
||||||
|
presignedUrl: string;
|
||||||
|
key: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 2 — PUT directly to storage, tracking progress via XHR.
|
||||||
|
await putWithProgress(presignedUrl, file, (fraction) => {
|
||||||
|
setPlateUploadStates((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[item.fileName]: { status: "uploading", progress: fraction },
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Step 3 — commit the plate record against the matched shot.
|
||||||
|
const commitRes = await fetch("/api/batch-upload/plates/upload", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
projectId,
|
||||||
|
shotId: item.shotId,
|
||||||
|
key,
|
||||||
|
fileName: file.name,
|
||||||
|
fileSize: file.size,
|
||||||
|
label: item.label,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!commitRes.ok) {
|
||||||
|
const d = await commitRes.json().catch(() => ({ error: "Failed to save plate" }));
|
||||||
|
throw new Error((d as { error?: string }).error ?? "Failed to save plate");
|
||||||
|
}
|
||||||
|
|
||||||
|
setPlateUploadStates((prev) => ({ ...prev, [item.fileName]: { status: "success" } }));
|
||||||
|
} catch (err) {
|
||||||
|
setPlateUploadStates((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[item.fileName]: {
|
||||||
|
status: "error",
|
||||||
|
error: err instanceof Error ? err.message : "Upload failed",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setPlateIsUploading(false);
|
||||||
|
setPlateUploadComplete(true);
|
||||||
|
};
|
||||||
|
|
||||||
// ── Derived counts ─────────────────────────────────────────────────────────
|
// ── Derived counts ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const uploadable = preview?.filter(
|
const uploadable = preview?.filter(
|
||||||
@@ -359,7 +517,11 @@ export function BatchUploadClient({ projects }: BatchUploadClientProps) {
|
|||||||
value={projectId}
|
value={projectId}
|
||||||
onValueChange={(v) => {
|
onValueChange={(v) => {
|
||||||
setProjectId(v);
|
setProjectId(v);
|
||||||
|
// Every preview is resolved against a specific project, so none
|
||||||
|
// of them survive a project switch.
|
||||||
reset();
|
reset();
|
||||||
|
resetThumbs();
|
||||||
|
resetPlates();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-80 bg-zinc-800 border-zinc-700">
|
<SelectTrigger className="w-80 bg-zinc-800 border-zinc-700">
|
||||||
@@ -735,12 +897,260 @@ export function BatchUploadClient({ projects }: BatchUploadClientProps) {
|
|||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
|
|
||||||
|
{/* ── Footage plate bulk upload ───────────────────────────────── */}
|
||||||
|
<div className="border-t border-zinc-800 pt-2">
|
||||||
|
<h2 className="text-base font-semibold text-white">Bulk Footage Plate Upload</h2>
|
||||||
|
<p className="text-zinc-400 text-sm mt-1">
|
||||||
|
Drop plate movies here to add them to a shot's Footage tab. The shot is taken
|
||||||
|
from the start of the filename and the remainder becomes the plate label —{" "}
|
||||||
|
<span className="text-zinc-300 font-mono text-xs">DH2_VFX_058_120_REF.mov</span>{" "}
|
||||||
|
becomes the plate <span className="text-zinc-300">REF</span> on shot{" "}
|
||||||
|
<span className="text-zinc-300 font-mono text-xs">DH2_VFX_058_120</span>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Plate drop zone */}
|
||||||
|
{!plateUploadComplete && (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="pt-5">
|
||||||
|
<div
|
||||||
|
onDragOver={(e) => { e.preventDefault(); setPlateIsDragging(true); }}
|
||||||
|
onDragLeave={() => setPlateIsDragging(false)}
|
||||||
|
onDrop={handlePlateDrop}
|
||||||
|
onClick={() => plateInputRef.current?.click()}
|
||||||
|
className={cn(
|
||||||
|
"border-2 border-dashed rounded-xl p-10 text-center cursor-pointer transition-colors select-none",
|
||||||
|
plateIsDragging
|
||||||
|
? "border-emerald-400 bg-emerald-400/5"
|
||||||
|
: "border-zinc-700 hover:border-zinc-500 hover:bg-zinc-800/30"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Film className="h-9 w-9 text-zinc-500 mx-auto mb-3" />
|
||||||
|
<p className="text-zinc-300 font-medium">Drop footage plates here</p>
|
||||||
|
<p className="text-zinc-500 text-sm mt-1">
|
||||||
|
MOV, MP4, MXF, AVI, MKV, WebM · or click to browse
|
||||||
|
</p>
|
||||||
|
{plateFiles.length > 0 && (
|
||||||
|
<p className="text-emerald-400 text-sm mt-3 font-medium">
|
||||||
|
{plateFiles.length} file{plateFiles.length !== 1 ? "s" : ""} selected
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
ref={plateInputRef}
|
||||||
|
type="file"
|
||||||
|
multiple
|
||||||
|
accept=".mov,.mp4,.m4v,.mxf,.avi,.mkv,.webm,video/*"
|
||||||
|
className="hidden"
|
||||||
|
onChange={handlePlateInput}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{plateFiles.length > 0 && !platePreview && (
|
||||||
|
<div className="mt-4 flex items-center gap-3">
|
||||||
|
<Button onClick={fetchPlatePreview} disabled={plateLoadingPreview}>
|
||||||
|
{plateLoadingPreview ? (
|
||||||
|
<><Loader2 className="h-4 w-4 mr-2 animate-spin" />Loading preview…</>
|
||||||
|
) : (
|
||||||
|
<>Preview<ChevronRight className="h-4 w-4 ml-2" /></>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<Button variant="ghost" onClick={resetPlates} disabled={plateLoadingPreview}>Clear</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Plate preview table */}
|
||||||
|
{platePreview && !plateUploadComplete && (() => {
|
||||||
|
const matched = platePreview.filter((i) => i.status === "match");
|
||||||
|
const skippedPlates = platePreview.filter((i) => i.status !== "match");
|
||||||
|
const dupes = platePreview.filter((i) => i.status === "duplicate");
|
||||||
|
const plateSuccess = Object.values(plateUploadStates).filter((s) => s.status === "success").length;
|
||||||
|
const plateErrors = Object.values(plateUploadStates).filter((s) => s.status === "error").length;
|
||||||
|
const plateDone = plateSuccess + plateErrors;
|
||||||
|
const plateProgress = matched.length > 0 ? (plateDone / matched.length) * 100 : 0;
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="pb-0">
|
||||||
|
<CardTitle className="text-base font-medium text-zinc-200">
|
||||||
|
Footage plate preview —{" "}
|
||||||
|
<span className="text-zinc-400 font-normal">
|
||||||
|
{matched.length} matched · {skippedPlates.length} skipped
|
||||||
|
</span>
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="p-0 mt-4">
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-zinc-800">
|
||||||
|
<th className="text-left text-xs text-zinc-500 font-normal px-6 py-2.5">File</th>
|
||||||
|
<th className="text-left text-xs text-zinc-500 font-normal px-6 py-2.5">Matched Shot</th>
|
||||||
|
<th className="text-left text-xs text-zinc-500 font-normal px-6 py-2.5">Plate label</th>
|
||||||
|
<th className="text-left text-xs text-zinc-500 font-normal px-4 py-2.5 w-32">Status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-zinc-800/60">
|
||||||
|
{platePreview.map((item) => {
|
||||||
|
const state = plateUploadStates[item.fileName];
|
||||||
|
return (
|
||||||
|
<tr key={item.fileName} className="hover:bg-zinc-800/30 transition-colors">
|
||||||
|
<td className="px-6 py-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<FileVideo className="h-4 w-4 text-zinc-500 shrink-0" />
|
||||||
|
<span className="text-zinc-200 font-mono text-xs truncate max-w-[240px]">{item.fileName}</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-3">
|
||||||
|
{item.shotCode ? (
|
||||||
|
<span className="font-mono text-xs text-zinc-300">
|
||||||
|
{item.shotCode}
|
||||||
|
{item.existingPlateCount > 0 && (
|
||||||
|
<span className="text-zinc-600 ml-1.5 font-sans">
|
||||||
|
({item.existingPlateCount} plate{item.existingPlateCount !== 1 ? "s" : ""})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-xs text-zinc-600 italic">
|
||||||
|
{item.status === "unsupported" ? "unsupported file" : "no match"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-3">
|
||||||
|
{item.status === "match" ? (
|
||||||
|
<span className="text-zinc-300 text-xs">{item.label}</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-zinc-700 text-xs">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3">
|
||||||
|
{item.status === "duplicate" ? (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-zinc-500" title="This shot already has a plate with this filename">
|
||||||
|
<XCircle className="h-3.5 w-3.5" />already added
|
||||||
|
</span>
|
||||||
|
) : item.status !== "match" ? (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-zinc-500"><XCircle className="h-3.5 w-3.5" />skip</span>
|
||||||
|
) : !state || state.status === "pending" ? (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-emerald-400"><ArrowRight className="h-3.5 w-3.5" />add plate</span>
|
||||||
|
) : state.status === "uploading" ? (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-amber-400">
|
||||||
|
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||||
|
{Math.round((state.progress ?? 0) * 100)}%
|
||||||
|
</span>
|
||||||
|
) : state.status === "success" ? (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-emerald-400"><CheckCircle2 className="h-3.5 w-3.5" />done</span>
|
||||||
|
) : (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-red-400" title={state.error}><XCircle className="h-3.5 w-3.5" />error</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{plateIsUploading && (
|
||||||
|
<div className="px-6 py-3 border-t border-zinc-800">
|
||||||
|
<div className="flex justify-between text-xs text-zinc-400 mb-1.5">
|
||||||
|
<span>Uploading {Math.min(plateDone + 1, matched.length)} of {matched.length}…</span>
|
||||||
|
<span>{Math.round(plateProgress)}%</span>
|
||||||
|
</div>
|
||||||
|
<Progress value={plateProgress} className="h-1.5" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="px-6 py-4 border-t border-zinc-800 flex items-center justify-between gap-4">
|
||||||
|
<p className="text-zinc-500 text-xs">
|
||||||
|
{matched.length} plate{matched.length !== 1 ? "s" : ""} will be added
|
||||||
|
{skippedPlates.length > 0 && (
|
||||||
|
<span className="text-zinc-600">
|
||||||
|
{" "}· {skippedPlates.length} skipped
|
||||||
|
{dupes.length > 0 && ` (${dupes.length} already uploaded)`}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
<div className="flex gap-3 shrink-0">
|
||||||
|
<Button variant="ghost" size="sm" onClick={resetPlates} disabled={plateIsUploading}>Change files</Button>
|
||||||
|
<Button size="sm" onClick={startPlateUpload} disabled={plateIsUploading || matched.length === 0}>
|
||||||
|
{plateIsUploading ? (
|
||||||
|
<><Loader2 className="h-4 w-4 mr-2 animate-spin" />Uploading…</>
|
||||||
|
) : (
|
||||||
|
`Upload ${matched.length} plate${matched.length !== 1 ? "s" : ""}`
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
|
||||||
|
{/* Plate done summary */}
|
||||||
|
{plateUploadComplete && (() => {
|
||||||
|
const plateSuccess = Object.values(plateUploadStates).filter((s) => s.status === "success").length;
|
||||||
|
const plateErrors = Object.values(plateUploadStates).filter((s) => s.status === "error").length;
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="pt-8 pb-8 flex flex-col items-center gap-4 text-center">
|
||||||
|
<CheckCircle2 className="h-12 w-12 text-green-500" />
|
||||||
|
<div>
|
||||||
|
<p className="text-white font-semibold text-lg">Footage plates uploaded</p>
|
||||||
|
<p className="text-zinc-400 text-sm mt-1">
|
||||||
|
{plateSuccess} added{plateErrors > 0 && <span className="text-red-400"> · {plateErrors} failed</span>}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button variant="outline" onClick={resetPlates} className="mt-2">
|
||||||
|
<RotateCcw className="h-4 w-4 mr-2" />Upload more plates
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Helpers ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT a file to a presigned storage URL, reporting upload progress.
|
||||||
|
*
|
||||||
|
* `fetch` gives no upload progress, and footage plates are big enough that a
|
||||||
|
* silent multi-minute wait per file is unusable — hence XHR.
|
||||||
|
*/
|
||||||
|
function putWithProgress(
|
||||||
|
url: string,
|
||||||
|
file: File,
|
||||||
|
onProgress: (fraction: number) => void
|
||||||
|
): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("PUT", url);
|
||||||
|
xhr.setRequestHeader("Content-Type", plateContentType(file.name));
|
||||||
|
|
||||||
|
xhr.upload.addEventListener("progress", (e) => {
|
||||||
|
if (e.lengthComputable) onProgress(e.loaded / e.total);
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.addEventListener("load", () => {
|
||||||
|
if (xhr.status >= 200 && xhr.status < 300) resolve();
|
||||||
|
else if (xhr.status === 403)
|
||||||
|
reject(new Error("Storage upload failed — check Hetzner CORS / bucket policy"));
|
||||||
|
else reject(new Error(`Storage upload failed (HTTP ${xhr.status})`));
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.addEventListener("error", () => reject(new Error("Network error")));
|
||||||
|
xhr.addEventListener("abort", () => reject(new Error("Upload aborted")));
|
||||||
|
xhr.send(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ── Sub-components ─────────────────────────────────────────────────────────────
|
// ── Sub-components ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function PreviewRow({
|
function PreviewRow({
|
||||||
|
|||||||
@@ -2,8 +2,15 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { ExternalLink, Copy, Check, Trash2, Clock, Film } from "lucide-react";
|
import { ExternalLink, Copy, Check, Trash2, Clock, Film, RotateCcw, Loader2 } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { cn, formatRelativeDate } from "@/lib/utils";
|
import { cn, formatRelativeDate } from "@/lib/utils";
|
||||||
|
|
||||||
@@ -28,9 +35,36 @@ const APP_URL = process.env.NEXT_PUBLIC_APP_URL ?? "";
|
|||||||
export function ReviewSessionList({ sessions }: ReviewSessionListProps) {
|
export function ReviewSessionList({ sessions }: ReviewSessionListProps) {
|
||||||
const [copiedId, setCopiedId] = useState<string | null>(null);
|
const [copiedId, setCopiedId] = useState<string | null>(null);
|
||||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||||
|
const [reactivatingId, setReactivatingId] = useState<string | null>(null);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
// Same token, new expiry — the URL the client already has starts working again.
|
||||||
|
const handleReactivate = async (id: string, days: number) => {
|
||||||
|
setReactivatingId(id);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/review-sessions?id=${id}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ expiresInDays: days }),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const body = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(body.error);
|
||||||
|
}
|
||||||
|
toast({ title: "Review link reactivated", description: `Valid for ${days} more days — same URL.` });
|
||||||
|
router.refresh();
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: "Failed to reactivate link",
|
||||||
|
description: e instanceof Error && e.message ? e.message : undefined,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setReactivatingId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleCopy = async (token: string, id: string) => {
|
const handleCopy = async (token: string, id: string) => {
|
||||||
const url = `${APP_URL}/client/${token}`;
|
const url = `${APP_URL}/client/${token}`;
|
||||||
await navigator.clipboard.writeText(url);
|
await navigator.clipboard.writeText(url);
|
||||||
@@ -122,6 +156,33 @@ export function ReviewSessionList({ sessions }: ReviewSessionListProps) {
|
|||||||
<span className="text-xs text-zinc-500 mr-2">
|
<span className="text-xs text-zinc-500 mr-2">
|
||||||
{session.accessCount} view{session.accessCount !== 1 ? "s" : ""}
|
{session.accessCount} view{session.accessCount !== 1 ? "s" : ""}
|
||||||
</span>
|
</span>
|
||||||
|
{expired && (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
className="h-7 px-2.5 gap-1.5 text-emerald-400 hover:bg-emerald-500/10 border-emerald-500/30"
|
||||||
|
disabled={reactivatingId === session.id}
|
||||||
|
>
|
||||||
|
{reactivatingId === session.id ? (
|
||||||
|
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<RotateCcw className="h-3.5 w-3.5" />
|
||||||
|
)}
|
||||||
|
Reactivate
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuLabel className="text-xs text-zinc-500">Valid for</DropdownMenuLabel>
|
||||||
|
{[7, 14, 30, 60, 90].map((d) => (
|
||||||
|
<DropdownMenuItem key={d} onClick={() => handleReactivate(session.id, d)}>
|
||||||
|
{d} days
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Badge } from "@/components/ui/badge";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { getInitials, formatRelativeDate } from "@/lib/utils";
|
import { getInitials, formatRelativeDate } from "@/lib/utils";
|
||||||
import { frameToTimecode } from "@/lib/frame-utils";
|
import { frameToTimecode } from "@/lib/frame-utils";
|
||||||
|
import { HandleBadge } from "@/components/player/HandleBadge";
|
||||||
import {
|
import {
|
||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
Circle,
|
Circle,
|
||||||
@@ -151,6 +152,7 @@ export function CommentPanel({
|
|||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
{frameToTimecode(activeCommentFrame, fps)}
|
{frameToTimecode(activeCommentFrame, fps)}
|
||||||
</span>
|
</span>
|
||||||
|
<HandleBadge frame={activeCommentFrame} />
|
||||||
</div>
|
</div>
|
||||||
<Textarea
|
<Textarea
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
@@ -348,6 +350,7 @@ function CommentThread({
|
|||||||
>
|
>
|
||||||
F{String(comment.frameNumber).padStart(4, "0")}
|
F{String(comment.frameNumber).padStart(4, "0")}
|
||||||
</button>
|
</button>
|
||||||
|
<HandleBadge frame={comment.frameNumber} />
|
||||||
<span className="text-xs text-muted-foreground ml-auto">
|
<span className="text-xs text-muted-foreground ml-auto">
|
||||||
{formatRelativeDate(comment.createdAt)}
|
{formatRelativeDate(comment.createdAt)}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { format, formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { AwaitingDelivery as AwaitingDeliveryRow } from "@/lib/dashboard/ops";
|
||||||
|
import type { DeliveryRequestView } from "@/lib/render-pipeline/delivery-requests";
|
||||||
|
import { DELIVERABLE_LABEL, type Deliverable } from "@/lib/render-pipeline/delivery-request-state";
|
||||||
|
|
||||||
|
const STAGE_LABEL: Record<AwaitingDeliveryRow["stage"], string> = {
|
||||||
|
AWAITING_UPLOAD: "Not uploaded",
|
||||||
|
AWAITING_SHARE: "Uploaded — link not shared",
|
||||||
|
};
|
||||||
|
|
||||||
|
const SEVERITY_STYLES: Record<AwaitingDeliveryRow["severity"], string> = {
|
||||||
|
normal: "bg-zinc-500/15 text-zinc-300 border-zinc-500/30",
|
||||||
|
warning: "bg-amber-500/15 text-amber-400 border-amber-500/30",
|
||||||
|
critical: "bg-red-500/15 text-red-400 border-red-500/30",
|
||||||
|
};
|
||||||
|
|
||||||
|
const ROW_CLASS =
|
||||||
|
"flex items-center gap-3 border-b border-zinc-800/60 px-4 py-2.5 last:border-b-0 hover:bg-zinc-900/40";
|
||||||
|
const PILL_CLASS = "shrink-0 rounded-full border px-2 py-0.5 text-xs whitespace-nowrap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Everything a client is owed: what they asked for that has not fully gone
|
||||||
|
* out, and built packages they do not have yet. A row only leaves this list
|
||||||
|
* when the upload location and who the link went to are on record (or a
|
||||||
|
* request is cancelled with a reason) — never because time passed or someone
|
||||||
|
* remembers doing it.
|
||||||
|
*/
|
||||||
|
export function AwaitingDelivery({
|
||||||
|
requests,
|
||||||
|
packages,
|
||||||
|
}: {
|
||||||
|
requests: DeliveryRequestView[];
|
||||||
|
packages: AwaitingDeliveryRow[];
|
||||||
|
}) {
|
||||||
|
if (requests.length === 0 && packages.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card px-4 py-4 text-sm text-zinc-500">
|
||||||
|
Nothing is owed to a client.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-amber-500/30 bg-card overflow-hidden">
|
||||||
|
{requests.map((r) => (
|
||||||
|
<Link key={r.id} href="/pipeline/deliveries" className={ROW_CLASS}>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="truncate text-[13px] text-white">
|
||||||
|
<span className="font-medium">Request #{r.requestNumber}</span>{" "}
|
||||||
|
<span className="text-zinc-300">
|
||||||
|
{DELIVERABLE_LABEL[r.deliverable as Deliverable] ?? r.deliverable}
|
||||||
|
{r.episode ? ` for ${r.episode}` : ""}
|
||||||
|
</span>{" "}
|
||||||
|
<span className="text-zinc-500">{r.projectCode}</span>
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-xs text-zinc-500">
|
||||||
|
asked by {r.requestedBy} {formatDistanceToNowStrict(r.createdAt)} ago
|
||||||
|
{r.dueDate ? ` · due ${format(r.dueDate, "d MMM")}` : ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className={cn(PILL_CLASS, SEVERITY_STYLES[r.severity])}>
|
||||||
|
{r.deliveredCount} of {r.lineCount} delivered
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
{packages.map((p) => (
|
||||||
|
<Link key={p.id} href="/pipeline/deliveries" className={ROW_CLASS}>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="truncate text-[13px] text-white">
|
||||||
|
<span className="font-mono font-medium">#{p.packageNumber}</span>{" "}
|
||||||
|
<span className="text-zinc-300">{p.name}</span>{" "}
|
||||||
|
<span className="text-zinc-500">
|
||||||
|
{p.projectCode}
|
||||||
|
{p.episode ? ` · ${p.episode}` : ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-xs text-zinc-500">
|
||||||
|
{p.itemCount} shot{p.itemCount === 1 ? "" : "s"} · built {formatDistanceToNowStrict(p.builtAt)} ago
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className={cn(PILL_CLASS, SEVERITY_STYLES[p.severity])}>{STAGE_LABEL[p.stage]}</span>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { EXPORT_STATUS_STYLES, statusLabel } from "@/app/(dashboard)/pipeline/status-colors";
|
||||||
|
import type { BlockedExport } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exception list: exports that have stopped moving and need a person.
|
||||||
|
*
|
||||||
|
* Read by scanning down the left edge — the severity rail says which rows are
|
||||||
|
* dead in the water (a failed state, which nothing retries) versus merely
|
||||||
|
* overdue (still nominally in flight, or waiting on a QC pass). The reason
|
||||||
|
* column exists so the answer to "what happened" doesn't require opening
|
||||||
|
* anything.
|
||||||
|
*/
|
||||||
|
export function BlockedQueue({ blocked }: { blocked: BlockedExport[] }) {
|
||||||
|
const critical = blocked.filter((b) => b.severity === "critical").length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
{blocked.length === 0
|
||||||
|
? "Nothing blocked"
|
||||||
|
: `${blocked.length} export${blocked.length === 1 ? "" : "s"} stalled`}
|
||||||
|
{critical > 0 && (
|
||||||
|
<span className="ml-2 text-xs font-normal text-red-400">{critical} failed</span>
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<Link href="/pipeline" className="text-xs text-zinc-400 hover:text-amber-400">
|
||||||
|
Open render queue →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{blocked.length === 0 ? (
|
||||||
|
<p className="px-4 py-10 text-center text-sm text-zinc-500">
|
||||||
|
Every export is either moving or done.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-zinc-800 bg-zinc-900/60 text-left text-xs text-zinc-400">
|
||||||
|
<th className="w-[3px] p-0" />
|
||||||
|
<th className="px-4 py-2.5 font-medium">Shot</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Status</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium whitespace-nowrap">Stuck</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Why</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Artist</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{blocked.map((b) => (
|
||||||
|
<tr key={b.exportId} className="border-b border-zinc-800/60 hover:bg-zinc-900/40">
|
||||||
|
<td className="w-[3px] p-0">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"h-9 w-[3px]",
|
||||||
|
b.severity === "critical" ? "bg-red-500" : "bg-amber-500"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5">
|
||||||
|
<Link
|
||||||
|
href={`/pipeline/exports/${b.exportId}`}
|
||||||
|
className="font-mono text-[13px] font-medium text-white hover:text-amber-400"
|
||||||
|
>
|
||||||
|
{b.shotCode}{" "}
|
||||||
|
<span className="text-zinc-500">{b.versionString}</span>
|
||||||
|
</Link>
|
||||||
|
<div className="text-xs text-zinc-500">
|
||||||
|
{b.projectCode}
|
||||||
|
{b.episode ? ` · ep ${b.episode}` : ""}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5">
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"inline-block rounded-full border px-2 py-0.5 text-xs whitespace-nowrap",
|
||||||
|
EXPORT_STATUS_STYLES[b.status] ?? "bg-zinc-500/15 text-zinc-300 border-zinc-500/30"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{statusLabel(b.status)}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
className={cn(
|
||||||
|
"px-4 py-2.5 tabular-nums whitespace-nowrap",
|
||||||
|
b.severity === "critical" ? "text-red-400" : "text-zinc-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{formatDistanceToNowStrict(b.since)}
|
||||||
|
</td>
|
||||||
|
{/* The reason can be an aerender error several lines long;
|
||||||
|
it is clamped here and given in full on hover. */}
|
||||||
|
<td className="px-4 py-2.5 text-zinc-400 max-w-md" title={b.reason}>
|
||||||
|
<span className="line-clamp-2">{b.reason}</span>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 text-zinc-300 whitespace-nowrap">
|
||||||
|
{b.artistName ?? "—"}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { CountdownVerdict, EpisodeCountdown } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we going to make the date? One card per episode, sorted by how soon.
|
||||||
|
*
|
||||||
|
* The bar is the episode's shots by where they actually are, and the row under
|
||||||
|
* it is the only comparison that matters: shots per day still needed against
|
||||||
|
* shots per day the studio has managed this week.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const VERDICT: Record<CountdownVerdict, { rail: string; chip: string; label: string }> = {
|
||||||
|
overdue: { rail: "bg-red-500", chip: "text-red-400 bg-red-500/10", label: "Overdue" },
|
||||||
|
behind: { rail: "bg-red-500", chip: "text-red-400 bg-red-500/10", label: "Behind" },
|
||||||
|
stalled: { rail: "bg-red-500", chip: "text-red-400 bg-red-500/10", label: "Nothing delivered this week" },
|
||||||
|
tight: { rail: "bg-amber-500", chip: "text-amber-400 bg-amber-500/10", label: "No slack" },
|
||||||
|
ahead: { rail: "bg-green-500", chip: "text-green-400 bg-green-500/10", label: "On track" },
|
||||||
|
complete: { rail: "bg-emerald-500", chip: "text-emerald-400 bg-emerald-500/10", label: "All delivered" },
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Two decimals is false precision for a shot count; one is the real resolution. */
|
||||||
|
const perDay = (n: number) => n.toFixed(1);
|
||||||
|
|
||||||
|
export function DeliveryCountdown({ episodes }: { episodes: EpisodeCountdown[] }) {
|
||||||
|
if (episodes.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card px-4 py-8 text-center text-sm text-zinc-500">
|
||||||
|
No delivery dates set. Add them on a project's Episodes tab to see the countdown here.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3">
|
||||||
|
{episodes.map((ep) => {
|
||||||
|
const verdict = VERDICT[ep.verdict];
|
||||||
|
const pct = (n: number) => (ep.total === 0 ? 0 : (n / ep.total) * 100);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={`${ep.projectId}:${ep.episode ?? ""}`}
|
||||||
|
href={`/shot-status?projectId=${ep.projectId}`}
|
||||||
|
className="group relative flex flex-col gap-3.5 overflow-hidden rounded-lg border border-zinc-800 bg-card p-4 pl-[18px] transition-colors hover:border-zinc-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500"
|
||||||
|
>
|
||||||
|
{/* Severity rail — the card itself stays neutral so only the
|
||||||
|
episode in trouble pulls the eye. */}
|
||||||
|
<span className={cn("absolute inset-y-0 left-0 w-[3px]", verdict.rail)} aria-hidden="true" />
|
||||||
|
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="truncate text-[15px] font-semibold text-white">
|
||||||
|
{ep.projectCode}
|
||||||
|
{ep.episode && <span className="font-normal text-zinc-500"> · ep {ep.episode}</span>}
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 text-xs text-zinc-400">
|
||||||
|
Due {format(ep.dueDate, "EEE d MMM yyyy")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="shrink-0 text-right">
|
||||||
|
<b className="block text-3xl font-bold leading-none tabular-nums text-white">
|
||||||
|
{Math.abs(ep.daysLeft)}
|
||||||
|
</b>
|
||||||
|
<small className="text-[11px] uppercase tracking-wide text-zinc-500">
|
||||||
|
{ep.daysLeft < 0 ? "days over" : "days left"}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
className="flex h-2 overflow-hidden rounded-full bg-zinc-800"
|
||||||
|
role="img"
|
||||||
|
aria-label={`${ep.delivered} of ${ep.total} shots delivered, ${ep.inQc} through QC, ${ep.inProgress} in progress`}
|
||||||
|
>
|
||||||
|
<i className="block h-full bg-emerald-500" style={{ width: `${pct(ep.delivered)}%` }} />
|
||||||
|
<i className="block h-full bg-amber-500" style={{ width: `${pct(ep.inQc)}%` }} />
|
||||||
|
<i className="block h-full bg-blue-500" style={{ width: `${pct(ep.inProgress)}%` }} />
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs text-zinc-400">
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-emerald-500" /> {ep.delivered} delivered
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-amber-500" /> {ep.inQc} in QC
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-blue-500" /> {ep.inProgress} in progress
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-zinc-700" /> {ep.notStarted} not started
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between gap-3 border-t border-zinc-800/60 pt-3">
|
||||||
|
<div>
|
||||||
|
<div className="text-[11px] text-zinc-500">Needed / day</div>
|
||||||
|
<div className="font-mono text-[15px] tabular-nums text-white">
|
||||||
|
{perDay(ep.requiredPerDay)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="text-[11px] text-zinc-500">Last 7 days</div>
|
||||||
|
<div className="font-mono text-[15px] tabular-nums text-white">
|
||||||
|
{perDay(ep.actualPerDay)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className={cn("rounded-full px-2.5 py-1 text-xs font-semibold", verdict.chip)}>
|
||||||
|
{ep.verdict === "behind" && ep.daysBehind
|
||||||
|
? `${ep.daysBehind} day${ep.daysBehind === 1 ? "" : "s"} behind`
|
||||||
|
: ep.verdict === "overdue" && ep.daysBehind
|
||||||
|
? `${ep.daysBehind} day${ep.daysBehind === 1 ? "" : "s"} over`
|
||||||
|
: verdict.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { formatEta } from "@/app/(dashboard)/pipeline/status-colors";
|
||||||
|
import type { FarmStatus } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Farm health: who is up, what is waiting, and who is running an old worker.
|
||||||
|
*
|
||||||
|
* The version row is not trivia — a worker's version is what decides whether
|
||||||
|
* it has a given fix, and a machine that quietly stayed behind keeps producing
|
||||||
|
* the bug everyone else has stopped seeing.
|
||||||
|
*/
|
||||||
|
export function FarmStrip({ farm }: { farm: FarmStatus }) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
{farm.online} of {farm.total} online
|
||||||
|
</h3>
|
||||||
|
<Link href="/pipeline/machines" className="text-xs text-zinc-400 hover:text-amber-400">
|
||||||
|
Machines →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{farm.machines.length === 0 ? (
|
||||||
|
<p className="px-4 py-8 text-center text-sm text-zinc-500">
|
||||||
|
No machines have registered yet.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
farm.machines.map((m) => (
|
||||||
|
<div
|
||||||
|
key={m.id}
|
||||||
|
className="flex items-center gap-3 border-b border-zinc-800/60 px-4 py-2.5 last:border-b-0"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"h-2 w-2 shrink-0 rounded-full",
|
||||||
|
m.status === "ONLINE"
|
||||||
|
? "bg-green-500 ring-4 ring-green-500/15"
|
||||||
|
: m.status === "DISABLED"
|
||||||
|
? "bg-zinc-600"
|
||||||
|
: "bg-zinc-500"
|
||||||
|
)}
|
||||||
|
title={m.status}
|
||||||
|
/>
|
||||||
|
<span className="w-24 shrink-0 font-mono text-[12.5px] text-white">{m.name}</span>
|
||||||
|
<span className="min-w-0 flex-1 truncate text-[12.5px] text-zinc-400">
|
||||||
|
{m.currentJob
|
||||||
|
? `${m.currentJob.shotCode ?? "job"} ${m.currentJob.versionString ?? ""} · ${Math.round(
|
||||||
|
(m.currentJob.progress ?? 0) * 100
|
||||||
|
)}% · ETA ${formatEta(m.currentJob.etaSeconds)}`
|
||||||
|
: m.status === "ONLINE"
|
||||||
|
? "Idle"
|
||||||
|
: m.lastSeenAt
|
||||||
|
? `Offline · last seen ${formatDistanceToNowStrict(new Date(m.lastSeenAt))} ago`
|
||||||
|
: "Never seen"}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"shrink-0 font-mono text-[11.5px]",
|
||||||
|
farm.latestWorkerVersion && m.workerVersion !== farm.latestWorkerVersion
|
||||||
|
? "text-amber-400"
|
||||||
|
: "text-zinc-500"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{m.workerVersion ?? "—"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-3 border-t border-zinc-800/60">
|
||||||
|
<div className="border-r border-zinc-800/60 px-4 py-2.5">
|
||||||
|
<b className="block font-mono text-lg font-semibold leading-tight text-white">
|
||||||
|
{farm.queued.render}
|
||||||
|
</b>
|
||||||
|
<small className="text-xs text-zinc-500">renders queued</small>
|
||||||
|
</div>
|
||||||
|
<div className="border-r border-zinc-800/60 px-4 py-2.5">
|
||||||
|
<b className="block font-mono text-lg font-semibold leading-tight text-white">
|
||||||
|
{farm.queued.preview}
|
||||||
|
</b>
|
||||||
|
<small className="text-xs text-zinc-500">previews queued</small>
|
||||||
|
</div>
|
||||||
|
<div className="px-4 py-2.5">
|
||||||
|
<b className="block font-mono text-lg font-semibold leading-tight text-white">
|
||||||
|
{farm.oldestQueuedMs == null
|
||||||
|
? "—"
|
||||||
|
: formatDistanceToNowStrict(new Date(Date.now() - farm.oldestQueuedMs))}
|
||||||
|
</b>
|
||||||
|
<small className="text-xs text-zinc-500">oldest wait</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{farm.behindMachines.length > 0 && (
|
||||||
|
<div className="flex gap-2 border-t border-amber-500/20 bg-amber-500/[0.07] px-4 py-2.5 text-xs text-amber-400">
|
||||||
|
<span aria-hidden="true">▲</span>
|
||||||
|
<span>
|
||||||
|
{farm.behindMachines.length} machine
|
||||||
|
{farm.behindMachines.length === 1 ? " is" : "s are"} behind{" "}
|
||||||
|
<span className="font-mono">{farm.latestWorkerVersion}</span> —{" "}
|
||||||
|
{farm.behindMachines
|
||||||
|
.map((m) => `${m.name} (${m.workerVersion ?? "unknown"})`)
|
||||||
|
.join(", ")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { Plus } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { LogRequestDialog } from "@/components/delivery/LogRequestDialog";
|
||||||
|
|
||||||
|
/** The dashboard's way in to logging what a client just asked for. */
|
||||||
|
export function LogRequestButton() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button size="sm" variant="outline" onClick={() => setOpen(true)}>
|
||||||
|
<Plus className="h-3.5 w-3.5 mr-1.5" />
|
||||||
|
Log request
|
||||||
|
</Button>
|
||||||
|
<LogRequestDialog open={open} onClose={() => setOpen(false)} onLogged={() => router.refresh()} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { QcQueueEntry } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What is waiting on someone to watch the frames, oldest first.
|
||||||
|
*
|
||||||
|
* Everything upstream of QC is worked by the farm; this is the one stage that
|
||||||
|
* only drains when a person sits down to it, which is why depth here is worth
|
||||||
|
* a panel of its own rather than a filter on the queue page.
|
||||||
|
*/
|
||||||
|
export function QcQueue({ entries, staleHours }: { entries: QcQueueEntry[]; staleHours: number }) {
|
||||||
|
const oldest = entries[0];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
{entries.length === 0
|
||||||
|
? "QC queue empty"
|
||||||
|
: `${entries.length} waiting on QC`}
|
||||||
|
{oldest && (
|
||||||
|
<span className="ml-2 text-xs font-normal text-zinc-500">
|
||||||
|
oldest {formatDistanceToNowStrict(oldest.since)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<Link
|
||||||
|
href="/pipeline?status=READY_FOR_QC"
|
||||||
|
className="text-xs text-zinc-400 hover:text-amber-400"
|
||||||
|
>
|
||||||
|
Open QC →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{entries.length === 0 ? (
|
||||||
|
<p className="px-4 py-10 text-center text-sm text-zinc-500">
|
||||||
|
Nothing is waiting on a QC pass.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-zinc-800 bg-zinc-900/60 text-left text-xs text-zinc-400">
|
||||||
|
<th className="px-4 py-2.5 font-medium">Shot</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Version</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Waiting</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Frames</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Submitted by</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{entries.map((e) => {
|
||||||
|
const stale = Date.now() - e.since.getTime() > staleHours * 3600_000;
|
||||||
|
return (
|
||||||
|
<tr key={e.exportId} className="border-b border-zinc-800/60 hover:bg-zinc-900/40">
|
||||||
|
<td className="px-4 py-2.5">
|
||||||
|
<Link
|
||||||
|
href={`/pipeline/exports/${e.exportId}`}
|
||||||
|
className="font-mono text-[13px] font-medium text-white hover:text-amber-400"
|
||||||
|
>
|
||||||
|
{e.shotCode}
|
||||||
|
</Link>
|
||||||
|
<div className="text-xs text-zinc-500">
|
||||||
|
{e.projectCode}
|
||||||
|
{e.episode ? ` · ep ${e.episode}` : ""}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 font-mono text-[13px] text-zinc-300">
|
||||||
|
{e.versionString}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
className={cn(
|
||||||
|
"px-4 py-2.5 tabular-nums whitespace-nowrap",
|
||||||
|
stale ? "text-amber-400" : "text-zinc-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{formatDistanceToNowStrict(e.since)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 font-mono text-[13px] tabular-nums text-zinc-400 whitespace-nowrap">
|
||||||
|
{e.frameStart}–{e.frameEnd}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 text-zinc-300 whitespace-nowrap">
|
||||||
|
{e.submittedBy ?? "—"}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { DELIVERY_STATUS_STYLES } from "@/app/(dashboard)/pipeline/status-colors";
|
||||||
|
import type { DeliverySummary } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last few packages, and whether any of them went wrong.
|
||||||
|
*
|
||||||
|
* A failed build is otherwise silent — the exports stay READY_FOR_DELIVERY and
|
||||||
|
* nothing reaches the delivery volume, but no one finds out until the client
|
||||||
|
* asks where the shots are.
|
||||||
|
*/
|
||||||
|
export function RecentDeliveries({ deliveries }: { deliveries: DeliverySummary[] }) {
|
||||||
|
const problems = deliveries.filter((d) => d.status === "FAILED" || d.stuck).length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
Recent packages
|
||||||
|
{problems > 0 && (
|
||||||
|
<span className="ml-2 text-xs font-normal text-red-400">
|
||||||
|
{problems} need{problems === 1 ? "s" : ""} attention
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<Link href="/pipeline/deliveries" className="text-xs text-zinc-400 hover:text-amber-400">
|
||||||
|
All deliveries →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{deliveries.length === 0 ? (
|
||||||
|
<p className="px-4 py-8 text-center text-sm text-zinc-500">No packages built yet.</p>
|
||||||
|
) : (
|
||||||
|
deliveries.map((d) => (
|
||||||
|
<Link
|
||||||
|
key={d.id}
|
||||||
|
href="/pipeline/deliveries"
|
||||||
|
className="flex items-center gap-3 border-b border-zinc-800/60 px-4 py-2.5 last:border-b-0 hover:bg-zinc-900/40"
|
||||||
|
>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="truncate text-[13px] text-white">
|
||||||
|
<span className="font-mono font-medium">#{d.packageNumber}</span>{" "}
|
||||||
|
<span className="text-zinc-500">
|
||||||
|
{d.projectCode}
|
||||||
|
{d.episode ? ` · ${d.episode}` : ""}
|
||||||
|
{d.kind === "MOV_REVIEW" ? " · review" : ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-xs text-zinc-500" title={d.errorMessage ?? undefined}>
|
||||||
|
{d.status === "FAILED" && d.errorMessage
|
||||||
|
? d.errorMessage
|
||||||
|
: `${d.itemCount} shot${d.itemCount === 1 ? "" : "s"} · ${d.atLabel} ${formatDistanceToNowStrict(d.at)} ago`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"shrink-0 rounded-full border px-2 py-0.5 text-xs whitespace-nowrap",
|
||||||
|
// A build that never finished reads as a problem, not as work
|
||||||
|
// still in progress.
|
||||||
|
d.stuck
|
||||||
|
? "bg-red-500/15 text-red-400 border-red-500/30"
|
||||||
|
: DELIVERY_STATUS_STYLES[d.status] ?? "bg-zinc-500/15 text-zinc-300 border-zinc-500/30"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{d.stuck ? "STUCK" : d.status}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
"use client";
|
import Link from "next/link";
|
||||||
|
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import {
|
import {
|
||||||
Clock,
|
AlertTriangle,
|
||||||
AlertCircle,
|
ClipboardCheck,
|
||||||
CheckCircle2,
|
PackageCheck,
|
||||||
XCircle,
|
Eye,
|
||||||
TrendingUp,
|
TrendingUp,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import type { DashboardStats } from "@/types";
|
import type { DashboardStats } from "@/types";
|
||||||
@@ -15,47 +14,54 @@ interface StatsCardsProps {
|
|||||||
stats: DashboardStats;
|
stats: DashboardStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Five numbers that can go down. Each one links to the page that lists what it
|
||||||
|
* counts — a figure with no way through to the rows behind it is wallpaper.
|
||||||
|
*/
|
||||||
export function StatsCards({ stats }: StatsCardsProps) {
|
export function StatsCards({ stats }: StatsCardsProps) {
|
||||||
const cards = [
|
const cards = [
|
||||||
{
|
{
|
||||||
label: "Awaiting Review",
|
label: "Blocked",
|
||||||
value: stats.awaitingReview,
|
value: stats.blocked,
|
||||||
icon: Clock,
|
href: "#blocked",
|
||||||
color: "text-amber-400",
|
icon: AlertTriangle,
|
||||||
bg: "bg-amber-500/10",
|
|
||||||
ring: "ring-amber-500/20",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Needs Revisions",
|
|
||||||
value: stats.needsRevisions,
|
|
||||||
icon: AlertCircle,
|
|
||||||
color: "text-orange-400",
|
|
||||||
bg: "bg-orange-500/10",
|
|
||||||
ring: "ring-orange-500/20",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Approved",
|
|
||||||
value: stats.approved,
|
|
||||||
icon: CheckCircle2,
|
|
||||||
color: "text-emerald-400",
|
|
||||||
bg: "bg-emerald-500/10",
|
|
||||||
ring: "ring-emerald-500/20",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Overdue Tasks",
|
|
||||||
value: stats.tasksOverdue ?? stats.overdue,
|
|
||||||
icon: XCircle,
|
|
||||||
color: "text-red-400",
|
color: "text-red-400",
|
||||||
bg: "bg-red-500/10",
|
bg: "bg-red-500/10",
|
||||||
ring: "ring-red-500/20",
|
// The only card that earns emphasis when it is non-zero: everything else
|
||||||
|
// here is a queue depth, this one is work that has stopped.
|
||||||
|
emphasise: stats.blocked > 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Active Projects",
|
label: "In QC",
|
||||||
value: stats.activeProjects,
|
value: stats.inQc,
|
||||||
icon: TrendingUp,
|
href: "/pipeline?status=READY_FOR_QC",
|
||||||
|
icon: ClipboardCheck,
|
||||||
|
color: "text-amber-400",
|
||||||
|
bg: "bg-amber-500/10",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Ready to deliver",
|
||||||
|
value: stats.readyToDeliver,
|
||||||
|
href: "/pipeline/deliveries",
|
||||||
|
icon: PackageCheck,
|
||||||
|
color: "text-green-400",
|
||||||
|
bg: "bg-green-500/10",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "With the client",
|
||||||
|
value: stats.awaitingClientReview,
|
||||||
|
href: "/playlist",
|
||||||
|
icon: Eye,
|
||||||
color: "text-blue-400",
|
color: "text-blue-400",
|
||||||
bg: "bg-blue-500/10",
|
bg: "bg-blue-500/10",
|
||||||
ring: "ring-blue-500/20",
|
},
|
||||||
|
{
|
||||||
|
label: "Active projects",
|
||||||
|
value: stats.activeProjects,
|
||||||
|
href: "/projects",
|
||||||
|
icon: TrendingUp,
|
||||||
|
color: "text-zinc-400",
|
||||||
|
bg: "bg-zinc-500/10",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -64,19 +70,31 @@ export function StatsCards({ stats }: StatsCardsProps) {
|
|||||||
{cards.map((card) => {
|
{cards.map((card) => {
|
||||||
const Icon = card.icon;
|
const Icon = card.icon;
|
||||||
return (
|
return (
|
||||||
<Card key={card.label}>
|
<Link key={card.label} href={card.href} className="group rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500">
|
||||||
|
<Card
|
||||||
|
className={cn(
|
||||||
|
"h-full transition-colors group-hover:border-zinc-700",
|
||||||
|
card.emphasise && "border-red-500/40"
|
||||||
|
)}
|
||||||
|
>
|
||||||
<CardContent className="p-4">
|
<CardContent className="p-4">
|
||||||
<div className="flex items-center justify-between mb-3">
|
<div className="flex items-center justify-between mb-3">
|
||||||
<div className={cn("p-2 rounded-md", card.bg)}>
|
<div className={cn("p-2 rounded-md", card.bg)}>
|
||||||
<Icon className={cn("h-4 w-4", card.color)} />
|
<Icon className={cn("h-4 w-4", card.color)} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-3xl font-bold text-white">
|
<p
|
||||||
|
className={cn(
|
||||||
|
"text-3xl font-bold tabular-nums",
|
||||||
|
card.emphasise ? "text-red-400" : "text-white"
|
||||||
|
)}
|
||||||
|
>
|
||||||
{card.value}
|
{card.value}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-zinc-400 mt-0.5">{card.label}</p>
|
<p className="text-sm text-zinc-400 mt-0.5">{card.label}</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
</Link>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import type { WhoseCourt as WhoseCourtData } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which waits are the client's and which are ours.
|
||||||
|
*
|
||||||
|
* Two numbers rather than one, because they call for opposite responses: a
|
||||||
|
* version unanswered for a fortnight is a phone call, while notes nobody has
|
||||||
|
* picked up is a scheduling problem.
|
||||||
|
*/
|
||||||
|
export function WhoseCourt({ court }: { court: WhoseCourtData }) {
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<Side
|
||||||
|
title="Waiting on the client"
|
||||||
|
subtitle="Sent for review, no verdict yet"
|
||||||
|
side={court.client}
|
||||||
|
empty="Nothing is with the client."
|
||||||
|
className="border-b border-zinc-800/60 sm:border-b-0 sm:border-r"
|
||||||
|
/>
|
||||||
|
<Side
|
||||||
|
title="Waiting on us"
|
||||||
|
subtitle="Notes in, still unresolved"
|
||||||
|
side={court.us}
|
||||||
|
empty="No open notes."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Side({
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
side,
|
||||||
|
empty,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
subtitle: string;
|
||||||
|
side: WhoseCourtData["client"];
|
||||||
|
empty: string;
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={`px-4 py-3 ${className ?? ""}`}>
|
||||||
|
<h4 className="text-xs font-semibold text-white">{title}</h4>
|
||||||
|
<p className="text-[11px] text-zinc-500">{subtitle}</p>
|
||||||
|
<b className="mt-2 mb-2 block font-mono text-2xl font-bold leading-none tabular-nums text-white">
|
||||||
|
{side.count}
|
||||||
|
</b>
|
||||||
|
{side.items.length === 0 ? (
|
||||||
|
<p className="text-xs text-zinc-500">{empty}</p>
|
||||||
|
) : (
|
||||||
|
<ul className="flex flex-col gap-1.5">
|
||||||
|
{side.items.map((item) => (
|
||||||
|
<li key={item.id} className="flex items-baseline justify-between gap-3 text-xs">
|
||||||
|
<Link
|
||||||
|
href={item.href}
|
||||||
|
className="truncate font-mono text-[11.5px] text-zinc-200 hover:text-amber-400"
|
||||||
|
>
|
||||||
|
{item.shotCode}
|
||||||
|
</Link>
|
||||||
|
<span className="shrink-0 tabular-nums text-zinc-500">{item.label}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { DELIVERABLES, DELIVERABLE_LABEL, parseShotCodes, type Deliverable } from "@/lib/render-pipeline/delivery-request-state";
|
||||||
|
|
||||||
|
const SELECT_CLASS = "w-full rounded-md border border-zinc-800 bg-zinc-900 px-3 py-2 text-sm text-zinc-200";
|
||||||
|
|
||||||
|
interface ProjectOption {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log what a client asked for. The ask arrives over chat, so this has to be
|
||||||
|
* quicker than deciding to do it later: a project, the shots, who asked.
|
||||||
|
*
|
||||||
|
* With `preset` the shots are already chosen (the shot-status selection);
|
||||||
|
* otherwise they come from an episode or a pasted list of codes.
|
||||||
|
*/
|
||||||
|
export function LogRequestDialog({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onLogged,
|
||||||
|
preset,
|
||||||
|
defaultProjectId,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onLogged: () => void;
|
||||||
|
preset?: { projectId: string; shotIds: string[] };
|
||||||
|
defaultProjectId?: string;
|
||||||
|
}) {
|
||||||
|
const { toast } = useToast();
|
||||||
|
const [projects, setProjects] = useState<ProjectOption[]>([]);
|
||||||
|
const [projectId, setProjectId] = useState("");
|
||||||
|
const [episodes, setEpisodes] = useState<{ episode: string; shotCount: number }[]>([]);
|
||||||
|
const [mode, setMode] = useState<"episode" | "codes">("episode");
|
||||||
|
const [episode, setEpisode] = useState("");
|
||||||
|
const [codes, setCodes] = useState("");
|
||||||
|
const [deliverable, setDeliverable] = useState<Deliverable>("EXR");
|
||||||
|
const [requestedBy, setRequestedBy] = useState("");
|
||||||
|
const [dueDate, setDueDate] = useState("");
|
||||||
|
const [note, setNote] = useState("");
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
setProjectId(preset?.projectId ?? defaultProjectId ?? "");
|
||||||
|
setMode("episode");
|
||||||
|
setEpisode("");
|
||||||
|
setCodes("");
|
||||||
|
setDeliverable("EXR");
|
||||||
|
setRequestedBy("");
|
||||||
|
setDueDate("");
|
||||||
|
setNote("");
|
||||||
|
setError(null);
|
||||||
|
if (preset) return;
|
||||||
|
fetch("/api/projects")
|
||||||
|
.then((res) => (res.ok ? res.json() : { projects: [] }))
|
||||||
|
.then((body) => setProjects((body.projects ?? body) as ProjectOption[]))
|
||||||
|
.catch(() => setProjects([]));
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setEpisodes([]);
|
||||||
|
setEpisode("");
|
||||||
|
if (!open || preset || !projectId) return;
|
||||||
|
let stale = false;
|
||||||
|
fetch(`/api/delivery-requests/options?projectId=${encodeURIComponent(projectId)}`)
|
||||||
|
.then((res) => (res.ok ? res.json() : { episodes: [] }))
|
||||||
|
.then((body) => {
|
||||||
|
if (!stale) setEpisodes(body.episodes ?? []);
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
return () => {
|
||||||
|
stale = true;
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [open, projectId]);
|
||||||
|
|
||||||
|
const codeCount = parseShotCodes(codes).length;
|
||||||
|
const hasShots = preset ? preset.shotIds.length > 0 : mode === "episode" ? Boolean(episode) : codeCount > 0;
|
||||||
|
const canSave = Boolean(projectId) && hasShots && requestedBy.trim().length > 0 && !saving;
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
setSaving(true);
|
||||||
|
setError(null);
|
||||||
|
const res = await fetch("/api/delivery-requests", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
projectId,
|
||||||
|
...(preset ? { shotIds: preset.shotIds } : mode === "episode" ? { episode } : { shotCodes: codes }),
|
||||||
|
deliverable,
|
||||||
|
requestedBy,
|
||||||
|
dueDate: dueDate || null,
|
||||||
|
note: note || null,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const body = await res.json().catch(() => ({}));
|
||||||
|
setSaving(false);
|
||||||
|
if (!res.ok) {
|
||||||
|
// Shown in place rather than as a toast: an unmatched code has to be
|
||||||
|
// fixed in the text right above it.
|
||||||
|
setError(body.error ?? res.statusText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast({
|
||||||
|
title: `Request #${body.request.requestNumber} logged`,
|
||||||
|
description: `${body.request.lineCount} shot${body.request.lineCount === 1 ? "" : "s"} awaiting delivery`,
|
||||||
|
});
|
||||||
|
onLogged();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={(o) => !o && !saving && onClose()}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Log delivery request</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
What the client asked for. It stays under Awaiting delivery until every shot has been uploaded and the
|
||||||
|
link shared.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
{preset ? (
|
||||||
|
<p className="text-sm text-zinc-300">
|
||||||
|
{preset.shotIds.length} selected shot{preset.shotIds.length === 1 ? "" : "s"}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="request-project">Project</Label>
|
||||||
|
<select
|
||||||
|
id="request-project"
|
||||||
|
value={projectId}
|
||||||
|
onChange={(e) => setProjectId(e.target.value)}
|
||||||
|
className={SELECT_CLASS}
|
||||||
|
>
|
||||||
|
<option value="">Select a project…</option>
|
||||||
|
{projects.map((p) => (
|
||||||
|
<option key={p.id} value={p.id}>
|
||||||
|
{p.name} ({p.code})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center gap-4 text-sm text-zinc-200">
|
||||||
|
<label className="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input type="radio" checked={mode === "episode"} onChange={() => setMode("episode")} />
|
||||||
|
Whole episode
|
||||||
|
</label>
|
||||||
|
<label className="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input type="radio" checked={mode === "codes"} onChange={() => setMode("codes")} />
|
||||||
|
Paste shot codes
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{mode === "episode" ? (
|
||||||
|
<select
|
||||||
|
aria-label="Episode"
|
||||||
|
value={episode}
|
||||||
|
onChange={(e) => setEpisode(e.target.value)}
|
||||||
|
disabled={!projectId}
|
||||||
|
className={SELECT_CLASS}
|
||||||
|
>
|
||||||
|
<option value="">{projectId ? "Select an episode…" : "Pick a project first"}</option>
|
||||||
|
{episodes.map((e) => (
|
||||||
|
<option key={e.episode} value={e.episode}>
|
||||||
|
{e.episode} — {e.shotCount} shots
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Textarea
|
||||||
|
aria-label="Shot codes"
|
||||||
|
value={codes}
|
||||||
|
onChange={(e) => setCodes(e.target.value)}
|
||||||
|
rows={4}
|
||||||
|
placeholder="Paste from the client's message — our codes or theirs, any separator"
|
||||||
|
className="font-mono text-xs"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-zinc-500">
|
||||||
|
{codeCount} code{codeCount === 1 ? "" : "s"} found
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="request-deliverable">Wanted</Label>
|
||||||
|
<select
|
||||||
|
id="request-deliverable"
|
||||||
|
value={deliverable}
|
||||||
|
onChange={(e) => setDeliverable(e.target.value as Deliverable)}
|
||||||
|
className={SELECT_CLASS}
|
||||||
|
>
|
||||||
|
{DELIVERABLES.map((d) => (
|
||||||
|
<option key={d} value={d}>
|
||||||
|
{DELIVERABLE_LABEL[d]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="request-due">Due (optional)</Label>
|
||||||
|
<Input
|
||||||
|
id="request-due"
|
||||||
|
type="date"
|
||||||
|
value={dueDate}
|
||||||
|
onChange={(e) => setDueDate(e.target.value)}
|
||||||
|
className="[color-scheme:dark]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="request-by">Asked by</Label>
|
||||||
|
<Input
|
||||||
|
id="request-by"
|
||||||
|
placeholder="Who at the client asked"
|
||||||
|
value={requestedBy}
|
||||||
|
onChange={(e) => setRequestedBy(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="request-note">Note (optional)</Label>
|
||||||
|
<Input id="request-note" value={note} onChange={(e) => setNote(e.target.value)} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <p className="text-sm text-red-400 break-words">{error}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={onClose} disabled={saving}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={save} disabled={!canSave}>
|
||||||
|
Log request
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -12,8 +12,9 @@ import {
|
|||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { NotificationBell } from "@/components/notifications/NotificationBell";
|
import { NotificationBell } from "@/components/notifications/NotificationBell";
|
||||||
import { getInitials } from "@/lib/utils";
|
import { getInitials } from "@/lib/utils";
|
||||||
import { LogOut, User, Settings } from "lucide-react";
|
import { LogOut, User, Settings, Menu } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useMobileNav } from "@/components/layout/MobileNav";
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -23,11 +24,21 @@ interface HeaderProps {
|
|||||||
export function Header({ title, breadcrumbs }: HeaderProps) {
|
export function Header({ title, breadcrumbs }: HeaderProps) {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const user = session?.user;
|
const user = session?.user;
|
||||||
|
const { setOpen: setMobileNavOpen } = useMobileNav();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="flex h-14 items-center justify-between border-b border-zinc-800 bg-zinc-950 px-6">
|
<header className="flex h-14 items-center justify-between border-b border-zinc-800 bg-zinc-950 px-4 md:px-6">
|
||||||
{/* Left: Title / Breadcrumbs */}
|
{/* Left: Title / Breadcrumbs */}
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
|
{/* Phones only: the sidebar is hidden below md and opens as a drawer. */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setMobileNavOpen(true)}
|
||||||
|
className="md:hidden -ml-2 rounded-md p-2 text-zinc-400 hover:bg-zinc-800 hover:text-white"
|
||||||
|
aria-label="Open menu"
|
||||||
|
>
|
||||||
|
<Menu className="h-5 w-5" />
|
||||||
|
</button>
|
||||||
{breadcrumbs ? (
|
{breadcrumbs ? (
|
||||||
<nav className="flex items-center gap-1.5 text-sm">
|
<nav className="flex items-center gap-1.5 text-sm">
|
||||||
{breadcrumbs.map((crumb, i) => (
|
{breadcrumbs.map((crumb, i) => (
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { createContext, useContext, useState } from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open/closed state of the phone-width navigation drawer, shared between the
|
||||||
|
* Header (which has the menu button) and the Sidebar (which is the drawer).
|
||||||
|
* At md and up the sidebar is always visible and this state is unused.
|
||||||
|
*/
|
||||||
|
const MobileNavContext = createContext<{ open: boolean; setOpen: (open: boolean) => void }>({
|
||||||
|
open: false,
|
||||||
|
setOpen: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
export function MobileNavProvider({ children }: { children: React.ReactNode }) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
return <MobileNavContext.Provider value={{ open, setOpen }}>{children}</MobileNavContext.Provider>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useMobileNav = () => useContext(MobileNavContext);
|
||||||
@@ -22,10 +22,12 @@ import {
|
|||||||
Clapperboard,
|
Clapperboard,
|
||||||
LayoutGrid,
|
LayoutGrid,
|
||||||
Server,
|
Server,
|
||||||
|
X,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useSession } from 'next-auth/react';
|
import { useSession } from 'next-auth/react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { useMobileNav } from '@/components/layout/MobileNav';
|
||||||
|
|
||||||
const navItems = [
|
const navItems = [
|
||||||
{ href: '/dashboard', label: 'Dashboard', icon: LayoutDashboard },
|
{ href: '/dashboard', label: 'Dashboard', icon: LayoutDashboard },
|
||||||
@@ -54,17 +56,76 @@ const montserrat = Montserrat({
|
|||||||
|
|
||||||
export function Sidebar() {
|
export function Sidebar() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { data: session } = useSession();
|
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
const isAdmin = ['ADMIN', 'PRODUCER'].includes(session?.user?.role ?? '');
|
const { open: mobileOpen, setOpen: setMobileOpen } = useMobileNav();
|
||||||
|
|
||||||
|
// Picking a page closes the phone drawer; so does Escape.
|
||||||
|
useEffect(() => {
|
||||||
|
setMobileOpen(false);
|
||||||
|
}, [pathname, setMobileOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!mobileOpen) return;
|
||||||
|
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setMobileOpen(false);
|
||||||
|
window.addEventListener('keydown', onKey);
|
||||||
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
|
}, [mobileOpen, setMobileOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{/* md and up: the sidebar exactly as before. */}
|
||||||
<aside
|
<aside
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex flex-col border-r border-zinc-800 bg-zinc-900 transition-all duration-200',
|
'hidden md:flex flex-col border-r border-zinc-800 bg-zinc-900 transition-all duration-200',
|
||||||
collapsed ? 'w-16' : 'w-60',
|
collapsed ? 'w-16' : 'w-60',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
<SidebarContent collapsed={collapsed} />
|
||||||
|
{/* Collapse toggle */}
|
||||||
|
<div className="border-t border-zinc-800 p-2">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
className="w-full"
|
||||||
|
onClick={() => setCollapsed(!collapsed)}
|
||||||
|
title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
||||||
|
>
|
||||||
|
{collapsed ? (
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
{/* Phones: the same navigation as a drawer, opened from the header. */}
|
||||||
|
{mobileOpen && (
|
||||||
|
<div className="fixed inset-0 z-50 md:hidden">
|
||||||
|
<div className="absolute inset-0 bg-black/60" onClick={() => setMobileOpen(false)} />
|
||||||
|
<aside className="absolute inset-y-0 left-0 flex w-64 max-w-[80vw] flex-col overflow-y-auto border-r border-zinc-800 bg-zinc-900">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setMobileOpen(false)}
|
||||||
|
className="absolute right-2 top-2 rounded-md p-2 text-zinc-400 hover:bg-zinc-800 hover:text-white"
|
||||||
|
aria-label="Close menu"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
<SidebarContent collapsed={false} />
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarContent({ collapsed }: { collapsed: boolean }) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const { data: session } = useSession();
|
||||||
|
const isAdmin = ['ADMIN', 'PRODUCER'].includes(session?.user?.role ?? '');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
{/* Logo */}
|
{/* Logo */}
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -119,23 +180,6 @@ export function Sidebar() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
|
</>
|
||||||
{/* Collapse toggle */}
|
|
||||||
<div className="border-t border-zinc-800 p-2">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon-sm"
|
|
||||||
className="w-full"
|
|
||||||
onClick={() => setCollapsed(!collapsed)}
|
|
||||||
title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
|
||||||
>
|
|
||||||
{collapsed ? (
|
|
||||||
<ChevronRight className="h-4 w-4" />
|
|
||||||
) : (
|
|
||||||
<ChevronLeft className="h-4 w-4" />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState, type RefObject } from "react";
|
||||||
|
import {
|
||||||
|
blankingInsets,
|
||||||
|
findAspectPreset,
|
||||||
|
isFullFrame,
|
||||||
|
letterboxRect,
|
||||||
|
type BlankingMode,
|
||||||
|
} from "@/lib/aspect-overlays";
|
||||||
|
|
||||||
|
interface AspectOverlayProps {
|
||||||
|
/** Preset id, or "off" — anything unknown draws nothing. */
|
||||||
|
presetId: string;
|
||||||
|
mode: BlankingMode;
|
||||||
|
videoRef: RefObject<HTMLVideoElement | null>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivery blanking drawn over the video. Purely visual: it never touches the
|
||||||
|
* video element, sits under the annotation canvas, and passes every pointer
|
||||||
|
* event through so click-to-play still works underneath it.
|
||||||
|
*/
|
||||||
|
export function AspectOverlay({ presetId, mode, videoRef }: AspectOverlayProps) {
|
||||||
|
const preset = findAspectPreset(presetId);
|
||||||
|
const [box, setBox] = useState<{
|
||||||
|
top: number;
|
||||||
|
bottom: number;
|
||||||
|
left: number;
|
||||||
|
right: number;
|
||||||
|
rect: { left: number; top: number; width: number; height: number };
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!video || !preset) {
|
||||||
|
setBox(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const measure = () => {
|
||||||
|
const rect = letterboxRect(
|
||||||
|
video.clientWidth,
|
||||||
|
video.clientHeight,
|
||||||
|
video.videoWidth,
|
||||||
|
video.videoHeight
|
||||||
|
);
|
||||||
|
// Before metadata lands videoWidth is 0 and there is nothing to measure.
|
||||||
|
if (!rect) {
|
||||||
|
setBox(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const insets = blankingInsets(rect, preset.ratio);
|
||||||
|
setBox(isFullFrame(insets) ? null : { ...insets, rect });
|
||||||
|
};
|
||||||
|
|
||||||
|
measure();
|
||||||
|
|
||||||
|
// The picture rect moves on layout changes (panel resize, fullscreen) and
|
||||||
|
// on metadata, which is when intrinsic dimensions first exist.
|
||||||
|
const observer = new ResizeObserver(measure);
|
||||||
|
observer.observe(video);
|
||||||
|
video.addEventListener("loadedmetadata", measure);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
observer.disconnect();
|
||||||
|
video.removeEventListener("loadedmetadata", measure);
|
||||||
|
};
|
||||||
|
}, [preset, videoRef]);
|
||||||
|
|
||||||
|
if (!preset || !box) return null;
|
||||||
|
|
||||||
|
const { rect } = box;
|
||||||
|
const barClass =
|
||||||
|
mode === "solid"
|
||||||
|
? "absolute bg-black"
|
||||||
|
: "absolute bg-black/60 ring-1 ring-inset ring-white/25";
|
||||||
|
|
||||||
|
// Each bar is positioned against the picture rect, not the element box, so
|
||||||
|
// blanking lands on the image itself whatever shape the player is.
|
||||||
|
const horizontal = box.top > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
// No z-index: the annotation canvas is also absolutely positioned and comes
|
||||||
|
// later in the DOM, so it stays on top and marks drawn over a blanked area
|
||||||
|
// remain visible.
|
||||||
|
<div
|
||||||
|
className="pointer-events-none absolute inset-0"
|
||||||
|
aria-hidden="true"
|
||||||
|
data-testid="aspect-overlay"
|
||||||
|
>
|
||||||
|
{horizontal ? (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={barClass}
|
||||||
|
style={{ left: rect.left, top: rect.top, width: rect.width, height: box.top }}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className={barClass}
|
||||||
|
style={{
|
||||||
|
left: rect.left,
|
||||||
|
top: rect.top + rect.height - box.bottom,
|
||||||
|
width: rect.width,
|
||||||
|
height: box.bottom,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={barClass}
|
||||||
|
style={{ left: rect.left, top: rect.top, width: box.left, height: rect.height }}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className={barClass}
|
||||||
|
style={{
|
||||||
|
left: rect.left + rect.width - box.right,
|
||||||
|
top: rect.top,
|
||||||
|
width: box.right,
|
||||||
|
height: rect.height,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="absolute bottom-3 right-3 rounded bg-black/70 px-2 py-1 font-mono text-[11px] text-zinc-300">
|
||||||
|
{preset.label}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ interface FrameTimelineProps {
|
|||||||
export function FrameTimeline({ fps, comments, annotations = [], videoRef, onSeek }: FrameTimelineProps) {
|
export function FrameTimeline({ fps, comments, annotations = [], videoRef, onSeek }: FrameTimelineProps) {
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
const isDragging = useRef(false);
|
const isDragging = useRef(false);
|
||||||
const { currentFrame, totalFrames } = useReviewStore();
|
const { currentFrame, totalFrames, editRange } = useReviewStore();
|
||||||
|
|
||||||
const draw = useCallback(() => {
|
const draw = useCallback(() => {
|
||||||
const canvas = canvasRef.current;
|
const canvas = canvasRef.current;
|
||||||
@@ -32,6 +32,42 @@ export function FrameTimeline({ fps, comments, annotations = [], videoRef, onSee
|
|||||||
ctx.fillStyle = "hsl(0 0% 6%)";
|
ctx.fillStyle = "hsl(0 0% 6%)";
|
||||||
ctx.fillRect(0, 0, W, H);
|
ctx.fillRect(0, 0, W, H);
|
||||||
|
|
||||||
|
// Slate and handles — under the ruler so ticks still read across them
|
||||||
|
const regions: { from: number; to: number; kind: "slate" | "handle" }[] = [];
|
||||||
|
if (editRange && totalFrames > 0) {
|
||||||
|
const { pictureStart, cutIn, tailStart, pictureEnd } = editRange;
|
||||||
|
if (pictureStart > 0) regions.push({ from: 0, to: pictureStart, kind: "slate" });
|
||||||
|
if (cutIn > pictureStart) regions.push({ from: pictureStart, to: cutIn, kind: "handle" });
|
||||||
|
if (pictureEnd > tailStart) regions.push({ from: tailStart, to: pictureEnd, kind: "handle" });
|
||||||
|
}
|
||||||
|
const xOf = (f: number) => Math.round((f / totalFrames) * W);
|
||||||
|
for (const r of regions) {
|
||||||
|
const x0 = xOf(r.from);
|
||||||
|
const x1 = xOf(r.to);
|
||||||
|
if (x1 <= x0) continue;
|
||||||
|
if (r.kind === "slate") {
|
||||||
|
ctx.fillStyle = "hsl(0 0% 2%)";
|
||||||
|
ctx.fillRect(x0, 0, x1 - x0, H);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ctx.fillStyle = "hsl(38 92% 50% / 0.14)";
|
||||||
|
ctx.fillRect(x0, 0, x1 - x0, H);
|
||||||
|
// Diagonal hatching, clipped to the region
|
||||||
|
ctx.save();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.rect(x0, 0, x1 - x0, H);
|
||||||
|
ctx.clip();
|
||||||
|
ctx.strokeStyle = "hsl(38 92% 50% / 0.28)";
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
for (let x = x0 - H; x < x1; x += 7) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x, H);
|
||||||
|
ctx.lineTo(x + H, 0);
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
// Frame ruler ticks
|
// Frame ruler ticks
|
||||||
if (totalFrames > 0) {
|
if (totalFrames > 0) {
|
||||||
const tickInterval = Math.max(1, Math.floor(totalFrames / (W / 40)));
|
const tickInterval = Math.max(1, Math.floor(totalFrames / (W / 40)));
|
||||||
@@ -59,6 +95,31 @@ export function FrameTimeline({ fps, comments, annotations = [], videoRef, onSee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Region labels and cut points, over the ruler
|
||||||
|
for (const r of regions) {
|
||||||
|
const x0 = xOf(r.from);
|
||||||
|
const x1 = xOf(r.to);
|
||||||
|
const label = r.kind === "slate" ? "SLATE" : "HANDLE";
|
||||||
|
ctx.font = "bold 9px monospace";
|
||||||
|
if (x1 - x0 >= ctx.measureText(label).width + 8) {
|
||||||
|
ctx.fillStyle = r.kind === "slate" ? "hsl(0 0% 45%)" : "hsl(38 92% 60%)";
|
||||||
|
ctx.textAlign = "center";
|
||||||
|
ctx.fillText(label, (x0 + x1) / 2, H / 2 + 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (editRange && totalFrames > 0) {
|
||||||
|
ctx.strokeStyle = "hsl(38 92% 55%)";
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
for (const f of [editRange.cutIn, editRange.tailStart]) {
|
||||||
|
if (f <= editRange.pictureStart || f >= editRange.pictureEnd) continue;
|
||||||
|
const x = xOf(f) + 0.5;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x, 0);
|
||||||
|
ctx.lineTo(x, H);
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Annotation markers — amber diamonds at top
|
// Annotation markers — amber diamonds at top
|
||||||
const seenAnnotationFrames = new Set<number>();
|
const seenAnnotationFrames = new Set<number>();
|
||||||
annotations.forEach((ann) => {
|
annotations.forEach((ann) => {
|
||||||
@@ -121,7 +182,7 @@ export function FrameTimeline({ fps, comments, annotations = [], videoRef, onSee
|
|||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
}, [currentFrame, totalFrames, comments, annotations]);
|
}, [currentFrame, totalFrames, comments, annotations, editRange]);
|
||||||
|
|
||||||
// Resize observer to match canvas to container
|
// Resize observer to match canvas to container
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useReviewStore } from "@/hooks/use-review-player";
|
||||||
|
import { isHandleFrame } from "@/lib/handles";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "HANDLE" tag for a note left on a handle frame, so whoever picks it up can
|
||||||
|
* see at a glance that it's about a frame outside the edit.
|
||||||
|
*/
|
||||||
|
export function HandleBadge({ frame, className }: { frame: number; className?: string }) {
|
||||||
|
const editRange = useReviewStore((s) => s.editRange);
|
||||||
|
if (!isHandleFrame(editRange, frame)) return null;
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"rounded border border-amber-400/40 bg-amber-400/10 px-1 py-px font-mono text-[9px] font-bold tracking-wide text-amber-400",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
title="This frame is a handle — outside the edit"
|
||||||
|
>
|
||||||
|
HANDLE
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type { FrameRegion } from "@/lib/handles";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags a handle frame on the picture: an amber frame round the player and a
|
||||||
|
* "HANDLE · NOT IN EDIT" tag. Shown only while the playhead is in a handle so
|
||||||
|
* a reviewer can't mistake a glitch there for a problem in the cut.
|
||||||
|
*
|
||||||
|
* Purely a viewing aid over the player — it never reaches the media, passes
|
||||||
|
* every pointer event through, and sits outside the zoom layer so it stays
|
||||||
|
* readable at any zoom.
|
||||||
|
*/
|
||||||
|
export function HandleOverlay({ region }: { region: FrameRegion }) {
|
||||||
|
if (region !== "head" && region !== "tail") return null;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="pointer-events-none absolute inset-0 ring-4 ring-inset ring-amber-400/80"
|
||||||
|
data-testid="handle-overlay"
|
||||||
|
>
|
||||||
|
<div className="absolute left-1/2 top-3 -translate-x-1/2 whitespace-nowrap rounded bg-amber-400 px-2.5 py-1 font-mono text-[11px] font-bold tracking-wide text-black shadow">
|
||||||
|
{region === "head" ? "HEAD" : "TAIL"} HANDLE · NOT IN EDIT
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
Pencil,
|
Pencil,
|
||||||
Eye,
|
Eye,
|
||||||
EyeOff,
|
EyeOff,
|
||||||
|
RectangleHorizontal,
|
||||||
|
Scissors,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -20,9 +22,17 @@ import {
|
|||||||
TooltipContent,
|
TooltipContent,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
import { useReviewStore } from "@/hooks/use-review-player";
|
import { useReviewStore } from "@/hooks/use-review-player";
|
||||||
import { frameToTimecode } from "@/lib/frame-utils";
|
import { frameToTimecode } from "@/lib/frame-utils";
|
||||||
|
import { ASPECT_OFF, ASPECT_PRESETS } from "@/lib/aspect-overlays";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2];
|
const PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2];
|
||||||
@@ -37,6 +47,9 @@ interface PlaybackControlsProps {
|
|||||||
onTogglePlay: () => void;
|
onTogglePlay: () => void;
|
||||||
onToggleFullscreen: () => void;
|
onToggleFullscreen: () => void;
|
||||||
onAddComment: () => void;
|
onAddComment: () => void;
|
||||||
|
/** Current quality, or null when the version has no High quality source. */
|
||||||
|
quality?: "standard" | "high" | null;
|
||||||
|
onQualityChange?: (quality: "standard" | "high") => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PlaybackControls({
|
export function PlaybackControls({
|
||||||
@@ -49,6 +62,8 @@ export function PlaybackControls({
|
|||||||
onTogglePlay,
|
onTogglePlay,
|
||||||
onToggleFullscreen,
|
onToggleFullscreen,
|
||||||
onAddComment,
|
onAddComment,
|
||||||
|
quality = null,
|
||||||
|
onQualityChange,
|
||||||
}: PlaybackControlsProps) {
|
}: PlaybackControlsProps) {
|
||||||
const {
|
const {
|
||||||
isPlaying,
|
isPlaying,
|
||||||
@@ -58,17 +73,35 @@ export function PlaybackControls({
|
|||||||
playbackRate,
|
playbackRate,
|
||||||
isAnnotating,
|
isAnnotating,
|
||||||
showAnnotations,
|
showAnnotations,
|
||||||
|
aspectPresetId,
|
||||||
|
blankingMode,
|
||||||
setPlaybackRate,
|
setPlaybackRate,
|
||||||
setAnnotating,
|
setAnnotating,
|
||||||
setShowAnnotations,
|
setShowAnnotations,
|
||||||
|
setAspectPresetId,
|
||||||
|
setBlankingMode,
|
||||||
|
editRange,
|
||||||
|
editRangeOnly,
|
||||||
|
setEditRangeOnly,
|
||||||
} = useReviewStore();
|
} = useReviewStore();
|
||||||
|
|
||||||
|
// Keeping to the edit, the ends of the transport are the cut points.
|
||||||
|
const keepToEdit = editRangeOnly && !!editRange;
|
||||||
|
const goToFrame = (frame: number) => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!video) return;
|
||||||
|
video.pause();
|
||||||
|
video.currentTime = frame / fps;
|
||||||
|
};
|
||||||
|
|
||||||
const handleRateChange = (val: string) => {
|
const handleRateChange = (val: string) => {
|
||||||
const rate = parseFloat(val);
|
const rate = parseFloat(val);
|
||||||
if (videoRef.current) videoRef.current.playbackRate = rate;
|
if (videoRef.current) videoRef.current.playbackRate = rate;
|
||||||
setPlaybackRate(rate);
|
setPlaybackRate(rate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const blankingOn = aspectPresetId !== ASPECT_OFF;
|
||||||
|
|
||||||
const timecode = frameToTimecode(currentFrame, fps);
|
const timecode = frameToTimecode(currentFrame, fps);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -100,13 +133,14 @@ export function PlaybackControls({
|
|||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
className="text-zinc-400 hover:text-white"
|
className="text-zinc-400 hover:text-white"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (videoRef.current) videoRef.current.currentTime = 0;
|
if (keepToEdit && editRange) goToFrame(editRange.cutIn);
|
||||||
|
else if (videoRef.current) videoRef.current.currentTime = 0;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ChevronFirst className="h-4 w-4" />
|
<ChevronFirst className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>Go to start</TooltipContent>
|
<TooltipContent>{keepToEdit ? "Go to cut in" : "Go to start"}</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
@@ -183,14 +217,15 @@ export function PlaybackControls({
|
|||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
className="text-zinc-400 hover:text-white"
|
className="text-zinc-400 hover:text-white"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (videoRef.current)
|
if (keepToEdit && editRange) goToFrame(editRange.tailStart - 1);
|
||||||
|
else if (videoRef.current)
|
||||||
videoRef.current.currentTime = videoRef.current.duration;
|
videoRef.current.currentTime = videoRef.current.duration;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ChevronLast className="h-4 w-4" />
|
<ChevronLast className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>Go to end</TooltipContent>
|
<TooltipContent>{keepToEdit ? "Go to cut out" : "Go to end"}</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -216,6 +251,111 @@ export function PlaybackControls({
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Delivery blanking — hidden on mobile */}
|
||||||
|
<div className="hidden sm:contents">
|
||||||
|
<Select value={aspectPresetId} onValueChange={setAspectPresetId}>
|
||||||
|
<SelectTrigger
|
||||||
|
className={cn(
|
||||||
|
"h-7 w-24 text-xs border-0 bg-white/5 px-2",
|
||||||
|
blankingOn ? "text-amber-400" : "text-zinc-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value={ASPECT_OFF} className="text-xs">
|
||||||
|
No blanking
|
||||||
|
</SelectItem>
|
||||||
|
<SelectSeparator />
|
||||||
|
{ASPECT_PRESETS.map((p) => (
|
||||||
|
<SelectItem key={p.id} value={p.id} className="text-xs">
|
||||||
|
<span className="font-mono">{p.label}</span>
|
||||||
|
<span className="ml-2 text-zinc-500">{p.note}</span>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
{blankingOn && (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
className={cn(
|
||||||
|
"text-zinc-400 hover:text-white",
|
||||||
|
blankingMode === "guide" && "text-amber-400 bg-amber-400/10"
|
||||||
|
)}
|
||||||
|
onClick={() =>
|
||||||
|
setBlankingMode(blankingMode === "solid" ? "guide" : "solid")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<RectangleHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
{blankingMode === "solid"
|
||||||
|
? "Dim the crop instead of hiding it"
|
||||||
|
: "Hide the crop behind solid bars"}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Quality — only when the version has a High quality source */}
|
||||||
|
{quality && (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className={cn(
|
||||||
|
"h-7 px-1.5 font-mono text-[11px] font-bold tracking-wide",
|
||||||
|
quality === "high"
|
||||||
|
? "text-sky-400 bg-sky-400/10 hover:text-sky-300"
|
||||||
|
: "text-zinc-500 hover:text-white"
|
||||||
|
)}
|
||||||
|
onClick={() => onQualityChange?.(quality === "high" ? "standard" : "high")}
|
||||||
|
aria-pressed={quality === "high"}
|
||||||
|
aria-label="High quality"
|
||||||
|
>
|
||||||
|
HQ
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
{quality === "high"
|
||||||
|
? "High quality — click for Standard (smaller, loads faster)"
|
||||||
|
: "Switch to High quality (full resolution, needs a fast connection)"}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Edit range only — only for versions with handles marked */}
|
||||||
|
{editRange && (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
className={cn(
|
||||||
|
"text-zinc-400 hover:text-white",
|
||||||
|
editRangeOnly && "text-amber-400 bg-amber-400/10"
|
||||||
|
)}
|
||||||
|
onClick={() => setEditRangeOnly(!editRangeOnly)}
|
||||||
|
aria-pressed={editRangeOnly}
|
||||||
|
aria-label="Edit range only"
|
||||||
|
>
|
||||||
|
<Scissors className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
{editRangeOnly
|
||||||
|
? "Playing the edit only — click to include handles"
|
||||||
|
: "Play the edit only (skip handles)"}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Annotation toggle */}
|
{/* Annotation toggle */}
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
|
|||||||
@@ -12,10 +12,15 @@ import {
|
|||||||
import { useReviewStore } from "@/hooks/use-review-player";
|
import { useReviewStore } from "@/hooks/use-review-player";
|
||||||
import { AnnotationCanvas } from "@/components/annotations/AnnotationCanvas";
|
import { AnnotationCanvas } from "@/components/annotations/AnnotationCanvas";
|
||||||
import { AnnotationTools } from "@/components/annotations/AnnotationTools";
|
import { AnnotationTools } from "@/components/annotations/AnnotationTools";
|
||||||
|
import { AspectOverlay } from "./AspectOverlay";
|
||||||
import { FrameTimeline } from "./FrameTimeline";
|
import { FrameTimeline } from "./FrameTimeline";
|
||||||
import { PlaybackControls } from "./PlaybackControls";
|
import { PlaybackControls } from "./PlaybackControls";
|
||||||
|
import { HandleOverlay } from "./HandleOverlay";
|
||||||
|
import { useZoomPan } from "@/hooks/use-zoom-pan";
|
||||||
|
import { Minus, Plus } from "lucide-react";
|
||||||
import { timeToFrame, frameToTime, durationToFrameCount } from "@/lib/frame-utils";
|
import { timeToFrame, frameToTime, durationToFrameCount } from "@/lib/frame-utils";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { computeEditRange, frameRegion, type VersionHandles } from "@/lib/handles";
|
||||||
import type { CommentWithReplies } from "@/types";
|
import type { CommentWithReplies } from "@/types";
|
||||||
|
|
||||||
export interface ReviewPlayerRef {
|
export interface ReviewPlayerRef {
|
||||||
@@ -37,8 +42,17 @@ interface ReviewPlayerProps {
|
|||||||
saveAnnotationFn?: (data: { versionId: string; frameNumber: number; drawingData: unknown; color: string }) => Promise<void>;
|
saveAnnotationFn?: (data: { versionId: string; frameNumber: number; drawingData: unknown; color: string }) => Promise<void>;
|
||||||
/** Override the default server action used to create the companion comment */
|
/** Override the default server action used to create the companion comment */
|
||||||
addCommentFn?: (data: { versionId: string; frameNumber: number; timestamp: number; text: string }) => Promise<void>;
|
addCommentFn?: (data: { versionId: string; frameNumber: number; timestamp: number; text: string }) => Promise<void>;
|
||||||
|
/** The version's handle metadata — frames past the cut get flagged. */
|
||||||
|
handles?: VersionHandles | null;
|
||||||
|
/** Start with playback kept to the edit (the client portal's default). */
|
||||||
|
defaultEditRangeOnly?: boolean;
|
||||||
|
/** High quality source (full res, high bitrate); enables the quality switch. */
|
||||||
|
hqVideoUrl?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PlaybackQuality = "standard" | "high";
|
||||||
|
const QUALITY_KEY = "review:quality";
|
||||||
|
|
||||||
export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
||||||
function ReviewPlayer(
|
function ReviewPlayer(
|
||||||
{
|
{
|
||||||
@@ -52,6 +66,9 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
onAnnotationSaved,
|
onAnnotationSaved,
|
||||||
saveAnnotationFn,
|
saveAnnotationFn,
|
||||||
addCommentFn,
|
addCommentFn,
|
||||||
|
handles,
|
||||||
|
defaultEditRangeOnly = false,
|
||||||
|
hqVideoUrl,
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) {
|
) {
|
||||||
@@ -60,7 +77,45 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
const stableAnnotations = useMemo(() => annotations ?? [], [annotations]);
|
const stableAnnotations = useMemo(() => annotations ?? [], [annotations]);
|
||||||
const videoRef = useRef<HTMLVideoElement>(null);
|
const videoRef = useRef<HTMLVideoElement>(null);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const stageRef = useRef<HTMLDivElement>(null);
|
||||||
|
const zoomLayerRef = useRef<HTMLDivElement>(null);
|
||||||
const reverseIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
const reverseIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||||
|
const openedAtCut = useRef(false);
|
||||||
|
|
||||||
|
// ── Quality ──────────────────────────────────────────────────────────────
|
||||||
|
// Standard is the review MP4; High is the full-res, high-bitrate encode of
|
||||||
|
// the delivery MOV. The choice is a per-browser preference, read after
|
||||||
|
// mount so the server render and the first client render agree.
|
||||||
|
const [quality, setQuality] = useState<PlaybackQuality>("standard");
|
||||||
|
const [switchingQuality, setSwitchingQuality] = useState(false);
|
||||||
|
// Where to pick up once the other source has loaded.
|
||||||
|
const resumeRef = useRef<{ time: number; playing: boolean } | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
if (localStorage.getItem(QUALITY_KEY) === "high") setQuality("high");
|
||||||
|
} catch {
|
||||||
|
// storage blocked — Standard it is
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
const activeSrc = quality === "high" && hqVideoUrl ? hqVideoUrl : videoUrl;
|
||||||
|
|
||||||
|
const changeQuality = useCallback(
|
||||||
|
(next: PlaybackQuality) => {
|
||||||
|
if (next === quality) return;
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (video && video.readyState > 0 && hqVideoUrl) {
|
||||||
|
resumeRef.current = { time: video.currentTime, playing: !video.paused };
|
||||||
|
setSwitchingQuality(true);
|
||||||
|
}
|
||||||
|
setQuality(next);
|
||||||
|
try {
|
||||||
|
localStorage.setItem(QUALITY_KEY, next);
|
||||||
|
} catch {
|
||||||
|
// preference just isn't remembered
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[quality, hqVideoUrl]
|
||||||
|
);
|
||||||
const [isReversing, setIsReversing] = useState(false);
|
const [isReversing, setIsReversing] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -68,14 +123,51 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
currentFrame,
|
currentFrame,
|
||||||
isAnnotating,
|
isAnnotating,
|
||||||
showAnnotations,
|
showAnnotations,
|
||||||
|
aspectPresetId,
|
||||||
|
blankingMode,
|
||||||
setPlaying,
|
setPlaying,
|
||||||
setCurrentFrame,
|
setCurrentFrame,
|
||||||
setCurrentTime,
|
setCurrentTime,
|
||||||
setDuration,
|
setDuration,
|
||||||
setFps,
|
setFps,
|
||||||
setTotalFrames,
|
setTotalFrames,
|
||||||
|
totalFrames,
|
||||||
|
editRange,
|
||||||
|
editRangeOnly,
|
||||||
|
setEditRange,
|
||||||
|
setEditRangeOnly,
|
||||||
} = useReviewStore();
|
} = useReviewStore();
|
||||||
|
|
||||||
|
// ── Handles ──────────────────────────────────────────────────────────────
|
||||||
|
// Where the cut sits in this media. Recomputed from primitives so a parent
|
||||||
|
// re-render with a fresh `handles` object does not churn the store.
|
||||||
|
const handleHead = handles?.handleHead ?? null;
|
||||||
|
const handleTail = handles?.handleTail ?? null;
|
||||||
|
const pictureStartFrame = handles?.pictureStartFrame ?? null;
|
||||||
|
const handleFrameCount = handles?.frameCount ?? null;
|
||||||
|
useEffect(() => {
|
||||||
|
setEditRange(
|
||||||
|
computeEditRange(
|
||||||
|
{ handleHead, handleTail, pictureStartFrame, frameCount: handleFrameCount },
|
||||||
|
totalFrames
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, [handleHead, handleTail, pictureStartFrame, handleFrameCount, totalFrames, setEditRange]);
|
||||||
|
useEffect(() => () => setEditRange(null), [setEditRange]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setEditRangeOnly(defaultEditRangeOnly);
|
||||||
|
}, [defaultEditRangeOnly, setEditRangeOnly]);
|
||||||
|
|
||||||
|
// Read inside event handlers / intervals without re-binding them.
|
||||||
|
const keepToEdit = useRef<{ range: typeof editRange; on: boolean }>({ range: null, on: false });
|
||||||
|
keepToEdit.current = { range: editRange, on: editRangeOnly && !!editRange };
|
||||||
|
|
||||||
|
const zoom = useZoomPan(stageRef, zoomLayerRef, {
|
||||||
|
gesturesEnabled: !isAnnotating,
|
||||||
|
});
|
||||||
|
const { reset: resetZoom, zoomBy } = zoom;
|
||||||
|
|
||||||
// Initialize player config from props
|
// Initialize player config from props
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFps(fps);
|
setFps(fps);
|
||||||
@@ -89,7 +181,11 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
setCurrentTime(0);
|
setCurrentTime(0);
|
||||||
setDuration(0);
|
setDuration(0);
|
||||||
setTotalFrames(0);
|
setTotalFrames(0);
|
||||||
}, [videoUrl, setCurrentFrame, setCurrentTime, setDuration, setTotalFrames]);
|
resetZoom();
|
||||||
|
openedAtCut.current = false;
|
||||||
|
resumeRef.current = null;
|
||||||
|
setSwitchingQuality(false);
|
||||||
|
}, [videoUrl, setCurrentFrame, setCurrentTime, setDuration, setTotalFrames, resetZoom]);
|
||||||
|
|
||||||
// ── Playback state sync ──────────────────────────────────────────────────
|
// ── Playback state sync ──────────────────────────────────────────────────
|
||||||
const handleTimeUpdate = useCallback(() => {
|
const handleTimeUpdate = useCallback(() => {
|
||||||
@@ -106,8 +202,75 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
const frames = durationToFrameCount(video.duration, fps);
|
const frames = durationToFrameCount(video.duration, fps);
|
||||||
setDuration(video.duration);
|
setDuration(video.duration);
|
||||||
setTotalFrames(frames);
|
setTotalFrames(frames);
|
||||||
|
// A new source starts at 1x; keep the speed the reviewer chose.
|
||||||
|
video.playbackRate = useReviewStore.getState().playbackRate;
|
||||||
|
// Quality switch: carry on from the same frame, playing or not.
|
||||||
|
const resume = resumeRef.current;
|
||||||
|
resumeRef.current = null;
|
||||||
|
if (resume) {
|
||||||
|
video.currentTime = resume.time;
|
||||||
|
if (resume.playing) video.play().catch(() => {});
|
||||||
|
}
|
||||||
}, [fps, setDuration, setTotalFrames]);
|
}, [fps, setDuration, setTotalFrames]);
|
||||||
|
|
||||||
|
// High quality failed to load (pruned, or a network hiccup): fall back to
|
||||||
|
// Standard rather than leave a black player. Not remembered as a choice.
|
||||||
|
const handleVideoError = useCallback(() => {
|
||||||
|
if (quality !== "high" || !hqVideoUrl) return;
|
||||||
|
setQuality("standard");
|
||||||
|
}, [quality, hqVideoUrl]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play — when keeping to the edit, from the cut in-point if the playhead
|
||||||
|
* is outside the cut (slate, a handle, or parked on the last cut frame).
|
||||||
|
*/
|
||||||
|
const startPlayback = useCallback(() => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!video) return;
|
||||||
|
const { range, on } = keepToEdit.current;
|
||||||
|
if (on && range) {
|
||||||
|
const frame = timeToFrame(video.currentTime, fps);
|
||||||
|
if (frame < range.cutIn || frame >= range.tailStart - 1) {
|
||||||
|
video.currentTime = frameToTime(range.cutIn, fps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A pause() or power-saving pause before playback starts rejects this;
|
||||||
|
// that's expected, not an error.
|
||||||
|
video.play().catch(() => {});
|
||||||
|
}, [fps]);
|
||||||
|
|
||||||
|
// Keeping to the edit: stop on the last frame of the cut rather than
|
||||||
|
// playing into the tail handle. Checked every animation frame — the
|
||||||
|
// video's own timeupdate only fires ~4x a second.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isPlaying || !editRangeOnly || !editRange) return;
|
||||||
|
const lastCutFrame = editRange.tailStart - 1;
|
||||||
|
let raf = 0;
|
||||||
|
const tick = () => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!video || video.paused) return;
|
||||||
|
if (timeToFrame(video.currentTime, fps) >= editRange.tailStart) {
|
||||||
|
video.pause();
|
||||||
|
video.currentTime = frameToTime(lastCutFrame, fps);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
raf = requestAnimationFrame(tick);
|
||||||
|
};
|
||||||
|
raf = requestAnimationFrame(tick);
|
||||||
|
return () => cancelAnimationFrame(raf);
|
||||||
|
}, [isPlaying, editRangeOnly, editRange, fps]);
|
||||||
|
|
||||||
|
// Keeping to the edit: open on the first frame of the cut rather than on
|
||||||
|
// the slate. Once per video, so it never moves the playhead afterwards.
|
||||||
|
useEffect(() => {
|
||||||
|
const video = videoRef.current;
|
||||||
|
if (!video || openedAtCut.current || !editRangeOnly || !editRange) return;
|
||||||
|
openedAtCut.current = true;
|
||||||
|
if (video.paused && timeToFrame(video.currentTime, fps) < editRange.cutIn) {
|
||||||
|
video.currentTime = frameToTime(editRange.cutIn, fps);
|
||||||
|
}
|
||||||
|
}, [editRange, editRangeOnly, fps]);
|
||||||
|
|
||||||
const handlePlay = useCallback(() => setPlaying(true), [setPlaying]);
|
const handlePlay = useCallback(() => setPlaying(true), [setPlaying]);
|
||||||
const handlePause = useCallback(() => setPlaying(false), [setPlaying]);
|
const handlePause = useCallback(() => setPlaying(false), [setPlaying]);
|
||||||
|
|
||||||
@@ -119,7 +282,7 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
video.currentTime = frameToTime(frame, fps);
|
video.currentTime = frameToTime(frame, fps);
|
||||||
if (!video.paused) video.pause();
|
if (!video.paused) video.pause();
|
||||||
},
|
},
|
||||||
play: () => videoRef.current?.play(),
|
play: () => startPlayback(),
|
||||||
pause: () => videoRef.current?.pause(),
|
pause: () => videoRef.current?.pause(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -150,11 +313,14 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
video.pause();
|
video.pause();
|
||||||
setIsReversing(true);
|
setIsReversing(true);
|
||||||
reverseIntervalRef.current = setInterval(() => {
|
reverseIntervalRef.current = setInterval(() => {
|
||||||
if (!videoRef.current || videoRef.current.currentTime <= 0) {
|
// Keeping to the edit, reverse stops at the cut in-point.
|
||||||
|
const { range, on } = keepToEdit.current;
|
||||||
|
const floor = on && range ? frameToTime(range.cutIn, fps) : 0;
|
||||||
|
if (!videoRef.current || videoRef.current.currentTime <= floor) {
|
||||||
stopReverse();
|
stopReverse();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
videoRef.current.currentTime = Math.max(0, videoRef.current.currentTime - 1 / fps);
|
videoRef.current.currentTime = Math.max(floor, videoRef.current.currentTime - 1 / fps);
|
||||||
}, 1000 / fps);
|
}, 1000 / fps);
|
||||||
}, [fps, stopReverse]);
|
}, [fps, stopReverse]);
|
||||||
|
|
||||||
@@ -163,11 +329,11 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
if (!video) return;
|
if (!video) return;
|
||||||
stopReverse();
|
stopReverse();
|
||||||
if (video.paused) {
|
if (video.paused) {
|
||||||
video.play();
|
startPlayback();
|
||||||
} else {
|
} else {
|
||||||
video.pause();
|
video.pause();
|
||||||
}
|
}
|
||||||
}, [stopReverse]);
|
}, [stopReverse, startPlayback]);
|
||||||
|
|
||||||
// ── Keyboard shortcuts (JKL + arrows + space + F) ───────────────────────
|
// ── Keyboard shortcuts (JKL + arrows + space + F) ───────────────────────
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -200,7 +366,7 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
case "l":
|
case "l":
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
stopReverse();
|
stopReverse();
|
||||||
if (videoRef.current?.paused) videoRef.current.play();
|
if (videoRef.current?.paused) startPlayback();
|
||||||
break;
|
break;
|
||||||
case "arrowleft":
|
case "arrowleft":
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -219,15 +385,31 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
toggleFullscreen();
|
toggleFullscreen();
|
||||||
break;
|
break;
|
||||||
|
case "=":
|
||||||
|
case "+":
|
||||||
|
e.preventDefault();
|
||||||
|
zoomBy(1.25);
|
||||||
|
break;
|
||||||
|
case "-":
|
||||||
|
case "_":
|
||||||
|
e.preventDefault();
|
||||||
|
zoomBy(0.8);
|
||||||
|
break;
|
||||||
|
case "0":
|
||||||
|
e.preventDefault();
|
||||||
|
resetZoom();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("keydown", handleKeyDown);
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
return () => {
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||||
window.removeEventListener("keydown", handleKeyDown);
|
}, [isReversing, stepFrame, startReverse, stopReverse, togglePlayback, startPlayback, zoomBy, resetZoom]);
|
||||||
stopReverse();
|
|
||||||
};
|
// Stop a running reverse only on unmount. This used to live in the
|
||||||
}, [isReversing, stepFrame, startReverse, stopReverse, togglePlayback]);
|
// cleanup above, which re-runs whenever isReversing changes — so starting
|
||||||
|
// reverse immediately stopped it, and J never did anything.
|
||||||
|
useEffect(() => stopReverse, [stopReverse]);
|
||||||
|
|
||||||
// ── Fullscreen ───────────────────────────────────────────────────────────
|
// ── Fullscreen ───────────────────────────────────────────────────────────
|
||||||
const toggleFullscreen = () => {
|
const toggleFullscreen = () => {
|
||||||
@@ -266,26 +448,54 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* Video — tap anywhere to play/pause (pointer-events pass through canvas when not annotating) */}
|
{/* Video — tap anywhere to play/pause (pointer-events pass through canvas when not annotating).
|
||||||
|
Wheel / pinch zooms, drag pans when zoomed; a drag never counts as a tap. */}
|
||||||
<div
|
<div
|
||||||
|
ref={stageRef}
|
||||||
className="relative flex-1 min-h-0 overflow-hidden"
|
className="relative flex-1 min-h-0 overflow-hidden"
|
||||||
onClick={!isAnnotating ? togglePlayback : undefined}
|
style={zoom.stageStyle}
|
||||||
|
{...zoom.stageHandlers}
|
||||||
|
onClick={
|
||||||
|
!isAnnotating
|
||||||
|
? () => {
|
||||||
|
if (!zoom.consumeDrag()) togglePlayback();
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{/* Zoomed as one layer so blanking and annotations stay pinned to the
|
||||||
|
picture — annotation coords are normalised from the canvas's
|
||||||
|
transformed bounding rect, so drawing while zoomed lands correctly. */}
|
||||||
|
<div
|
||||||
|
ref={zoomLayerRef}
|
||||||
|
className="absolute inset-0 origin-top-left will-change-transform"
|
||||||
>
|
>
|
||||||
<video
|
<video
|
||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
src={videoUrl}
|
src={activeSrc}
|
||||||
className="block w-full h-full object-contain"
|
className="block w-full h-full object-contain"
|
||||||
onTimeUpdate={handleTimeUpdate}
|
onTimeUpdate={handleTimeUpdate}
|
||||||
onLoadedMetadata={handleLoadedMetadata}
|
onLoadedMetadata={handleLoadedMetadata}
|
||||||
onPlay={handlePlay}
|
onPlay={handlePlay}
|
||||||
onPause={handlePause}
|
onPause={handlePause}
|
||||||
|
onCanPlay={() => setSwitchingQuality(false)}
|
||||||
|
onError={handleVideoError}
|
||||||
preload="metadata"
|
preload="metadata"
|
||||||
playsInline
|
playsInline
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Delivery blanking — under the annotation canvas, so a reviewer
|
||||||
|
can still draw over a blanked area if they need to */}
|
||||||
|
<AspectOverlay
|
||||||
|
presetId={aspectPresetId}
|
||||||
|
mode={blankingMode}
|
||||||
|
videoRef={videoRef}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Annotation canvas overlay */}
|
{/* Annotation canvas overlay */}
|
||||||
<AnnotationCanvas
|
<AnnotationCanvas
|
||||||
versionId={versionId}
|
versionId={versionId}
|
||||||
|
videoRef={videoRef}
|
||||||
frameNumber={currentFrame}
|
frameNumber={currentFrame}
|
||||||
fps={fps}
|
fps={fps}
|
||||||
isAnnotating={isAnnotating && !isPlaying}
|
isAnnotating={isAnnotating && !isPlaying}
|
||||||
@@ -295,6 +505,52 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
saveAnnotationFn={saveAnnotationFn as any}
|
saveAnnotationFn={saveAnnotationFn as any}
|
||||||
addCommentFn={addCommentFn}
|
addCommentFn={addCommentFn}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Handle flag — drawn over the player, never into the media */}
|
||||||
|
<HandleOverlay region={frameRegion(editRange, currentFrame)} />
|
||||||
|
|
||||||
|
{/* Zoom badge — only while zoomed */}
|
||||||
|
{zoom.zoomed && (
|
||||||
|
<div
|
||||||
|
className="absolute top-3 right-3 flex items-center gap-0.5 rounded bg-black/70 p-0.5 text-xs text-white"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
onPointerDown={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded p-1.5 hover:bg-white/15"
|
||||||
|
onClick={() => zoomBy(0.8)}
|
||||||
|
aria-label="Zoom out"
|
||||||
|
>
|
||||||
|
<Minus className="h-3.5 w-3.5" />
|
||||||
|
</button>
|
||||||
|
<span className="w-10 text-center font-mono tabular-nums">
|
||||||
|
{Math.round(zoom.scale * 100)}%
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded p-1.5 hover:bg-white/15"
|
||||||
|
onClick={() => zoomBy(1.25)}
|
||||||
|
aria-label="Zoom in"
|
||||||
|
>
|
||||||
|
<Plus className="h-3.5 w-3.5" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded px-2 py-1 hover:bg-white/15"
|
||||||
|
onClick={resetZoom}
|
||||||
|
>
|
||||||
|
Fit
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{switchingQuality && (
|
||||||
|
<div className="pointer-events-none absolute bottom-3 left-3 rounded bg-black/70 px-2 py-1 text-xs text-white">
|
||||||
|
Loading {quality === "high" ? "high" : "standard"} quality…
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* JKL hint overlay — shown briefly when reversing */}
|
{/* JKL hint overlay — shown briefly when reversing */}
|
||||||
{isReversing && (
|
{isReversing && (
|
||||||
@@ -327,6 +583,8 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
|||||||
onTogglePlay={togglePlayback}
|
onTogglePlay={togglePlayback}
|
||||||
onToggleFullscreen={toggleFullscreen}
|
onToggleFullscreen={toggleFullscreen}
|
||||||
onAddComment={handleAddComment}
|
onAddComment={handleAddComment}
|
||||||
|
quality={hqVideoUrl ? quality : null}
|
||||||
|
onQualityChange={changeQuality}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,842 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seamless playlist playback: plays the cut of each clip back to back — no
|
||||||
|
* slate, no handles — without the gap of loading one video after another.
|
||||||
|
*
|
||||||
|
* Two <video> elements are stacked. While one plays, the other has the next
|
||||||
|
* clip loaded and parked on its cut in-point; on the cut out-point they swap.
|
||||||
|
* The out-point is caught with requestVideoFrameCallback (per presented
|
||||||
|
* frame) where the browser has it, else every animation frame.
|
||||||
|
*
|
||||||
|
* The media is never changed: the cut comes from the version's handle and
|
||||||
|
* slate metadata (lib/handles.ts), as in the review player.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { cutSpan, type FrameSpan, type VersionHandles } from "@/lib/handles";
|
||||||
|
import { durationToFrameCount, frameToTime, frameToTimecode, timeToFrame } from "@/lib/frame-utils";
|
||||||
|
import {
|
||||||
|
ChevronFirst,
|
||||||
|
ChevronLast,
|
||||||
|
Loader2,
|
||||||
|
Pause,
|
||||||
|
Play,
|
||||||
|
Repeat,
|
||||||
|
Volume2,
|
||||||
|
VolumeX,
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
|
export interface SequenceClip {
|
||||||
|
/** Version id. */
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
sublabel?: string;
|
||||||
|
url: string;
|
||||||
|
hqUrl?: string | null;
|
||||||
|
fps: number;
|
||||||
|
/** Media duration in seconds, if known — sizes the timeline before loading. */
|
||||||
|
duration?: number | null;
|
||||||
|
handles: VersionHandles;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SequencePlayerProps {
|
||||||
|
clips: SequenceClip[];
|
||||||
|
/** Called with the clip now on screen. */
|
||||||
|
onClipChange?: (clip: SequenceClip, index: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Slot = 0 | 1;
|
||||||
|
|
||||||
|
interface Loaded {
|
||||||
|
index: number;
|
||||||
|
url: string;
|
||||||
|
/** Media frame it is parked on, once seeked. */
|
||||||
|
parkedAt?: number;
|
||||||
|
/** Its cut in-point, once the media length is known. */
|
||||||
|
cutIn?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Seek a quarter frame in so float error can't land on the previous frame. */
|
||||||
|
const SEEK_BIAS = 0.25;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The next clip waits this many frames before its cut in (handle or slate —
|
||||||
|
* hidden anyway) so it's already running, past the stutter of a video
|
||||||
|
* starting up, when it comes on screen. Clips with less lead-in (a 1-frame
|
||||||
|
* slate, no handles) pre-roll what they have.
|
||||||
|
*/
|
||||||
|
const PREROLL_FRAMES = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long before its pre-roll frames the next clip must start. Chrome counts
|
||||||
|
* the parked frame as shown the moment play() is called, so ~0; calibrated at
|
||||||
|
* every cut for browsers that differ.
|
||||||
|
*/
|
||||||
|
const INITIAL_START_LATENCY_MS = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hold off loading the clip after next until the cut has settled: loading
|
||||||
|
* one video while another starts playing made the incoming clip drop a frame.
|
||||||
|
*/
|
||||||
|
const PRELOAD_DELAY_MS = 300;
|
||||||
|
|
||||||
|
function estimatedSpan(clip: SequenceClip): FrameSpan {
|
||||||
|
const total =
|
||||||
|
clip.duration && clip.duration > 0
|
||||||
|
? durationToFrameCount(clip.duration, clip.fps)
|
||||||
|
: (clip.handles.frameCount ?? 0) + 1;
|
||||||
|
return cutSpan(clip.handles, total) ?? { start: 0, end: Math.max(1, total) };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SequencePlayer({ clips, onClipChange }: SequencePlayerProps) {
|
||||||
|
const videoRefs = [useRef<HTMLVideoElement>(null), useRef<HTMLVideoElement>(null)];
|
||||||
|
const loaded = useRef<[Loaded | null, Loaded | null]>([null, null]);
|
||||||
|
/** Real spans, filled in as each clip's metadata arrives. */
|
||||||
|
const spans = useRef(new Map<string, FrameSpan>());
|
||||||
|
|
||||||
|
const [active, setActive] = useState<Slot>(0);
|
||||||
|
const activeRef = useRef<Slot>(0);
|
||||||
|
const [index, setIndex] = useState(0);
|
||||||
|
const indexRef = useRef(0);
|
||||||
|
const [frame, setFrame] = useState(0); // frame within the active media
|
||||||
|
const [playing, setPlaying] = useState(false);
|
||||||
|
const playingRef = useRef(false);
|
||||||
|
const [buffering, setBuffering] = useState(false);
|
||||||
|
const [loop, setLoop] = useState(true);
|
||||||
|
const loopRef = useRef(true);
|
||||||
|
loopRef.current = loop;
|
||||||
|
const [muted, setMuted] = useState(true);
|
||||||
|
const [hq, setHq] = useState(false);
|
||||||
|
const [spanVersion, bumpSpans] = useState(0);
|
||||||
|
/** The latest load into each slot; an older load's listeners stand down. */
|
||||||
|
const slotToken = useRef<[object | null, object | null]>([null, null]);
|
||||||
|
/** The clip on screen, by id, to stay on when the clip list changes. */
|
||||||
|
const shownId = useRef<string | null>(null);
|
||||||
|
/** Bumped on every goTo so a superseded load stops acting. */
|
||||||
|
const generation = useRef(0);
|
||||||
|
/** The slot a goTo is loading into, until its clip is on screen. */
|
||||||
|
const jumpingInto = useRef<Slot | null>(null);
|
||||||
|
/** How much earlier than its pre-roll frames the next clip must start. */
|
||||||
|
const startLatency = useRef(INITIAL_START_LATENCY_MS);
|
||||||
|
|
||||||
|
const srcFor = useCallback(
|
||||||
|
(clip: SequenceClip) => (hq && clip.hqUrl ? clip.hqUrl : clip.url),
|
||||||
|
[hq]
|
||||||
|
);
|
||||||
|
const srcForRef = useRef(srcFor);
|
||||||
|
srcForRef.current = srcFor;
|
||||||
|
|
||||||
|
const spanOf = useCallback(
|
||||||
|
(i: number) => spans.current.get(clips[i].id) ?? estimatedSpan(clips[i]),
|
||||||
|
[clips]
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load clip `i` into a slot and park it on `frameInMedia` (default: its cut
|
||||||
|
* in, less `preroll` frames). Resolves false if superseded or the media failed.
|
||||||
|
*/
|
||||||
|
const prepare = useCallback(
|
||||||
|
(slot: Slot, i: number, frameInMedia?: number, preroll = 0): Promise<boolean> => {
|
||||||
|
const video = videoRefs[slot].current;
|
||||||
|
const clip = clips[i];
|
||||||
|
if (!video || !clip) return Promise.resolve(false);
|
||||||
|
const url = srcForRef.current(clip);
|
||||||
|
const gen = generation.current;
|
||||||
|
const token = {};
|
||||||
|
slotToken.current[slot] = token;
|
||||||
|
|
||||||
|
return new Promise<boolean>((resolve) => {
|
||||||
|
const superseded = () => {
|
||||||
|
if (slotToken.current[slot] === token) return false;
|
||||||
|
cleanup();
|
||||||
|
resolve(false);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
const cleanup = () => {
|
||||||
|
video.removeEventListener("loadedmetadata", onMeta);
|
||||||
|
video.removeEventListener("seeked", onSeeked);
|
||||||
|
video.removeEventListener("error", onError);
|
||||||
|
};
|
||||||
|
const onError = () => {
|
||||||
|
if (superseded()) return;
|
||||||
|
cleanup();
|
||||||
|
resolve(false);
|
||||||
|
};
|
||||||
|
const onSeeked = () => {
|
||||||
|
if (superseded()) return;
|
||||||
|
cleanup();
|
||||||
|
resolve(gen === generation.current);
|
||||||
|
};
|
||||||
|
const seek = () => {
|
||||||
|
const total = durationToFrameCount(video.duration, clip.fps);
|
||||||
|
const span = cutSpan(clip.handles, total);
|
||||||
|
if (span) spans.current.set(clip.id, span);
|
||||||
|
const cutIn = span?.start ?? 0;
|
||||||
|
const target = frameInMedia ?? Math.max(0, cutIn - preroll);
|
||||||
|
const entry = loaded.current[slot];
|
||||||
|
if (entry) {
|
||||||
|
entry.cutIn = cutIn;
|
||||||
|
entry.parkedAt = target;
|
||||||
|
}
|
||||||
|
video.addEventListener("seeked", onSeeked);
|
||||||
|
video.currentTime = frameToTime(target + SEEK_BIAS, clip.fps);
|
||||||
|
};
|
||||||
|
const onMeta = () => {
|
||||||
|
if (superseded()) return;
|
||||||
|
video.removeEventListener("loadedmetadata", onMeta);
|
||||||
|
bumpSpans((n) => n + 1);
|
||||||
|
seek();
|
||||||
|
};
|
||||||
|
|
||||||
|
video.addEventListener("error", onError);
|
||||||
|
const current = loaded.current[slot];
|
||||||
|
if (current && current.url === url && video.readyState >= 1) {
|
||||||
|
loaded.current[slot] = { index: i, url };
|
||||||
|
seek();
|
||||||
|
} else {
|
||||||
|
loaded.current[slot] = { index: i, url };
|
||||||
|
video.addEventListener("loadedmetadata", onMeta);
|
||||||
|
video.src = url;
|
||||||
|
video.load();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// videoRefs are stable refs
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[clips]
|
||||||
|
);
|
||||||
|
|
||||||
|
const nextIndex = useCallback(
|
||||||
|
(i: number) => (i + 1 < clips.length ? i + 1 : loopRef.current ? 0 : null),
|
||||||
|
[clips.length]
|
||||||
|
);
|
||||||
|
|
||||||
|
const preloadNext = useCallback(
|
||||||
|
(fromIndex: number) => {
|
||||||
|
const n = nextIndex(fromIndex);
|
||||||
|
if (n == null) return;
|
||||||
|
const standby = (1 - activeRef.current) as Slot;
|
||||||
|
// A jump is loading its clip there; it preloads the next one itself
|
||||||
|
// once it's on screen. Loading over it would leave the screen black.
|
||||||
|
if (jumpingInto.current === standby) return;
|
||||||
|
void prepare(standby, n, undefined, PREROLL_FRAMES);
|
||||||
|
},
|
||||||
|
[nextIndex, prepare]
|
||||||
|
);
|
||||||
|
|
||||||
|
const show = useCallback(
|
||||||
|
(slot: Slot, i: number) => {
|
||||||
|
activeRef.current = slot;
|
||||||
|
indexRef.current = i;
|
||||||
|
setActive(slot);
|
||||||
|
setIndex(i);
|
||||||
|
// Straight on the DOM, not via a re-render: a render later, the outgoing
|
||||||
|
// clip would already have painted a frame past its cut.
|
||||||
|
const other = videoRefs[1 - slot].current;
|
||||||
|
if (other) {
|
||||||
|
other.pause();
|
||||||
|
other.muted = true;
|
||||||
|
other.style.opacity = "0";
|
||||||
|
}
|
||||||
|
const video = videoRefs[slot].current;
|
||||||
|
if (video) {
|
||||||
|
video.style.opacity = "1";
|
||||||
|
video.muted = muted;
|
||||||
|
setFrame(timeToFrame(video.currentTime, clips[i].fps));
|
||||||
|
}
|
||||||
|
shownId.current = clips[i].id;
|
||||||
|
onClipChange?.(clips[i], i);
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[clips, muted, onClipChange]
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Jump to clip `i` (at a media frame, default its cut in). */
|
||||||
|
const goTo = useCallback(
|
||||||
|
async (i: number, frameInMedia?: number, autoplay = playingRef.current) => {
|
||||||
|
if (!clips[i]) return;
|
||||||
|
generation.current += 1;
|
||||||
|
const gen = generation.current;
|
||||||
|
// Always via the hidden slot: the picture on screen stays put while the
|
||||||
|
// clip loads (loading into the visible slot flashed its slate), and when
|
||||||
|
// it already holds this clip — usually the next one — it's just a seek.
|
||||||
|
// A seek within the clip on screen stays where it is.
|
||||||
|
const onScreen = loaded.current[activeRef.current];
|
||||||
|
const slot =
|
||||||
|
onScreen?.index === i && onScreen.url === srcForRef.current(clips[i])
|
||||||
|
? activeRef.current
|
||||||
|
: ((1 - activeRef.current) as Slot);
|
||||||
|
videoRefs[0].current?.pause();
|
||||||
|
videoRefs[1].current?.pause();
|
||||||
|
setBuffering(true);
|
||||||
|
jumpingInto.current = slot;
|
||||||
|
const ok = await prepare(slot, i, frameInMedia);
|
||||||
|
if (gen !== generation.current) return;
|
||||||
|
jumpingInto.current = null;
|
||||||
|
setBuffering(false);
|
||||||
|
if (!ok) return;
|
||||||
|
show(slot, i);
|
||||||
|
if (autoplay) {
|
||||||
|
playingRef.current = true;
|
||||||
|
setPlaying(true);
|
||||||
|
videoRefs[slot].current?.play().catch(() => {});
|
||||||
|
}
|
||||||
|
preloadNext(i);
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[clips, prepare, show, preloadNext]
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Put the (already playing) standby clip on screen. */
|
||||||
|
const cutTo = useCallback(
|
||||||
|
(slot: Slot, i: number) => {
|
||||||
|
videoRefs[1 - slot].current?.pause();
|
||||||
|
show(slot, i);
|
||||||
|
setTimeout(() => {
|
||||||
|
if (indexRef.current === i && activeRef.current === slot) preloadNext(i);
|
||||||
|
}, PRELOAD_DELAY_MS);
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[show, preloadNext]
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cut to the next clip now — the fallback when it wasn't pre-rolled (no
|
||||||
|
* requestVideoFrameCallback, or it wasn't loaded in time).
|
||||||
|
*/
|
||||||
|
const advance = useCallback(async () => {
|
||||||
|
const i = indexRef.current;
|
||||||
|
const n = nextIndex(i);
|
||||||
|
const slot = activeRef.current;
|
||||||
|
const current = videoRefs[slot].current;
|
||||||
|
if (n == null) {
|
||||||
|
// End of the playlist: hold the last frame of the cut.
|
||||||
|
current?.pause();
|
||||||
|
if (current) current.currentTime = frameToTime(spanOf(i).end - 1 + SEEK_BIAS, clips[i].fps);
|
||||||
|
playingRef.current = false;
|
||||||
|
setPlaying(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const standby = (1 - slot) as Slot;
|
||||||
|
const ready = loaded.current[standby];
|
||||||
|
const standbyVideo = videoRefs[standby].current;
|
||||||
|
if (ready?.index === n && ready.cutIn != null && standbyVideo && standbyVideo.readyState >= 2) {
|
||||||
|
// Parked short of its cut for a pre-roll: bring it up to the cut in.
|
||||||
|
if (ready.parkedAt !== ready.cutIn || standbyVideo.seeking) {
|
||||||
|
const ok = await prepare(standby, n);
|
||||||
|
if (!ok || !playingRef.current || indexRef.current !== i) return;
|
||||||
|
}
|
||||||
|
standbyVideo.play().catch(() => {});
|
||||||
|
cutTo(standby, n);
|
||||||
|
} else {
|
||||||
|
// Next clip not ready (slow network): load it, then carry on.
|
||||||
|
void goTo(n, undefined, true);
|
||||||
|
}
|
||||||
|
}, [nextIndex, spanOf, clips, prepare, cutTo, goTo]);
|
||||||
|
|
||||||
|
// Playing: watch the active clip for its out-point, pre-roll the next one
|
||||||
|
// so it arrives on its cut in-point as the out-point passes, and keep the
|
||||||
|
// frame readout live.
|
||||||
|
//
|
||||||
|
// A frame is reported as it goes to the screen, so waiting to see the first
|
||||||
|
// handle frame would mean it had already been shown. Instead the active
|
||||||
|
// clip pauses on the last frame of its cut (holding it, never decoding the
|
||||||
|
// handle), and the cut happens when the next clip reports its cut in-point.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!playing) return;
|
||||||
|
const video = videoRefs[active].current;
|
||||||
|
const clip = clips[index];
|
||||||
|
if (!video || !clip) return;
|
||||||
|
const end = spanOf(index).end;
|
||||||
|
const n = nextIndex(index);
|
||||||
|
const standbySlot = (1 - active) as Slot;
|
||||||
|
const standbyVideo = videoRefs[standbySlot].current;
|
||||||
|
const hasRvfc = "requestVideoFrameCallback" in HTMLVideoElement.prototype;
|
||||||
|
|
||||||
|
const armedGeneration = generation.current;
|
||||||
|
let disposed = false;
|
||||||
|
let held = false; // active clip paused on its last cut frame
|
||||||
|
let prerolling = false;
|
||||||
|
let didCut = false;
|
||||||
|
let handle = 0;
|
||||||
|
let standbyHandle = 0;
|
||||||
|
let cutTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
let prerollTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
|
const standbyReady = () => {
|
||||||
|
const l = loaded.current[standbySlot];
|
||||||
|
return n != null &&
|
||||||
|
hasRvfc &&
|
||||||
|
standbyVideo &&
|
||||||
|
l?.index === n &&
|
||||||
|
l.cutIn != null &&
|
||||||
|
l.parkedAt != null &&
|
||||||
|
l.parkedAt <= l.cutIn &&
|
||||||
|
standbyVideo.readyState >= 2 &&
|
||||||
|
!standbyVideo.seeking
|
||||||
|
? { l: l as Required<Loaded>, sv: standbyVideo }
|
||||||
|
: null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** `cutAt`: when the next clip's cut in-point should reach the screen. */
|
||||||
|
const startPreroll = (r: NonNullable<ReturnType<typeof standbyReady>>, cutAt: number) => {
|
||||||
|
if (disposed || prerolling || standbyReady() == null) return;
|
||||||
|
prerolling = true;
|
||||||
|
const onStandbyFrame = (_now: number, meta: VideoFrameCallbackMetadata) => {
|
||||||
|
if (disposed) return;
|
||||||
|
if (timeToFrame(meta.mediaTime, clips[r.l.index].fps) >= r.l.cutIn) {
|
||||||
|
// Calibrate: arrived early → start later next time, and vice versa.
|
||||||
|
const error = meta.expectedDisplayTime - cutAt;
|
||||||
|
if (Math.abs(error) < 250) {
|
||||||
|
startLatency.current = Math.min(
|
||||||
|
300,
|
||||||
|
Math.max(-100, startLatency.current + error / 2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
didCut = true;
|
||||||
|
cutTo(standbySlot, r.l.index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
standbyHandle = r.sv.requestVideoFrameCallback(onStandbyFrame);
|
||||||
|
};
|
||||||
|
standbyHandle = r.sv.requestVideoFrameCallback(onStandbyFrame);
|
||||||
|
r.sv.play().catch(() => {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const check = (mediaTime: number, shownAt: number) => {
|
||||||
|
const f = timeToFrame(mediaTime, clip.fps);
|
||||||
|
setFrame(f);
|
||||||
|
const frameMs = 1000 / clip.fps / (video.playbackRate || 1);
|
||||||
|
const now = performance.now();
|
||||||
|
// When the out-point would reach the screen.
|
||||||
|
const cutAt = shownAt + (end - f) * frameMs;
|
||||||
|
|
||||||
|
// Start the next clip `lead` before the cut — on a timer, as frame
|
||||||
|
// callbacks only come once a frame.
|
||||||
|
if (!prerolling && prerollTimer === undefined) {
|
||||||
|
const r = standbyReady();
|
||||||
|
if (r) {
|
||||||
|
const lead =
|
||||||
|
startLatency.current + (r.l.cutIn - r.l.parkedAt) * (1000 / clips[r.l.index].fps);
|
||||||
|
const startIn = cutAt - now - lead;
|
||||||
|
if (startIn < frameMs * 2) {
|
||||||
|
prerollTimer = setTimeout(() => startPreroll(r, cutAt), Math.max(0, startIn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f >= end - 1) {
|
||||||
|
held = true;
|
||||||
|
video.pause();
|
||||||
|
// Not pre-rolled: cut on time by hand. Pre-rolled: the next clip cuts
|
||||||
|
// itself in; this only catches it never arriving.
|
||||||
|
const wait =
|
||||||
|
Math.max(0, cutAt - now) + (prerolling || prerollTimer !== undefined ? 500 : 0);
|
||||||
|
cutTimer = setTimeout(() => {
|
||||||
|
if (!disposed && !didCut && playingRef.current) void advance();
|
||||||
|
}, wait);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (hasRvfc) {
|
||||||
|
const onFrame = (_now: number, meta: VideoFrameCallbackMetadata) => {
|
||||||
|
if (disposed || check(meta.mediaTime, meta.expectedDisplayTime)) return;
|
||||||
|
handle = video.requestVideoFrameCallback(onFrame);
|
||||||
|
};
|
||||||
|
handle = video.requestVideoFrameCallback(onFrame);
|
||||||
|
} else {
|
||||||
|
const tick = () => {
|
||||||
|
if (disposed || check(video.currentTime, performance.now())) return;
|
||||||
|
handle = requestAnimationFrame(tick);
|
||||||
|
};
|
||||||
|
handle = requestAnimationFrame(tick);
|
||||||
|
}
|
||||||
|
// Media that ends before the computed out-point (duration rounding).
|
||||||
|
const onEnded = () => {
|
||||||
|
if (!held && !prerolling) {
|
||||||
|
held = true;
|
||||||
|
void advance();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
video.addEventListener("ended", onEnded);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
disposed = true;
|
||||||
|
clearTimeout(cutTimer);
|
||||||
|
clearTimeout(prerollTimer);
|
||||||
|
video.removeEventListener("ended", onEnded);
|
||||||
|
if (hasRvfc) {
|
||||||
|
video.cancelVideoFrameCallback(handle);
|
||||||
|
standbyVideo?.cancelVideoFrameCallback(standbyHandle);
|
||||||
|
} else {
|
||||||
|
cancelAnimationFrame(handle);
|
||||||
|
}
|
||||||
|
// Stopped mid pre-roll (paused): park the next clip again — unless a
|
||||||
|
// jump has taken over, and the standby may now be the clip on screen.
|
||||||
|
if (
|
||||||
|
prerolling &&
|
||||||
|
!didCut &&
|
||||||
|
standbyVideo &&
|
||||||
|
n != null &&
|
||||||
|
generation.current === armedGeneration &&
|
||||||
|
activeRef.current !== standbySlot
|
||||||
|
) {
|
||||||
|
standbyVideo.pause();
|
||||||
|
void prepare(standbySlot, n, undefined, PREROLL_FRAMES);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// spans are read live; re-arm when the active clip changes
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [playing, active, index, clips, advance, cutTo]);
|
||||||
|
|
||||||
|
// A new clip list: stay on the clip on screen if it's still in the list
|
||||||
|
// (a shot checked or unchecked mid-review), else start from the first.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!clips.length) return;
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
const keep = shownId.current ? clips.findIndex((c) => c.id === shownId.current) : -1;
|
||||||
|
loaded.current = [null, null];
|
||||||
|
if (keep >= 0 && video) {
|
||||||
|
void goTo(keep, timeToFrame(video.currentTime, clips[keep].fps));
|
||||||
|
} else {
|
||||||
|
playingRef.current = false;
|
||||||
|
setPlaying(false);
|
||||||
|
void goTo(0, undefined, false);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [clips]);
|
||||||
|
|
||||||
|
// Quality switch: reload the current clip at the same frame.
|
||||||
|
const lastHq = useRef(hq);
|
||||||
|
useEffect(() => {
|
||||||
|
if (lastHq.current === hq) return;
|
||||||
|
lastHq.current = hq;
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
const clip = clips[indexRef.current];
|
||||||
|
if (!video || !clip) return;
|
||||||
|
const at = timeToFrame(video.currentTime, clip.fps);
|
||||||
|
loaded.current = [null, null];
|
||||||
|
void goTo(indexRef.current, at);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [hq]);
|
||||||
|
|
||||||
|
// Loop toggled: what comes after the last clip changed, so reload the
|
||||||
|
// standby. Not on mount — the first goTo is loading then.
|
||||||
|
const lastLoop = useRef(loop);
|
||||||
|
useEffect(() => {
|
||||||
|
if (lastLoop.current === loop) return;
|
||||||
|
lastLoop.current = loop;
|
||||||
|
if (clips.length) preloadNext(indexRef.current);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [loop]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
if (video) video.muted = muted;
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [muted]);
|
||||||
|
|
||||||
|
// ── Transport ──────────────────────────────────────────────────────────────
|
||||||
|
const play = useCallback(() => {
|
||||||
|
const i = indexRef.current;
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
const clip = clips[i];
|
||||||
|
if (!video || !clip) return;
|
||||||
|
const span = spanOf(i);
|
||||||
|
const f = timeToFrame(video.currentTime, clip.fps);
|
||||||
|
// Parked on the last frame of the cut (paused at the cut, or at the end
|
||||||
|
// of the playlist): carry on from the next clip, or start over.
|
||||||
|
if (f >= span.end - 1) {
|
||||||
|
if (nextIndex(i) == null) {
|
||||||
|
void goTo(0, undefined, true);
|
||||||
|
} else {
|
||||||
|
playingRef.current = true;
|
||||||
|
setPlaying(true);
|
||||||
|
void advance();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (f < span.start || f >= span.end) {
|
||||||
|
video.currentTime = frameToTime(span.start + SEEK_BIAS, clip.fps);
|
||||||
|
}
|
||||||
|
playingRef.current = true;
|
||||||
|
setPlaying(true);
|
||||||
|
video.play().catch(() => {});
|
||||||
|
}, [clips, spanOf, nextIndex, goTo, advance]);
|
||||||
|
|
||||||
|
const pause = useCallback(() => {
|
||||||
|
playingRef.current = false;
|
||||||
|
setPlaying(false);
|
||||||
|
videoRefs[activeRef.current].current?.pause();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const toggle = useCallback(() => (playingRef.current ? pause() : play()), [play, pause]);
|
||||||
|
|
||||||
|
/** Step within the cut; stepping past either end moves to the next/previous clip. */
|
||||||
|
const step = useCallback(
|
||||||
|
(delta: number) => {
|
||||||
|
pause();
|
||||||
|
const i = indexRef.current;
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
const clip = clips[i];
|
||||||
|
if (!video || !clip) return;
|
||||||
|
const span = spanOf(i);
|
||||||
|
const f = timeToFrame(video.currentTime, clip.fps) + delta;
|
||||||
|
if (f >= span.end) {
|
||||||
|
if (i + 1 < clips.length) void goTo(i + 1, undefined, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (f < span.start) {
|
||||||
|
if (i > 0) void goTo(i - 1, spanOf(i - 1).end - 1, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
video.currentTime = frameToTime(f + SEEK_BIAS, clip.fps);
|
||||||
|
setFrame(f);
|
||||||
|
},
|
||||||
|
[clips, spanOf, goTo, pause]
|
||||||
|
);
|
||||||
|
|
||||||
|
const prevClip = useCallback(() => {
|
||||||
|
const i = indexRef.current;
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
const clip = clips[i];
|
||||||
|
// Like a transport: first press returns to the head of this clip.
|
||||||
|
if (video && clip && timeToFrame(video.currentTime, clip.fps) > spanOf(i).start + 2) {
|
||||||
|
void goTo(i);
|
||||||
|
} else {
|
||||||
|
void goTo(Math.max(0, i - 1));
|
||||||
|
}
|
||||||
|
}, [clips, spanOf, goTo]);
|
||||||
|
|
||||||
|
const nextClip = useCallback(() => {
|
||||||
|
const n = nextIndex(indexRef.current);
|
||||||
|
if (n != null) void goTo(n);
|
||||||
|
}, [nextIndex, goTo]);
|
||||||
|
|
||||||
|
// Keyboard
|
||||||
|
useEffect(() => {
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
const t = e.target as HTMLElement | null;
|
||||||
|
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
|
||||||
|
switch (e.key) {
|
||||||
|
case " ":
|
||||||
|
case "k":
|
||||||
|
case "K":
|
||||||
|
e.preventDefault();
|
||||||
|
toggle();
|
||||||
|
break;
|
||||||
|
case "ArrowRight":
|
||||||
|
e.preventDefault();
|
||||||
|
step(1);
|
||||||
|
break;
|
||||||
|
case "ArrowLeft":
|
||||||
|
e.preventDefault();
|
||||||
|
step(-1);
|
||||||
|
break;
|
||||||
|
case "ArrowDown":
|
||||||
|
e.preventDefault();
|
||||||
|
nextClip();
|
||||||
|
break;
|
||||||
|
case "ArrowUp":
|
||||||
|
e.preventDefault();
|
||||||
|
prevClip();
|
||||||
|
break;
|
||||||
|
case "Home":
|
||||||
|
e.preventDefault();
|
||||||
|
void goTo(0);
|
||||||
|
break;
|
||||||
|
case "m":
|
||||||
|
case "M":
|
||||||
|
setMuted((m) => !m);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener("keydown", onKey);
|
||||||
|
return () => window.removeEventListener("keydown", onKey);
|
||||||
|
}, [toggle, step, nextClip, prevClip, goTo]);
|
||||||
|
|
||||||
|
// ── Timeline ───────────────────────────────────────────────────────────────
|
||||||
|
const segments = useMemo(() => {
|
||||||
|
let offset = 0;
|
||||||
|
return clips.map((clip, i) => {
|
||||||
|
const span = spanOf(i);
|
||||||
|
const length = span.end - span.start;
|
||||||
|
const seg = { clip, span, offset, length };
|
||||||
|
offset += length;
|
||||||
|
return seg;
|
||||||
|
});
|
||||||
|
// spans refine as clips load (bumpSpans)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [clips, spanOf, spanVersion]);
|
||||||
|
const totalLength = segments.reduce((sum, s) => sum + s.length, 0) || 1;
|
||||||
|
const current = segments[index];
|
||||||
|
const posInClip = current ? Math.min(Math.max(frame - current.span.start, 0), current.length - 1) : 0;
|
||||||
|
const position = current ? current.offset + posInClip : 0;
|
||||||
|
const fps = clips[index]?.fps ?? 24;
|
||||||
|
|
||||||
|
const seekTimeline = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
|
const rect = e.currentTarget.getBoundingClientRect();
|
||||||
|
const target = ((e.clientX - rect.left) / rect.width) * totalLength;
|
||||||
|
const seg =
|
||||||
|
segments.find((s) => target < s.offset + s.length) ?? segments[segments.length - 1];
|
||||||
|
if (!seg) return;
|
||||||
|
const i = segments.indexOf(seg);
|
||||||
|
const f = seg.span.start + Math.min(seg.length - 1, Math.floor(target - seg.offset));
|
||||||
|
if (i === indexRef.current) {
|
||||||
|
const video = videoRefs[activeRef.current].current;
|
||||||
|
if (video) {
|
||||||
|
video.currentTime = frameToTime(f + SEEK_BIAS, seg.clip.fps);
|
||||||
|
setFrame(f);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
void goTo(i, f);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const anyHq = clips.some((c) => c.hqUrl);
|
||||||
|
|
||||||
|
if (!clips.length) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col flex-1 min-h-0 bg-black">
|
||||||
|
{/* Stage */}
|
||||||
|
<div className="relative flex-1 min-h-0" onClick={toggle}>
|
||||||
|
{[0, 1].map((slot) => (
|
||||||
|
<video
|
||||||
|
key={slot}
|
||||||
|
ref={videoRefs[slot]}
|
||||||
|
playsInline
|
||||||
|
muted
|
||||||
|
preload="auto"
|
||||||
|
// Initial stacking only; show() swaps opacity on the DOM from then on.
|
||||||
|
style={{ opacity: slot === 0 ? 1 : 0 }}
|
||||||
|
className="absolute inset-0 w-full h-full object-contain"
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{current && (
|
||||||
|
<div className="absolute top-3 left-3 pointer-events-none flex items-center gap-2 rounded bg-black/60 px-2 py-1">
|
||||||
|
<span className="font-mono text-xs font-semibold text-white">{current.clip.label}</span>
|
||||||
|
{current.clip.sublabel && (
|
||||||
|
<span className="text-[10px] text-zinc-400">{current.clip.sublabel}</span>
|
||||||
|
)}
|
||||||
|
<span className="text-[10px] text-zinc-500">
|
||||||
|
{index + 1}/{clips.length}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{buffering && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center pointer-events-none">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-zinc-400" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Timeline: one segment per clip, sized by its cut length */}
|
||||||
|
<div className="px-3 pt-2 shrink-0">
|
||||||
|
<div
|
||||||
|
className="relative h-7 flex rounded overflow-hidden cursor-pointer bg-zinc-900 select-none"
|
||||||
|
onClick={seekTimeline}
|
||||||
|
>
|
||||||
|
{segments.map((s, i) => (
|
||||||
|
<div
|
||||||
|
key={s.clip.id}
|
||||||
|
style={{ width: `${(s.length / totalLength) * 100}%` }}
|
||||||
|
className={cn(
|
||||||
|
"h-full border-r border-black/70 px-1 flex items-center overflow-hidden",
|
||||||
|
i === index ? "bg-blue-500/30" : i % 2 ? "bg-zinc-800" : "bg-zinc-800/60"
|
||||||
|
)}
|
||||||
|
title={`${s.clip.label} · ${s.length} fr`}
|
||||||
|
>
|
||||||
|
<span className="text-[10px] font-mono text-zinc-300 truncate">{s.clip.label}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div
|
||||||
|
className="absolute top-0 bottom-0 w-px bg-white pointer-events-none"
|
||||||
|
style={{ left: `${(position / totalLength) * 100}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Transport */}
|
||||||
|
<div className="flex items-center gap-1 px-3 py-2 shrink-0 text-zinc-300">
|
||||||
|
<TransportButton onClick={prevClip} title="Previous shot (↑)">
|
||||||
|
<ChevronFirst className="h-4 w-4" />
|
||||||
|
</TransportButton>
|
||||||
|
<TransportButton onClick={toggle} title="Play / pause (Space)">
|
||||||
|
{playing ? <Pause className="h-4 w-4" /> : <Play className="h-4 w-4" />}
|
||||||
|
</TransportButton>
|
||||||
|
<TransportButton onClick={nextClip} title="Next shot (↓)">
|
||||||
|
<ChevronLast className="h-4 w-4" />
|
||||||
|
</TransportButton>
|
||||||
|
|
||||||
|
<span className="ml-2 font-mono text-xs tabular-nums text-zinc-400">
|
||||||
|
{frameToTimecode(position, fps)}
|
||||||
|
<span className="text-zinc-600"> / {frameToTimecode(totalLength, fps)}</span>
|
||||||
|
</span>
|
||||||
|
<span className="ml-3 font-mono text-[10px] text-zinc-600 tabular-nums">
|
||||||
|
shot fr {posInClip + 1}/{current?.length ?? 0}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div className="ml-auto flex items-center gap-1">
|
||||||
|
{anyHq && (
|
||||||
|
<button
|
||||||
|
onClick={() => setHq((v) => !v)}
|
||||||
|
onMouseDown={(e) => e.preventDefault()}
|
||||||
|
className={cn(
|
||||||
|
"px-2 h-7 rounded text-[10px] font-semibold uppercase tracking-wider border",
|
||||||
|
hq
|
||||||
|
? "border-blue-500/40 text-blue-300 bg-blue-500/10"
|
||||||
|
: "border-zinc-700 text-zinc-500 hover:text-zinc-300"
|
||||||
|
)}
|
||||||
|
title="High quality where available"
|
||||||
|
>
|
||||||
|
HQ
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<TransportButton
|
||||||
|
onClick={() => setLoop((v) => !v)}
|
||||||
|
title="Loop playlist"
|
||||||
|
active={loop}
|
||||||
|
>
|
||||||
|
<Repeat className="h-4 w-4" />
|
||||||
|
</TransportButton>
|
||||||
|
<TransportButton onClick={() => setMuted((m) => !m)} title="Mute (M)">
|
||||||
|
{muted ? <VolumeX className="h-4 w-4" /> : <Volume2 className="h-4 w-4" />}
|
||||||
|
</TransportButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TransportButton({
|
||||||
|
onClick,
|
||||||
|
title,
|
||||||
|
active,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
onClick: () => void;
|
||||||
|
title: string;
|
||||||
|
active?: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
onClick={onClick}
|
||||||
|
// Keep focus off the button so Space stays play/pause.
|
||||||
|
onMouseDown={(e) => e.preventDefault()}
|
||||||
|
title={title}
|
||||||
|
className={cn(
|
||||||
|
"h-8 w-8 flex items-center justify-center rounded hover:bg-zinc-800 transition-colors",
|
||||||
|
active ? "text-blue-400" : "text-zinc-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,20 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { Progress } from "@/components/ui/progress";
|
import { Progress } from "@/components/ui/progress";
|
||||||
import { cn, getInitials, formatRelativeDate } from "@/lib/utils";
|
import { cn, getInitials, formatRelativeDate } from "@/lib/utils";
|
||||||
import {
|
import { Film, Layers, CheckCircle2, Clock, ArrowUpRight } from "lucide-react";
|
||||||
Film,
|
|
||||||
Layers,
|
|
||||||
CheckCircle2,
|
|
||||||
Clock,
|
|
||||||
Users,
|
|
||||||
ArrowUpRight,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
interface ProjectCardProps {
|
interface ProjectCardProps {
|
||||||
project: {
|
project: {
|
||||||
@@ -23,7 +13,9 @@ interface ProjectCardProps {
|
|||||||
code: string;
|
code: string;
|
||||||
status: string;
|
status: string;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
deadline?: Date | null;
|
/** The column is `dueDate`; `deadline` is kept for older callers. */
|
||||||
|
dueDate?: Date | string | null;
|
||||||
|
deadline?: Date | string | null;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
client?: { company: string } | null;
|
client?: { company: string } | null;
|
||||||
producer?: { name: string | null; image: string | null } | null;
|
producer?: { name: string | null; image: string | null } | null;
|
||||||
@@ -33,117 +25,147 @@ interface ProjectCardProps {
|
|||||||
approved: number;
|
approved: number;
|
||||||
inProgress: number;
|
inProgress: number;
|
||||||
};
|
};
|
||||||
|
/** Still chosen from the project's own shots (lib/project-poster.ts). */
|
||||||
|
poster?: { url: string; shotCode: string; isKeyShot: boolean } | null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_STYLES: Record<string, string> = {
|
const STATUS_STYLES: Record<string, string> = {
|
||||||
ACTIVE: "bg-green-900/60 text-green-300",
|
ACTIVE: "bg-green-900/70 text-green-300",
|
||||||
ON_HOLD: "bg-yellow-900/60 text-yellow-300",
|
ON_HOLD: "bg-yellow-900/70 text-yellow-300",
|
||||||
COMPLETED: "bg-blue-900/60 text-blue-300",
|
COMPLETED: "bg-blue-900/70 text-blue-300",
|
||||||
ARCHIVED: "bg-zinc-800 text-zinc-500",
|
ARCHIVED: "bg-zinc-900/80 text-zinc-400",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A project card is scanned, not read: in a grid of twenty the frame is what
|
||||||
|
* the eye picks out, so the still leads and the title sits on it. Every card is
|
||||||
|
* the same height whatever it holds — a ragged grid reads as broken, and the
|
||||||
|
* description is the only part that varies, so it is given fixed room rather
|
||||||
|
* than allowed to push the rest around.
|
||||||
|
*/
|
||||||
export function ProjectCard({ project }: ProjectCardProps) {
|
export function ProjectCard({ project }: ProjectCardProps) {
|
||||||
const total = project.shotStats?.total ?? project._count?.shots ?? 0;
|
const total = project.shotStats?.total ?? project._count?.shots ?? 0;
|
||||||
const approved = project.shotStats?.approved ?? 0;
|
const approved = project.shotStats?.approved ?? 0;
|
||||||
const progress = total > 0 ? Math.round((approved / total) * 100) : 0;
|
const progress = total > 0 ? Math.round((approved / total) * 100) : 0;
|
||||||
|
const due = project.dueDate ?? project.deadline;
|
||||||
|
const isArchived = project.status === "ARCHIVED";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="group hover:border-zinc-700 transition-all flex flex-col">
|
<Link
|
||||||
<CardHeader className="pb-3">
|
href={`/projects/${project.id}`}
|
||||||
<div className="flex items-start justify-between gap-2">
|
className="group flex h-full flex-col overflow-hidden rounded-lg border border-zinc-800 bg-card transition-colors hover:border-zinc-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500"
|
||||||
<div>
|
>
|
||||||
<div className="flex items-center gap-2 mb-0.5">
|
{/* Poster */}
|
||||||
<span className="font-mono text-xs text-zinc-500">{project.code}</span>
|
<div className="relative aspect-video w-full shrink-0 overflow-hidden bg-zinc-900">
|
||||||
{project.client && (
|
{project.poster ? (
|
||||||
<span className="text-xs text-zinc-600">• {project.client.company}</span>
|
<img
|
||||||
|
src={project.poster.url}
|
||||||
|
alt=""
|
||||||
|
loading="lazy"
|
||||||
|
className={cn(
|
||||||
|
"h-full w-full object-cover transition-transform duration-500 group-hover:scale-[1.04]",
|
||||||
|
// An archived show is still recognisable, just visibly past.
|
||||||
|
isArchived && "opacity-50 grayscale"
|
||||||
)}
|
)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
// Same footprint as a real poster, so a project without stills does
|
||||||
|
// not leave a hole in the grid.
|
||||||
|
<div className="flex h-full w-full items-center justify-center bg-gradient-to-br from-zinc-900 to-zinc-950">
|
||||||
|
<Film className="h-8 w-8 text-zinc-700" />
|
||||||
</div>
|
</div>
|
||||||
<h3 className="font-semibold text-base leading-tight text-white">{project.name}</h3>
|
)}
|
||||||
</div>
|
|
||||||
|
{/* Scrim: the title has to hold on a bright frame as well as a dark one. */}
|
||||||
|
<div className="absolute inset-0 bg-gradient-to-t from-black/90 via-black/35 to-black/10" />
|
||||||
|
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-xs px-2 py-0.5 rounded-full border-0 font-medium shrink-0",
|
"absolute right-2.5 top-2.5 rounded-full px-2 py-0.5 text-[11px] font-medium backdrop-blur-sm",
|
||||||
STATUS_STYLES[project.status] ?? STATUS_STYLES.ACTIVE
|
STATUS_STYLES[project.status] ?? STATUS_STYLES.ACTIVE
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{project.status.replace("_", " ")}
|
{project.status.replace("_", " ")}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<div className="absolute inset-x-0 bottom-0 p-3">
|
||||||
|
<div className="flex items-center gap-2 text-[11px] text-zinc-300/90">
|
||||||
|
<span className="font-mono">{project.code}</span>
|
||||||
|
{project.client && (
|
||||||
|
<span className="truncate text-zinc-400">• {project.client.company}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<h3 className="mt-0.5 line-clamp-2 text-base font-semibold leading-tight text-white drop-shadow-sm">
|
||||||
|
{project.name}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{project.description && (
|
{/* Body — fixed room so every card lands the same height */}
|
||||||
<p className="text-sm text-zinc-400 line-clamp-2 mt-1">
|
<div className="flex flex-1 flex-col gap-3 p-3">
|
||||||
{project.description}
|
<p className="line-clamp-2 min-h-[2.5rem] text-xs text-zinc-400">
|
||||||
|
{project.description || <span className="text-zinc-600">No description</span>}
|
||||||
</p>
|
</p>
|
||||||
)}
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent className="flex-1 pb-3 space-y-3">
|
|
||||||
{/* Progress */}
|
|
||||||
{total > 0 && (
|
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||||
<span>Shot progress</span>
|
<span>Shot progress</span>
|
||||||
<span className="text-foreground font-medium">{approved}/{total} approved</span>
|
<span className="font-medium text-foreground tabular-nums">
|
||||||
|
{total > 0 ? `${approved}/${total} approved` : "No shots yet"}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Progress value={progress} className="h-1.5" />
|
<Progress value={progress} className="h-1.5" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Stats */}
|
|
||||||
<div className="grid grid-cols-3 gap-2 text-xs">
|
<div className="grid grid-cols-3 gap-2 text-xs">
|
||||||
<div className="flex flex-col items-center rounded-lg bg-zinc-800 py-2">
|
<div className="flex flex-col items-center rounded-lg bg-zinc-800 py-2">
|
||||||
<Layers className="h-3.5 w-3.5 text-zinc-400 mb-1" />
|
<Layers className="mb-1 h-3.5 w-3.5 text-zinc-400" />
|
||||||
<span className="font-semibold text-white">{total}</span>
|
<span className="font-semibold tabular-nums text-white">{total}</span>
|
||||||
<span className="text-zinc-400">shots</span>
|
<span className="text-zinc-400">shots</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col items-center rounded-lg bg-zinc-800 py-2">
|
<div className="flex flex-col items-center rounded-lg bg-zinc-800 py-2">
|
||||||
<CheckCircle2 className="h-3.5 w-3.5 text-green-400 mb-1" />
|
<CheckCircle2 className="mb-1 h-3.5 w-3.5 text-green-400" />
|
||||||
<span className="font-semibold text-white">{approved}</span>
|
<span className="font-semibold tabular-nums text-white">{approved}</span>
|
||||||
<span className="text-zinc-400">done</span>
|
<span className="text-zinc-400">done</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col items-center rounded-lg bg-zinc-800 py-2">
|
<div className="flex flex-col items-center rounded-lg bg-zinc-800 py-2">
|
||||||
<Film className="h-3.5 w-3.5 text-blue-400 mb-1" />
|
<Film className="mb-1 h-3.5 w-3.5 text-blue-400" />
|
||||||
<span className="font-semibold text-white">
|
<span className="font-semibold tabular-nums text-white">
|
||||||
{project.shotStats?.inProgress ?? 0}
|
{project.shotStats?.inProgress ?? 0}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-zinc-400">active</span>
|
<span className="text-zinc-400">active</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
|
||||||
|
|
||||||
<CardFooter className="pt-2 border-t border-zinc-800 flex items-center justify-between">
|
{/* Pinned to the bottom so the footers line up across the row. */}
|
||||||
<div className="flex items-center gap-2 text-xs text-zinc-400">
|
<div className="mt-auto flex items-center justify-between gap-2 border-t border-zinc-800 pt-2.5 text-xs text-zinc-400">
|
||||||
|
<div className="flex min-w-0 items-center gap-2">
|
||||||
{project.producer ? (
|
{project.producer ? (
|
||||||
<>
|
<>
|
||||||
<Avatar className="h-5 w-5">
|
<Avatar className="h-5 w-5 shrink-0">
|
||||||
{project.producer.image && <AvatarImage src={project.producer.image} />}
|
{project.producer.image && <AvatarImage src={project.producer.image} />}
|
||||||
<AvatarFallback className="text-[9px]">
|
<AvatarFallback className="text-[9px]">
|
||||||
{getInitials(project.producer.name)}
|
{getInitials(project.producer.name)}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<span>{project.producer.name ?? "Producer"}</span>
|
<span className="truncate">{project.producer.name ?? "Producer"}</span>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Clock className="h-3 w-3" />
|
<Clock className="h-3 w-3 shrink-0" />
|
||||||
<span>{formatRelativeDate(project.createdAt)}</span>
|
<span className="truncate">{formatRelativeDate(project.createdAt)}</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{project.deadline && (
|
|
||||||
<span className="text-amber-400 ml-2">
|
|
||||||
Due {formatRelativeDate(project.deadline)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button variant="ghost" size="sm" asChild className="h-7 text-xs gap-1">
|
{due ? (
|
||||||
<Link href={`/projects/${project.id}`}>
|
<span className="shrink-0 text-amber-400">Due {formatRelativeDate(due as Date)}</span>
|
||||||
Open
|
) : (
|
||||||
<ArrowUpRight className="h-3 w-3" />
|
<ArrowUpRight className="h-3.5 w-3.5 shrink-0 text-zinc-600 transition-colors group-hover:text-amber-400" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
|
||||||
</CardFooter>
|
|
||||||
</Card>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user