mirror of
https://github.com/imputnet/cobalt.git
synced 2025-01-14 19:05:16 +00:00
web/queue: add types & states
This commit is contained in:
parent
fcab598ec4
commit
13ec4f4faf
61
web/src/lib/state/queue.ts
Normal file
61
web/src/lib/state/queue.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { merge } from "ts-deepmerge";
|
||||
import { get, readable, type Updater } from "svelte/store";
|
||||
import type { OngoingQueueItem, QueueItem } from "$lib/types/queue";
|
||||
|
||||
type Queue = {
|
||||
[id: string]: QueueItem;
|
||||
}
|
||||
|
||||
type OngoingQueue = {
|
||||
[id: string]: OngoingQueueItem;
|
||||
}
|
||||
|
||||
let update: (_: Updater<Queue>) => void;
|
||||
|
||||
const queue = readable<Queue>(
|
||||
{},
|
||||
(_, _update) => { update = _update }
|
||||
);
|
||||
|
||||
export function addToQueue(item: QueueItem) {
|
||||
update(queueData => {
|
||||
queueData[item.id] = item;
|
||||
return queueData;
|
||||
});
|
||||
}
|
||||
|
||||
export function removeFromQueue(id: string) {
|
||||
update(queueData => {
|
||||
delete queueData[id];
|
||||
return queueData;
|
||||
});
|
||||
}
|
||||
|
||||
let updateOngoing: (_: Updater<OngoingQueue>) => void;
|
||||
|
||||
const ongoingQueue = readable<OngoingQueue>(
|
||||
{},
|
||||
(_, _update) => { updateOngoing = _update }
|
||||
);
|
||||
|
||||
export function updateOngoingQueue(id: string, itemInfo: Partial<OngoingQueueItem> = {}) {
|
||||
updateOngoing(queueData => {
|
||||
if (get(queue)?.id) {
|
||||
queueData[id] = merge(queueData[id], {
|
||||
id,
|
||||
...itemInfo,
|
||||
});
|
||||
}
|
||||
|
||||
return queueData;
|
||||
});
|
||||
}
|
||||
|
||||
export function removeFromOngoingQueue(id: string) {
|
||||
updateOngoing(queue => {
|
||||
delete queue[id];
|
||||
return queue;
|
||||
});
|
||||
}
|
||||
|
||||
export { queue, ongoingQueue };
|
|
@ -1,7 +1,34 @@
|
|||
type ProcessingStep = "mux" | "mux_hls" | "encode";
|
||||
type ProcessingPreset = "mp4" | "webm" | "copy";
|
||||
type ProcessingState = "completed" | "failed" | "canceled" | "waiting" | "downloading" | "muxing" | "converting";
|
||||
type ProcessingType = "video" | "video_mute" | "audio" | "audio_convert" | "image" | "gif";
|
||||
type QueueFileType = "video" | "audio" | "image" | "gif";
|
||||
|
||||
export type ProcessingStepItem = {
|
||||
type: ProcessingStep,
|
||||
preset?: ProcessingPreset,
|
||||
}
|
||||
|
||||
export type QueueFile = {
|
||||
type: QueueFileType,
|
||||
url: string,
|
||||
}
|
||||
|
||||
export type QueueItem = {
|
||||
id: string,
|
||||
type: "video" | "audio" | "mute" | "image" | "gif",
|
||||
status: ProcessingState,
|
||||
type: ProcessingType,
|
||||
filename: string,
|
||||
status: string,
|
||||
progress: number,
|
||||
files: QueueFile[],
|
||||
processingSteps: ProcessingStepItem[],
|
||||
}
|
||||
|
||||
export type OngoingQueueItem = {
|
||||
id: string,
|
||||
currentStep?: ProcessingStep,
|
||||
size?: {
|
||||
expected: number,
|
||||
current: number,
|
||||
},
|
||||
speed?: number,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue