Skip to content

Open source CapCut alternative.

TypeScript

fix(cut): retire dismissed settled exports from the backend feed [rebuild]

David Leb63180b4c1dd
diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.ts
index bf58b048..f7e5996f 100644
--- a/site/src/cut/lib/exportClient.ts
+++ b/site/src/cut/lib/exportClient.ts
@@ -513,7 +513,8 @@ export async function createExportJob(
return body.id;
}
-/** Cancel a running or queued export job by id. */
+/** Cancel a running or queued export job, or retire a settled one from the
+ * export-jobs feed. */
export function cancelExportJob(jobId: string, backend: CutBackend = getBackend()) {
void backend.fetch(`/api/cut/export/${jobId}`, { method: "DELETE" }).catch(() => {});
}
diff --git a/site/src/cut/lib/exportStore.ts b/site/src/cut/lib/exportStore.ts
index e5af1529..d4d90dac 100644
--- a/site/src/cut/lib/exportStore.ts
+++ b/site/src/cut/lib/exportStore.ts
@@ -130,15 +130,29 @@ export const useExports = create<ExportsState>((set, get) => ({
void get().refresh();
},
- dismiss: (id) =>
+ dismiss: (id) => {
+ // A settled row is retired from its backend's feed too (the same DELETE
+ // that cancels a live job), so it stays gone across tabs and reloads —
+ // the `dismissed` entry only hides it until the next poll confirms.
+ // Hiding a still-running row stays local: the export keeps rendering.
+ const job = get().jobs.find((j) => j.id === id);
+ if (job && (job.status === "done" || job.status === "error")) {
+ cancelExportJob(id, exportBackend(job.residency));
+ }
set((s) => ({
local: s.local.filter((r) => r.id !== id),
dismissed: s.jobs.some((j) => j.id === id)
? [...new Set([...s.dismissed, id])]
: s.dismissed,
- })),
+ }));
+ },
- dismissSettled: () =>
+ dismissSettled: () => {
+ for (const j of get().jobs) {
+ if (j.status === "done" || j.status === "error") {
+ cancelExportJob(j.id, exportBackend(j.residency));
+ }
+ }
set((s) => ({
local: s.local.filter((r) => r.status !== "error"),
dismissed: [
@@ -149,7 +163,8 @@ export const useExports = create<ExportsState>((set, get) => ({
.map((j) => j.id),
]),
],
- })),
+ }));
+ },
refresh: async () => {
// One backend's feed, rows stamped with its residency; null on a hiccup so
diff --git a/site/src/cut/server/cloud/jobs.ts b/site/src/cut/server/cloud/jobs.ts
index 001bbc9e..f2d2c48d 100644
--- a/site/src/cut/server/cloud/jobs.ts
+++ b/site/src/cut/server/cloud/jobs.ts
@@ -154,10 +154,17 @@ export const jobsCloud = {
async exportCancel(userId: string, jobId: string) {
// The worker honors "canceled" mid-run; a queued row is simply never claimed.
- await prisma.cutRenderJob.updateMany({
+ const canceled = await prisma.cutRenderJob.updateMany({
where: { id: jobId, userId, state: { in: ["queued", "running"] } },
data: { state: "canceled" },
});
+ // A settled row is being dismissed from the dock: drop it from the feed
+ // for good. A finished file survives as the project's export media object.
+ if (canceled.count === 0) {
+ await prisma.cutRenderJob.deleteMany({
+ where: { id: jobId, userId, state: { in: ["done", "error", "canceled"] } },
+ });
+ }
return Response.json({ ok: true });
},
diff --git a/site/src/cut/server/jobs.ts b/site/src/cut/server/jobs.ts
index 9b0adaa7..93c0a2eb 100644
--- a/site/src/cut/server/jobs.ts
+++ b/site/src/cut/server/jobs.ts
@@ -130,6 +130,10 @@ export function cancelJob(id: string) {
const i = pending.findIndex((p) => p.job.id === id);
if (i >= 0) pending.splice(i, 1);
retire(job);
+ } else if (job.status === "done" || job.status === "error") {
+ // Dismissed from the dock: drop it from the feed for good. A finished
+ // file stays on disk in exports/.
+ jobs.delete(id);
}
}