.get(
"/workflow",
validator(
"query",
z.object({
videoId: z.string().min(1),
instanceId: z.string().optional(),
}),
),
describeRoute({
tags: ["Video"],
}),
async (c) => {
const organization = c.get("organization");
const { instanceId, videoId } = c.req.valid("query");
const video = await db(c.env.COVE).video.findUnique({
where: { id: videoId, organizationId: organization?.id },
});
if (!video) {
return c.json({ error: "Video not found" }, 404);
}
if (instanceId) {
const instance =
await c.env.COVE_WORKFLOW_VIDEO.get(instanceId);
return c.json({
status: await instance.status(),
});
}
// Spawn a new instance and return the ID and status
const instance = await c.env.COVE_WORKFLOW_VIDEO.create({
params: {
key: video.key,
},
});
return c.json({
id: instance.id,
details: await instance.status(),
});
},
)
.get(
"/workflow",
validator(
"query",
z.object({
videoId: z.string().min(1),
instanceId: z.string().optional(),
}),
),
describeRoute({
tags: ["Video"],
}),
async (c) => {
const organization = c.get("organization");
const { instanceId, videoId } = c.req.valid("query");
const video = await db(c.env.COVE).video.findUnique({
where: { id: videoId, organizationId: organization?.id },
});
if (!video) {
return c.json({ error: "Video not found" }, 404);
}
if (instanceId) {
const instance =
await c.env.COVE_WORKFLOW_VIDEO.get(instanceId);
return c.json({
status: await instance.status(),
});
}
// Spawn a new instance and return the ID and status
const instance = await c.env.COVE_WORKFLOW_VIDEO.create({
params: {
key: video.key,
},
});
return c.json({
id: instance.id,
details: await instance.status(),
});
},
)