Files
cnb/agent/app.ts
xiongxiao ef38fc0596 update
2026-03-11 16:15:48 +08:00

38 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { QueryRouterServer as App } from '@kevisual/router'
import { useContextKey } from '@kevisual/context'
import { useKey } from '@kevisual/use-config'
import { CNB } from '../src/index.ts';
import { CNBManager } from './modules/cnb-manager.ts'
export const cnbManager = new CNBManager()
// CNB_TOKEN是降级兼容变量推荐使用CNB_API_KEY
// CNB_TOKEN 是流水线自己就有的变量,但是权限比较小
const token = useKey('CNB_API_KEY') as string || useKey('CNB_TOKEN') as string
// cookie 变量是可选的
const cookie = useKey('CNB_COOKIE') as string
try {
cnbManager.addCNB({
username: 'default',
token: token,
cookie: cookie,
cnb: new CNB({ token: token, cookie: cookie })
})
} catch (error) {
process.exit(1)
}
await new Promise(resolve => setTimeout(resolve, 1000))
export const cnbItem = await cnbManager.getCNB({ username: 'default' });
export const cnb = cnbItem?.cnb;
export const app = await useContextKey<App>('app', () => {
return new App({})
})
export const notCNBCheck = (ctx: any) => {
const isCNB = useKey('CNB');
if (!isCNB) {
ctx.throw(400, '当前环境非 cnb-board 环境,无法获取内容');
}
return false;
}