mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-09 20:12:10 +10:00
* feat: historical tasks in database, better scheduling, and unified API for accessing tasks * feat: new UI for everything * fix: add translations and fix formatting
36 lines
984 B
TypeScript
36 lines
984 B
TypeScript
import aclManager from "~/server/internal/acls";
|
|
import prisma from "~/server/internal/db/database";
|
|
import taskHandler from "~/server/internal/tasks";
|
|
|
|
export default defineEventHandler(async (h3) => {
|
|
const allowed = await aclManager.allowSystemACL(h3, ["task:read"]);
|
|
if (!allowed) throw createError({ statusCode: 403 });
|
|
const allAcls = await aclManager.fetchAllACLs(h3);
|
|
if (!allAcls)
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: "Somehow no ACLs on authenticated request.",
|
|
});
|
|
|
|
const runningTasks = (await taskHandler.runningTasks()).map((e) => e.id);
|
|
const historicalTasks = await prisma.task.findMany({
|
|
where: {
|
|
OR: [
|
|
{
|
|
acls: { hasSome: allAcls },
|
|
},
|
|
{
|
|
acls: { isEmpty: true },
|
|
},
|
|
],
|
|
},
|
|
orderBy: {
|
|
ended: "desc",
|
|
},
|
|
take: 10,
|
|
});
|
|
const dailyTasks = await taskHandler.dailyTasks();
|
|
|
|
return { runningTasks, historicalTasks, dailyTasks };
|
|
});
|