generated from tailored/router-template
temp
This commit is contained in:
parent
c2a0623482
commit
d6014b3c40
@ -46,6 +46,7 @@
|
||||
"devDependencies": {
|
||||
"@kevisual/ai-center": "^0.0.3",
|
||||
"@kevisual/app-assistant": "workspace:*",
|
||||
"@kevisual/xhs": "workspace:*",
|
||||
"@kevisual/types": "^0.0.9",
|
||||
"@kevisual/use-config": "^1.0.12",
|
||||
"@types/bun": "^1.2.11",
|
||||
|
@ -2,23 +2,19 @@
|
||||
// https://bun.sh/docs/bundler
|
||||
// @ts-ignore
|
||||
import pkg from './package.json';
|
||||
// import { resolvePath as rp } from '@kevisual/use-config/env';
|
||||
import path from 'path';
|
||||
const rp = (resolvePath) => {
|
||||
return path.resolve(process.cwd(), resolvePath);
|
||||
};
|
||||
import { resolvePath as rp } from '@kevisual/use-config/env';
|
||||
|
||||
// bun run src/index.ts --
|
||||
await Bun.build({
|
||||
target: 'node',
|
||||
format: 'esm',
|
||||
entrypoints: [rp('src/index.js')],
|
||||
entrypoints: [rp('src/index.ts')],
|
||||
outdir: rp('./dist'),
|
||||
naming: {
|
||||
entry: 'app.mjs',
|
||||
},
|
||||
|
||||
define: {
|
||||
VERSION: JSON.stringify(pkg.version),
|
||||
},
|
||||
env: 'KEVISUAL_*',
|
||||
external: ['sequelize'],
|
||||
});
|
||||
|
@ -6,7 +6,7 @@
|
||||
"types": "app.d.ts",
|
||||
"scripts": {
|
||||
"build": "bun run bun.config.mjs",
|
||||
"postbuild": "dts -i src/index.js -o app.d.ts",
|
||||
"postbuild": "dts -i src/index.ts -o app.d.ts",
|
||||
"cmd": "tsx src/test/command.ts ",
|
||||
"dts": "dts -i src/index.js -o app.d.ts"
|
||||
},
|
||||
@ -22,10 +22,21 @@
|
||||
"packageManager": "pnpm@10.10.0",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@kevisual/use-config": "^1.0.14",
|
||||
"@kevisual/xhs-core": "workspace:*",
|
||||
"@types/node": "^22.15.3"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/app.mjs",
|
||||
"types": "./dist/app.d.ts"
|
||||
},
|
||||
"./index": {
|
||||
"import": "./src/index.ts"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@kevisual/db": "^0.0.1",
|
||||
"nanoid": "^5.1.5",
|
||||
"sequelize": "^6.37.7",
|
||||
"sqlite3": "^5.1.7"
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { QueryRouterServer } from '@kevisual/router';
|
||||
import { XhsServices } from '@/services/xhs-services.ts';
|
||||
import { QueryRouterServer } from '@kevisual/router/browser';
|
||||
import { XhsServices } from '@kevisual/xhs/services/xhs-services.ts';
|
||||
|
||||
export const app = new QueryRouterServer();
|
||||
export const xhsServices = new XhsServices();
|
||||
|
@ -49,7 +49,7 @@ export const getSign = async (signInfo: SignInfo, options?: SignOptions): Promis
|
||||
web_session: web_session,
|
||||
}),
|
||||
}).then((res) => res.json());
|
||||
return signs;
|
||||
return signs as SignResponse;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
@ -161,7 +161,7 @@ export class XhsClient extends XhsClientBase {
|
||||
const url = '/api/sns/web/v1/you/mentions';
|
||||
const response = await this.get(
|
||||
url,
|
||||
{ num: 20, cursor: '' },
|
||||
{ num: num, cursor: '' },
|
||||
{
|
||||
sign: this.sign.bind(this),
|
||||
needSign: true,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { app, xhsServices } from '@/app.ts';
|
||||
import { Parse } from '@/libs/parse.ts';
|
||||
import { app, xhsServices } from '@kevisual/xhs/app.ts';
|
||||
import { Parse } from '@kevisual/xhs/libs/parse.ts';
|
||||
app
|
||||
.route({
|
||||
path: 'fans',
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { app, xhsServices } from '@/app.ts';
|
||||
import { app, xhsServices } from '@kevisual/xhs/app.ts';
|
||||
|
||||
app
|
||||
.route({
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { app, xhsServices } from '@/app.ts';
|
||||
import { Mention } from '@/libs/xhs-type/mention.ts';
|
||||
import { Parse } from '@/libs/parse.ts';
|
||||
import { app, xhsServices } from '@kevisual/xhs/app.ts';
|
||||
import { Mention } from '@kevisual/xhs/libs/xhs-type/mention.ts';
|
||||
import { Parse } from '@kevisual/xhs/libs/parse.ts';
|
||||
|
||||
app
|
||||
.route({
|
||||
@ -20,7 +20,7 @@ app
|
||||
path: 'mention',
|
||||
key: 'getMention',
|
||||
payload: {
|
||||
num: 2,
|
||||
num: unread_count,
|
||||
},
|
||||
});
|
||||
if (mentionRes.code === 200) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { InitOptions, Model, Sequelize, SyncOptions } from 'sequelize';
|
||||
import { DBModel, Sequelize, SyncOptions } from '@kevisual/db';
|
||||
import { DataTypes } from 'sequelize';
|
||||
export class Comment extends Model {
|
||||
export class Comment extends DBModel {
|
||||
declare id: number;
|
||||
declare content: string;
|
||||
declare note_id: string;
|
||||
@ -8,7 +8,7 @@ export class Comment extends Model {
|
||||
declare comment_id: string;
|
||||
declare created_at: Date;
|
||||
declare updated_at: Date;
|
||||
static async initModel(sequelize: Sequelize, initOptions?: InitOptions, opts?: SyncOptions) {
|
||||
static async initModel(sequelize: Sequelize, opts?: SyncOptions) {
|
||||
Comment.init(
|
||||
{
|
||||
id: {
|
||||
@ -36,7 +36,6 @@ export class Comment extends Model {
|
||||
{
|
||||
sequelize, // passing the `sequelize` instance is required
|
||||
modelName: 'Comment', // we need to choose the model name
|
||||
...initOptions,
|
||||
},
|
||||
);
|
||||
await Comment.sync(opts || {});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { XhsClient } from '@/libs/xhs.ts';
|
||||
import { XhsClient } from '@kevisual/xhs/libs/xhs.ts';
|
||||
import { Sequelize } from 'sequelize';
|
||||
import { createSequelize } from '@/services/xhs-db/db.ts';
|
||||
import { createSequelize } from '@kevisual/xhs/services/xhs-db/db.ts';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
@ -22,6 +22,10 @@ type XhsClientMap = {
|
||||
type XhsServicesOptions = {
|
||||
root?: string;
|
||||
};
|
||||
/**
|
||||
* @description XhsServices is a singleton class that manages the XhsClient instances.
|
||||
* It is used to create and manage the XhsClient instances.
|
||||
*/
|
||||
export class XhsServices {
|
||||
map: Map<string, XhsClientMap> = new Map();
|
||||
root: string = 'root';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Comment } from '@/services/xhs-db/comment.ts';
|
||||
import { Comment } from '@kevisual/xhs/services/xhs-db/comment.ts';
|
||||
|
||||
import { Sequelize, Model, DataTypes, InferAttributes, InferCreationAttributes } from 'sequelize';
|
||||
import path from 'path';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { app } from '@/index.ts';
|
||||
import { app } from '@kevisual/xhs/index.ts';
|
||||
|
||||
app.parse({
|
||||
path: 'mention',
|
||||
|
Binary file not shown.
@ -5,13 +5,8 @@
|
||||
"lib": [
|
||||
"ESNext"
|
||||
],
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"types": [
|
||||
"node_modules/@types"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"@kevisual/xhs/*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
|
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
@ -42,6 +42,9 @@ importers:
|
||||
'@kevisual/types':
|
||||
specifier: ^0.0.9
|
||||
version: 0.0.9
|
||||
'@kevisual/xhs':
|
||||
specifier: workspace:*
|
||||
version: link:packages/xhs
|
||||
'@types/bun':
|
||||
specifier: ^1.2.11
|
||||
version: 1.2.11
|
||||
@ -109,6 +112,9 @@ importers:
|
||||
|
||||
packages/xhs:
|
||||
dependencies:
|
||||
'@kevisual/db':
|
||||
specifier: ^0.0.1
|
||||
version: 0.0.1
|
||||
nanoid:
|
||||
specifier: ^5.1.5
|
||||
version: 5.1.5
|
||||
@ -119,6 +125,9 @@ importers:
|
||||
specifier: ^5.1.7
|
||||
version: 5.1.7
|
||||
devDependencies:
|
||||
'@kevisual/use-config':
|
||||
specifier: ^1.0.14
|
||||
version: 1.0.14(dotenv@16.5.0)
|
||||
'@kevisual/xhs-core':
|
||||
specifier: workspace:*
|
||||
version: link:../xhs-core
|
||||
@ -211,6 +220,9 @@ packages:
|
||||
pg: ^8.13.3
|
||||
sequelize: ^6.37.5
|
||||
|
||||
'@kevisual/db@0.0.1':
|
||||
resolution: {integrity: sha512-FgDS5FzcU5Um2UV6EYQN4+D4R24M6/A7DANMPpvTpRioS94apKsnthZQWNL65e6gPc4ca3ys8zygrF6rd3ZA7Q==}
|
||||
|
||||
'@kevisual/dts@0.0.2':
|
||||
resolution: {integrity: sha512-AFULZR011hH8g6F30djbUlIgbG2y4AbEXml+1jotLC0Mf87apZ7LYlb9amxVSiPqOmtXYKETsI47RDzgihBpLw==}
|
||||
hasBin: true
|
||||
@ -229,6 +241,11 @@ packages:
|
||||
peerDependencies:
|
||||
dotenv: ^16.4.7
|
||||
|
||||
'@kevisual/use-config@1.0.14':
|
||||
resolution: {integrity: sha512-U4fmPFJre+Ph+hdg+EKVaRGxdpD4T4ZoOz5QLEyC6o3ekg8NC4n1i7Myo1ektqATyoG9Y0q/bJdOhiJwnLEt4g==}
|
||||
peerDependencies:
|
||||
dotenv: ^16.4.7
|
||||
|
||||
'@ljharb/resumer@0.1.3':
|
||||
resolution: {integrity: sha512-d+tsDgfkj9X5QTriqM4lKesCkMMJC3IrbPKHvayP00ELx2axdXvDfWkqjxrLXIzGcQzmj7VAUT1wopqARTvafw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@ -2099,6 +2116,8 @@ snapshots:
|
||||
- supports-color
|
||||
- utf-8-validate
|
||||
|
||||
'@kevisual/db@0.0.1': {}
|
||||
|
||||
'@kevisual/dts@0.0.2(typescript@5.8.3)':
|
||||
dependencies:
|
||||
rollup: 4.40.1
|
||||
@ -2122,6 +2141,11 @@ snapshots:
|
||||
'@kevisual/load': 0.0.6
|
||||
dotenv: 16.5.0
|
||||
|
||||
'@kevisual/use-config@1.0.14(dotenv@16.5.0)':
|
||||
dependencies:
|
||||
'@kevisual/load': 0.0.6
|
||||
dotenv: 16.5.0
|
||||
|
||||
'@ljharb/resumer@0.1.3':
|
||||
dependencies:
|
||||
'@ljharb/through': 2.3.14
|
||||
|
33
src/services/xhs-task.ts
Normal file
33
src/services/xhs-task.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Queue } from 'bullmq';
|
||||
import { app } from '@kevisual/xhs/index';
|
||||
import { QueryRouterServer } from '@kevisual/router';
|
||||
|
||||
type XhsTaskOptions = {
|
||||
queue: Queue;
|
||||
};
|
||||
export class XhsTask {
|
||||
queue: Queue;
|
||||
constructor(opts: XhsTaskOptions) {
|
||||
this.queue = opts.queue;
|
||||
}
|
||||
async getUnread() {
|
||||
const res = await app.call({
|
||||
path: 'mention',
|
||||
key: 'getUnread',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const qs = new QueryRouterServer();
|
||||
|
||||
qs.route({
|
||||
path: 'task',
|
||||
key: 'getUnread',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const unread_count = 0;
|
||||
if (unread_count > 0) {
|
||||
|
||||
}
|
||||
})
|
||||
.addTo(qs);
|
@ -1,2 +1,3 @@
|
||||
// https://edith.xiaohongshu.com/api/sns/web/unread_count
|
||||
export const XHS_GET_UNREAD = 'unread_count';
|
||||
export const XHS_QUEUE_NAME = 'XHS_QUEUE';
|
@ -1,7 +1,8 @@
|
||||
import { redis } from '@/modules/redis.ts';
|
||||
import { Queue } from 'bullmq';
|
||||
import { nanoid } from 'nanoid';
|
||||
const XHS_QUEUE_NAME = 'XHS_QUEUE';
|
||||
import { XHS_QUEUE_NAME } from '@/task/common.ts';
|
||||
|
||||
export const queue = new Queue(XHS_QUEUE_NAME, {
|
||||
connection: redis,
|
||||
});
|
||||
|
15
src/test/router.ts
Normal file
15
src/test/router.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { App, QueryRouterServer } from '@kevisual/router';
|
||||
|
||||
export const app = new App();
|
||||
app
|
||||
.route({
|
||||
path: 'k',
|
||||
key: 'k',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = 'hello world';
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
const res = await app.router.queryRoute({ path: 'k', key: 'k' });
|
||||
console.log('res', res);
|
Loading…
x
Reference in New Issue
Block a user