Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: asset: delete assets #1971

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/api/src/schema/api-schema.yaml
Expand Up @@ -883,6 +883,8 @@ components:
- processing
- ready
- failed
- deleting
- deleted
updatedAt:
type: number
description:
Expand Down Expand Up @@ -1408,6 +1410,7 @@ components:
- upload
- export
- export-data
- delete
- transcode-file
- clip
createdAt:
Expand Down Expand Up @@ -1473,6 +1476,16 @@ components:
id:
type: string
description: Optional ID of the content
delete:
type: object
additionalProperties: false
description: Parameters for the delete asset task
required:
- assetId
properties:
assetId:
type: string
description: ID of the asset to delete
transcode-file:
type: object
additionalProperties: false
Expand Down
28 changes: 25 additions & 3 deletions packages/api/src/task/scheduler.ts
Expand Up @@ -198,6 +198,18 @@ export class TaskScheduler {
});
}
break;
case "delete":
const deletingAsset = await db.asset.get(task.inputAssetId);
if (task.params.delete.assetId === deletingAsset.id) {
await this.updateAsset(deletingAsset, {
deletedAt: Date.now(),
deleted: true,
status: {
phase: "deleted",
updatedAt: Date.now(),
},
});
}
}
await this.updateTask(task, {
status: {
Expand Down Expand Up @@ -526,10 +538,20 @@ export class TaskScheduler {
if (typeof asset === "string") {
asset = await db.asset.get(asset);
}
const task = await taskScheduler.createAndScheduleTask(
"delete",
{
delete: {
assetId: asset.id,
},
},
asset
);
await this.updateAsset(asset, {
deleted: true,
deletedAt: Date.now(),
status: asset.status, // prevent updatedAt from being bumped
status: {
phase: "deleting",
updatedAt: Date.now(),
},
});
}

Expand Down