diff --git a/nuxt.config.ts b/nuxt.config.ts index c4dc56b..5833054 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,6 +1,6 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ - compatibilityDate: '2024-04-03', + compatibilityDate: "2024-04-03", devtools: { enabled: false }, css: ["~/assets/core.scss"], @@ -13,9 +13,7 @@ export default defineNuxtConfig({ app: { head: { - link: [ - { rel: 'icon', href: '/favicon.ico', } - ] - } - } -}) \ No newline at end of file + link: [{ rel: "icon", href: "/favicon.ico" }], + }, + }, +}); diff --git a/pages/client/[id]/callback.vue b/pages/client/[id]/callback.vue new file mode 100644 index 0000000..cc340bc --- /dev/null +++ b/pages/client/[id]/callback.vue @@ -0,0 +1 @@ + diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4dddcb5..946e294 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -49,6 +49,9 @@ model Client { endpoint String capabilities ClientCapabilities[] + + name String + platform String } enum MetadataSource { diff --git a/server/api/v1/client/callback/index.get.ts b/server/api/v1/client/callback/index.get.ts new file mode 100644 index 0000000..497873a --- /dev/null +++ b/server/api/v1/client/callback/index.get.ts @@ -0,0 +1,3 @@ +export default defineEventHandler((h3) => { + +}); \ No newline at end of file diff --git a/server/api/v1/client/callback/index.post.ts b/server/api/v1/client/callback/index.post.ts new file mode 100644 index 0000000..497873a --- /dev/null +++ b/server/api/v1/client/callback/index.post.ts @@ -0,0 +1,3 @@ +export default defineEventHandler((h3) => { + +}); \ No newline at end of file diff --git a/server/api/v1/client/initiate.post.ts b/server/api/v1/client/initiate.post.ts index 5475725..fbce624 100644 --- a/server/api/v1/client/initiate.post.ts +++ b/server/api/v1/client/initiate.post.ts @@ -1,3 +1,18 @@ -export default defineEventHandler(async (h3) => { +import clientHandler from "~/server/internal/clients/handler"; -}); \ No newline at end of file +export default defineEventHandler(async (h3) => { + const body = await readBody(h3); + + const name = body.name; + const platform = body.platform; + + if (!name || !platform) + throw createError({ + statusCode: 400, + statusMessage: "Missing name or platform in body", + }); + + const clientId = await clientHandler.initiate({ name, platform }); + + return `/client/${clientId}/callback`; +}); diff --git a/server/api/v1/index.get.ts b/server/api/v1/index.get.ts new file mode 100644 index 0000000..9732811 --- /dev/null +++ b/server/api/v1/index.get.ts @@ -0,0 +1,5 @@ +export default defineEventHandler((h3) => { + return { + appName: "Drop", + }; +}); diff --git a/server/internal/clients/handler.ts b/server/internal/clients/handler.ts new file mode 100644 index 0000000..b5ecc9d --- /dev/null +++ b/server/internal/clients/handler.ts @@ -0,0 +1,29 @@ +import { v4 as uuidv4 } from "uuid"; + +export interface ClientMetadata { + name: string; + platform: string; +} + +export class ClientHandler { + private temporaryClientTable: { + [key: string]: { timeout: NodeJS.Timeout; data: ClientMetadata }; + } = {}; + + async initiate(metadata: ClientMetadata) { + const clientId = uuidv4(); + + this.temporaryClientTable[clientId] = { + data: metadata, + timeout: setTimeout(() => { + if (this.temporaryClientTable[clientId]) + delete this.temporaryClientTable[clientId]; + }, 1000 * 60 * 10), // 10 minutes + }; + + return clientId; + } +} + +export const clientHandler = new ClientHandler(); +export default clientHandler;