mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
fix: remaining type issues
This commit is contained in:
@ -42,10 +42,10 @@ export default defineEventHandler<{
|
||||
await objectHandler.deleteAsSystem(imageId);
|
||||
|
||||
if (game.mBannerObjectId === imageId) {
|
||||
game.mBannerObjectId = game.mImageLibraryObjectIds[0];
|
||||
game.mBannerObjectId = game.mImageLibraryObjectIds[0] ?? "";
|
||||
}
|
||||
if (game.mCoverObjectId === imageId) {
|
||||
game.mCoverObjectId = game.mImageLibraryObjectIds[0];
|
||||
game.mCoverObjectId = game.mImageLibraryObjectIds[0] ?? "";
|
||||
}
|
||||
|
||||
const result = await prisma.game.update({
|
||||
|
||||
@ -2,11 +2,10 @@ import { type } from "arktype";
|
||||
import { readDropValidatedBody, throwingArktype } from "~~/server/arktype";
|
||||
import aclManager from "~~/server/internal/acls";
|
||||
import taskHandler from "~~/server/internal/tasks";
|
||||
import type { TaskGroup } from "~~/server/internal/tasks/group";
|
||||
import { taskGroups } from "~~/server/internal/tasks/group";
|
||||
import { TASK_GROUPS, type TaskGroup } from "~~/server/internal/tasks/group";
|
||||
|
||||
const StartTask = type({
|
||||
taskGroup: type("string"),
|
||||
taskGroup: type.enumerated(...TASK_GROUPS),
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
@ -14,14 +13,8 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readDropValidatedBody(h3, StartTask);
|
||||
const taskGroup = body.taskGroup as TaskGroup;
|
||||
if (!taskGroups[taskGroup])
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "Invalid task group.",
|
||||
});
|
||||
|
||||
const task = await taskHandler.runTaskGroupByName(taskGroup);
|
||||
const task = await taskHandler.runTaskGroupByName(body.taskGroup);
|
||||
if (!task)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
import { type } from "arktype";
|
||||
import { ClientCapabilities } from "~~/prisma/client/enums";
|
||||
import { readDropValidatedBody, throwingArktype } from "~~/server/arktype";
|
||||
import type {
|
||||
CapabilityConfiguration,
|
||||
InternalClientCapability,
|
||||
} from "~~/server/internal/clients/capabilities";
|
||||
import capabilityManager, {
|
||||
validCapabilities,
|
||||
} from "~~/server/internal/clients/capabilities";
|
||||
import clientHandler, { AuthMode } from "~~/server/internal/clients/handler";
|
||||
import clientHandler, { AuthMode, AuthModes } from "~~/server/internal/clients/handler";
|
||||
import { parsePlatform } from "~~/server/internal/utils/parseplatform";
|
||||
|
||||
const ClientAuthInitiate = type({
|
||||
name: "string",
|
||||
platform: "string",
|
||||
capabilities: "object",
|
||||
mode: type.valueOf(AuthMode).default(AuthMode.Callback),
|
||||
mode: type.enumerated(...AuthModes).default("callback"),
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
@ -32,7 +32,7 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
|
||||
const capabilityIterable = Object.entries(capabilities) as Array<
|
||||
[InternalClientCapability, object]
|
||||
[ClientCapabilities, object]
|
||||
>;
|
||||
if (
|
||||
capabilityIterable.length > 0 &&
|
||||
|
||||
@ -1,39 +1,24 @@
|
||||
import type { InternalClientCapability } from "~~/server/internal/clients/capabilities";
|
||||
import { type } from "arktype";
|
||||
import { ClientCapabilities } from "~~/prisma/client/enums";
|
||||
import { readDropValidatedBody, throwingArktype } from "~~/server/arktype";
|
||||
import capabilityManager, {
|
||||
validCapabilities,
|
||||
} from "~~/server/internal/clients/capabilities";
|
||||
import { defineClientEventHandler } from "~~/server/internal/clients/event-handler";
|
||||
import notificationSystem from "~~/server/internal/notifications";
|
||||
|
||||
const SetCapability = type({
|
||||
capability: type.enumerated(...Object.values(ClientCapabilities)),
|
||||
configuration: "object"
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineClientEventHandler(
|
||||
async (h3, { clientId, fetchClient, fetchUser }) => {
|
||||
const body = await readBody(h3);
|
||||
const rawCapability = body.capability;
|
||||
const configuration = body.configuration;
|
||||
|
||||
if (!rawCapability || typeof rawCapability !== "string")
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "capability must be a string",
|
||||
});
|
||||
|
||||
if (!configuration || typeof configuration !== "object")
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "configuration must be an object",
|
||||
});
|
||||
|
||||
const capability = rawCapability as InternalClientCapability;
|
||||
|
||||
if (!validCapabilities.includes(capability))
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "Invalid capability.",
|
||||
});
|
||||
const body = await readDropValidatedBody(h3, SetCapability);
|
||||
|
||||
const isValid = await capabilityManager.validateCapabilityConfiguration(
|
||||
capability,
|
||||
configuration,
|
||||
body.capability,
|
||||
body.configuration,
|
||||
);
|
||||
if (!isValid)
|
||||
throw createError({
|
||||
@ -42,8 +27,8 @@ export default defineClientEventHandler(
|
||||
});
|
||||
|
||||
await capabilityManager.upsertClientCapability(
|
||||
capability,
|
||||
configuration,
|
||||
body.capability,
|
||||
body.configuration,
|
||||
clientId,
|
||||
);
|
||||
|
||||
@ -51,9 +36,9 @@ export default defineClientEventHandler(
|
||||
const user = await fetchUser();
|
||||
|
||||
await notificationSystem.push(user.id, {
|
||||
nonce: `capability-${clientId}-${capability}`,
|
||||
title: `"${client.name}" can now access ${capability}`,
|
||||
description: `A device called "${client.name}" now has access to your ${capability}.`,
|
||||
nonce: `capability-${clientId}-${body.capability}`,
|
||||
title: `"${client.name}" can now access ${body.capability}`,
|
||||
description: `A device called "${client.name}" now has access to your ${body.capability}.`,
|
||||
actions: ["Review|/account/devices"],
|
||||
acls: ["user:clients:read"],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user