mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-09 20:12:10 +10:00
client initiate
This commit is contained in:
@ -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', }
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
link: [{ rel: "icon", href: "/favicon.ico" }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
1
pages/client/[id]/callback.vue
Normal file
1
pages/client/[id]/callback.vue
Normal file
@ -0,0 +1 @@
|
||||
<template></template>
|
||||
@ -49,6 +49,9 @@ model Client {
|
||||
|
||||
endpoint String
|
||||
capabilities ClientCapabilities[]
|
||||
|
||||
name String
|
||||
platform String
|
||||
}
|
||||
|
||||
enum MetadataSource {
|
||||
|
||||
3
server/api/v1/client/callback/index.get.ts
Normal file
3
server/api/v1/client/callback/index.get.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export default defineEventHandler((h3) => {
|
||||
|
||||
});
|
||||
3
server/api/v1/client/callback/index.post.ts
Normal file
3
server/api/v1/client/callback/index.post.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export default defineEventHandler((h3) => {
|
||||
|
||||
});
|
||||
@ -1,3 +1,18 @@
|
||||
export default defineEventHandler(async (h3) => {
|
||||
import clientHandler from "~/server/internal/clients/handler";
|
||||
|
||||
});
|
||||
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`;
|
||||
});
|
||||
|
||||
5
server/api/v1/index.get.ts
Normal file
5
server/api/v1/index.get.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export default defineEventHandler((h3) => {
|
||||
return {
|
||||
appName: "Drop",
|
||||
};
|
||||
});
|
||||
29
server/internal/clients/handler.ts
Normal file
29
server/internal/clients/handler.ts
Normal file
@ -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;
|
||||
Reference in New Issue
Block a user