feat: 添加短链管理功能,包括创建、更新、删除和列表接口
This commit is contained in:
@@ -4,7 +4,8 @@ import { omit } from 'es-toolkit';
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
import { renderServerHtml } from '../html/render-server-html.ts';
|
||||
import { baseURL } from '../domain.ts';
|
||||
|
||||
import { app } from '@/app.ts'
|
||||
import { N5Service } from '@/routes/n5-link/modules/n5.services.ts';
|
||||
type ProxyOptions = {
|
||||
createNotFoundPage: (msg?: string) => any;
|
||||
};
|
||||
@@ -18,19 +19,30 @@ export const N5Proxy = async (req: IncomingMessage, res: ServerResponse, opts?:
|
||||
opts?.createNotFoundPage?.('应用未找到');
|
||||
return false;
|
||||
}
|
||||
const convexResult = await convex.query(convexApi.nCode.getBySlug, { slug: app })
|
||||
if (!convexResult) {
|
||||
opts?.createNotFoundPage?.('应用未找到');
|
||||
return false;
|
||||
}
|
||||
const data = convexResult.data ?? {};
|
||||
const link = data.link;
|
||||
if (!link) {
|
||||
opts?.createNotFoundPage?.('不存在对应的跳转的链接');
|
||||
let n5Data = null;
|
||||
let data = null;
|
||||
let link = '';
|
||||
try {
|
||||
const convexResult = await N5Service.getBySlug(app);
|
||||
if (!convexResult || convexResult.length === 0) {
|
||||
opts?.createNotFoundPage?.('应用未找到');
|
||||
return false;
|
||||
}
|
||||
n5Data = convexResult[0];
|
||||
data = n5Data.data ?? {};
|
||||
link = data.link;
|
||||
if (!link) {
|
||||
opts?.createNotFoundPage?.('不存在对应的跳转的链接');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error fetching N5 data:', e);
|
||||
opts?.createNotFoundPage?.('应用数据异常');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data?.useOwnerToken) {
|
||||
const userId = convexResult.userId;
|
||||
const userId = n5Data.userId;
|
||||
if (!userId) {
|
||||
opts?.createNotFoundPage?.('未绑定账号');
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user