import { Query } from '@kevisual/query'; import { app, assistantConfig } from '../app.ts'; import './config/index.ts'; import './shop-install/index.ts'; import os from 'node:os'; app .route({ path: 'auth', id: 'auth', }) .define(async (ctx) => { const config = assistantConfig.getConfig(); const { auth } = config; const host = config.pageApi || config.registry || 'https://kevisual.cn'; const url = new URL('/api/router', host); const token = ctx.token; if (auth && auth.type !== 'public') { if (!token) { return ctx.throw(4001, 'not login'); } url.searchParams.set('token', token); // 鉴权代理 // TODO: const query = new Query({ baseURL: url.toString() }); const res = await query.post({ path: 'user', key: 'me', }); console.log('res', res); if (res.code !== 200) { return ctx.throw(4001, 'not login'); } const tokenUser = res.data || {}; ctx.state = { ...ctx.state, tokenUser, }; const { username } = tokenUser; } }) .addTo(app); app .route({ path: 'client', key: 'version', }) .define(async (ctx) => { ctx.body = 'v1.0.0'; }) .addTo(app); app .route({ path: 'client', key: 'time', }) .define(async (ctx) => { ctx.body = { time: new Date().getTime(), date: new Date().toLocaleDateString(), }; }) .addTo(app); app .route({ path: 'client', key: 'system', description: '获取系统信息', }) .define(async (ctx) => { const { platform, arch, release } = os; ctx.body = { platform: platform(), arch: arch(), release: release(), }; }) .addTo(app);