mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 16:22:39 +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
This commit is contained in:
35
server/api/v1/admin/task/index.get.ts
Normal file
35
server/api/v1/admin/task/index.get.ts
Normal file
@ -0,0 +1,35 @@
|
||||
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 };
|
||||
});
|
||||
Reference in New Issue
Block a user