mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 12:32:09 +10:00
Object storage now works fully, with the permission system. It still needs additional external endpoints for updating and deleting objects from the API, but it is otherwise complete. Further tasks include writing an S3 adapter.
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import clientHandler from "~/server/internal/clients/handler";
|
|
|
|
export default defineEventHandler(async (h3) => {
|
|
const body = await readBody(h3);
|
|
const clientId = body.clientId;
|
|
const token = body.token;
|
|
if (!clientId || !token)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "Missing token or client ID from body",
|
|
});
|
|
|
|
const metadata = await clientHandler.fetchClient(clientId);
|
|
if (!metadata)
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: "Invalid client ID",
|
|
});
|
|
if (!metadata.authToken || !metadata.userId)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "Un-authorized client ID",
|
|
});
|
|
if (metadata.authToken !== token)
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: "Invalid token",
|
|
});
|
|
|
|
const ca = h3.context.ca;
|
|
const bundle = await ca.generateClientCertificate(
|
|
clientId,
|
|
metadata.data.name
|
|
);
|
|
|
|
const client = await clientHandler.finialiseClient(clientId);
|
|
await ca.storeClientCertificate(clientId, bundle);
|
|
|
|
return {
|
|
private: bundle.priv,
|
|
certificate: bundle.cert,
|
|
id: client.id,
|
|
};
|
|
});
|