This commit is contained in:
熊潇 2025-05-03 21:12:58 +08:00
parent c2a0623482
commit d6014b3c40
19 changed files with 115 additions and 35 deletions

View File

@ -46,6 +46,7 @@
"devDependencies": { "devDependencies": {
"@kevisual/ai-center": "^0.0.3", "@kevisual/ai-center": "^0.0.3",
"@kevisual/app-assistant": "workspace:*", "@kevisual/app-assistant": "workspace:*",
"@kevisual/xhs": "workspace:*",
"@kevisual/types": "^0.0.9", "@kevisual/types": "^0.0.9",
"@kevisual/use-config": "^1.0.12", "@kevisual/use-config": "^1.0.12",
"@types/bun": "^1.2.11", "@types/bun": "^1.2.11",

View File

@ -2,23 +2,19 @@
// https://bun.sh/docs/bundler // https://bun.sh/docs/bundler
// @ts-ignore // @ts-ignore
import pkg from './package.json'; import pkg from './package.json';
// import { resolvePath as rp } from '@kevisual/use-config/env'; import { resolvePath as rp } from '@kevisual/use-config/env';
import path from 'path';
const rp = (resolvePath) => {
return path.resolve(process.cwd(), resolvePath);
};
// bun run src/index.ts -- // bun run src/index.ts --
await Bun.build({ await Bun.build({
target: 'node', target: 'node',
format: 'esm', format: 'esm',
entrypoints: [rp('src/index.js')], entrypoints: [rp('src/index.ts')],
outdir: rp('./dist'), outdir: rp('./dist'),
naming: { naming: {
entry: 'app.mjs', entry: 'app.mjs',
}, },
define: { define: {
VERSION: JSON.stringify(pkg.version), VERSION: JSON.stringify(pkg.version),
}, },
env: 'KEVISUAL_*', external: ['sequelize'],
}); });

View File

@ -6,7 +6,7 @@
"types": "app.d.ts", "types": "app.d.ts",
"scripts": { "scripts": {
"build": "bun run bun.config.mjs", "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 ", "cmd": "tsx src/test/command.ts ",
"dts": "dts -i src/index.js -o app.d.ts" "dts": "dts -i src/index.js -o app.d.ts"
}, },
@ -22,10 +22,21 @@
"packageManager": "pnpm@10.10.0", "packageManager": "pnpm@10.10.0",
"type": "module", "type": "module",
"devDependencies": { "devDependencies": {
"@kevisual/use-config": "^1.0.14",
"@kevisual/xhs-core": "workspace:*", "@kevisual/xhs-core": "workspace:*",
"@types/node": "^22.15.3" "@types/node": "^22.15.3"
}, },
"exports": {
".": {
"import": "./dist/app.mjs",
"types": "./dist/app.d.ts"
},
"./index": {
"import": "./src/index.ts"
}
},
"dependencies": { "dependencies": {
"@kevisual/db": "^0.0.1",
"nanoid": "^5.1.5", "nanoid": "^5.1.5",
"sequelize": "^6.37.7", "sequelize": "^6.37.7",
"sqlite3": "^5.1.7" "sqlite3": "^5.1.7"

View File

@ -1,5 +1,5 @@
import { QueryRouterServer } from '@kevisual/router'; import { QueryRouterServer } from '@kevisual/router/browser';
import { XhsServices } from '@/services/xhs-services.ts'; import { XhsServices } from '@kevisual/xhs/services/xhs-services.ts';
export const app = new QueryRouterServer(); export const app = new QueryRouterServer();
export const xhsServices = new XhsServices(); export const xhsServices = new XhsServices();

View File

@ -49,7 +49,7 @@ export const getSign = async (signInfo: SignInfo, options?: SignOptions): Promis
web_session: web_session, web_session: web_session,
}), }),
}).then((res) => res.json()); }).then((res) => res.json());
return signs; return signs as SignResponse;
} catch (error) { } catch (error) {
return null; return null;
} }
@ -161,7 +161,7 @@ export class XhsClient extends XhsClientBase {
const url = '/api/sns/web/v1/you/mentions'; const url = '/api/sns/web/v1/you/mentions';
const response = await this.get( const response = await this.get(
url, url,
{ num: 20, cursor: '' }, { num: num, cursor: '' },
{ {
sign: this.sign.bind(this), sign: this.sign.bind(this),
needSign: true, needSign: true,

View File

@ -1,5 +1,5 @@
import { app, xhsServices } from '@/app.ts'; import { app, xhsServices } from '@kevisual/xhs/app.ts';
import { Parse } from '@/libs/parse.ts'; import { Parse } from '@kevisual/xhs/libs/parse.ts';
app app
.route({ .route({
path: 'fans', path: 'fans',

View File

@ -1,4 +1,4 @@
import { app, xhsServices } from '@/app.ts'; import { app, xhsServices } from '@kevisual/xhs/app.ts';
app app
.route({ .route({

View File

@ -1,6 +1,6 @@
import { app, xhsServices } from '@/app.ts'; import { app, xhsServices } from '@kevisual/xhs/app.ts';
import { Mention } from '@/libs/xhs-type/mention.ts'; import { Mention } from '@kevisual/xhs/libs/xhs-type/mention.ts';
import { Parse } from '@/libs/parse.ts'; import { Parse } from '@kevisual/xhs/libs/parse.ts';
app app
.route({ .route({
@ -20,7 +20,7 @@ app
path: 'mention', path: 'mention',
key: 'getMention', key: 'getMention',
payload: { payload: {
num: 2, num: unread_count,
}, },
}); });
if (mentionRes.code === 200) { if (mentionRes.code === 200) {

View File

@ -1,6 +1,6 @@
import { InitOptions, Model, Sequelize, SyncOptions } from 'sequelize'; import { DBModel, Sequelize, SyncOptions } from '@kevisual/db';
import { DataTypes } from 'sequelize'; import { DataTypes } from 'sequelize';
export class Comment extends Model { export class Comment extends DBModel {
declare id: number; declare id: number;
declare content: string; declare content: string;
declare note_id: string; declare note_id: string;
@ -8,7 +8,7 @@ export class Comment extends Model {
declare comment_id: string; declare comment_id: string;
declare created_at: Date; declare created_at: Date;
declare updated_at: Date; declare updated_at: Date;
static async initModel(sequelize: Sequelize, initOptions?: InitOptions, opts?: SyncOptions) { static async initModel(sequelize: Sequelize, opts?: SyncOptions) {
Comment.init( Comment.init(
{ {
id: { id: {
@ -36,7 +36,6 @@ export class Comment extends Model {
{ {
sequelize, // passing the `sequelize` instance is required sequelize, // passing the `sequelize` instance is required
modelName: 'Comment', // we need to choose the model name modelName: 'Comment', // we need to choose the model name
...initOptions,
}, },
); );
await Comment.sync(opts || {}); await Comment.sync(opts || {});

View File

@ -1,6 +1,6 @@
import { XhsClient } from '@/libs/xhs.ts'; import { XhsClient } from '@kevisual/xhs/libs/xhs.ts';
import { Sequelize } from 'sequelize'; 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 path from 'node:path';
import fs from 'node:fs'; import fs from 'node:fs';
@ -22,6 +22,10 @@ type XhsClientMap = {
type XhsServicesOptions = { type XhsServicesOptions = {
root?: string; 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 { export class XhsServices {
map: Map<string, XhsClientMap> = new Map(); map: Map<string, XhsClientMap> = new Map();
root: string = 'root'; root: string = 'root';

View File

@ -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 { Sequelize, Model, DataTypes, InferAttributes, InferCreationAttributes } from 'sequelize';
import path from 'path'; import path from 'path';

View File

@ -1,4 +1,4 @@
import { app } from '@/index.ts'; import { app } from '@kevisual/xhs/index.ts';
app.parse({ app.parse({
path: 'mention', path: 'mention',

Binary file not shown.

View File

@ -5,13 +5,8 @@
"lib": [ "lib": [
"ESNext" "ESNext"
], ],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"types": [
"node_modules/@types"
],
"paths": { "paths": {
"@/*": [ "@kevisual/xhs/*": [
"src/*" "src/*"
] ]
} }

24
pnpm-lock.yaml generated
View File

@ -42,6 +42,9 @@ importers:
'@kevisual/types': '@kevisual/types':
specifier: ^0.0.9 specifier: ^0.0.9
version: 0.0.9 version: 0.0.9
'@kevisual/xhs':
specifier: workspace:*
version: link:packages/xhs
'@types/bun': '@types/bun':
specifier: ^1.2.11 specifier: ^1.2.11
version: 1.2.11 version: 1.2.11
@ -109,6 +112,9 @@ importers:
packages/xhs: packages/xhs:
dependencies: dependencies:
'@kevisual/db':
specifier: ^0.0.1
version: 0.0.1
nanoid: nanoid:
specifier: ^5.1.5 specifier: ^5.1.5
version: 5.1.5 version: 5.1.5
@ -119,6 +125,9 @@ importers:
specifier: ^5.1.7 specifier: ^5.1.7
version: 5.1.7 version: 5.1.7
devDependencies: devDependencies:
'@kevisual/use-config':
specifier: ^1.0.14
version: 1.0.14(dotenv@16.5.0)
'@kevisual/xhs-core': '@kevisual/xhs-core':
specifier: workspace:* specifier: workspace:*
version: link:../xhs-core version: link:../xhs-core
@ -211,6 +220,9 @@ packages:
pg: ^8.13.3 pg: ^8.13.3
sequelize: ^6.37.5 sequelize: ^6.37.5
'@kevisual/db@0.0.1':
resolution: {integrity: sha512-FgDS5FzcU5Um2UV6EYQN4+D4R24M6/A7DANMPpvTpRioS94apKsnthZQWNL65e6gPc4ca3ys8zygrF6rd3ZA7Q==}
'@kevisual/dts@0.0.2': '@kevisual/dts@0.0.2':
resolution: {integrity: sha512-AFULZR011hH8g6F30djbUlIgbG2y4AbEXml+1jotLC0Mf87apZ7LYlb9amxVSiPqOmtXYKETsI47RDzgihBpLw==} resolution: {integrity: sha512-AFULZR011hH8g6F30djbUlIgbG2y4AbEXml+1jotLC0Mf87apZ7LYlb9amxVSiPqOmtXYKETsI47RDzgihBpLw==}
hasBin: true hasBin: true
@ -229,6 +241,11 @@ packages:
peerDependencies: peerDependencies:
dotenv: ^16.4.7 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': '@ljharb/resumer@0.1.3':
resolution: {integrity: sha512-d+tsDgfkj9X5QTriqM4lKesCkMMJC3IrbPKHvayP00ELx2axdXvDfWkqjxrLXIzGcQzmj7VAUT1wopqARTvafw==} resolution: {integrity: sha512-d+tsDgfkj9X5QTriqM4lKesCkMMJC3IrbPKHvayP00ELx2axdXvDfWkqjxrLXIzGcQzmj7VAUT1wopqARTvafw==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
@ -2099,6 +2116,8 @@ snapshots:
- supports-color - supports-color
- utf-8-validate - utf-8-validate
'@kevisual/db@0.0.1': {}
'@kevisual/dts@0.0.2(typescript@5.8.3)': '@kevisual/dts@0.0.2(typescript@5.8.3)':
dependencies: dependencies:
rollup: 4.40.1 rollup: 4.40.1
@ -2122,6 +2141,11 @@ snapshots:
'@kevisual/load': 0.0.6 '@kevisual/load': 0.0.6
dotenv: 16.5.0 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': '@ljharb/resumer@0.1.3':
dependencies: dependencies:
'@ljharb/through': 2.3.14 '@ljharb/through': 2.3.14

33
src/services/xhs-task.ts Normal file
View 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);

View File

@ -1,2 +1,3 @@
// https://edith.xiaohongshu.com/api/sns/web/unread_count // https://edith.xiaohongshu.com/api/sns/web/unread_count
export const XHS_GET_UNREAD = 'unread_count'; export const XHS_GET_UNREAD = 'unread_count';
export const XHS_QUEUE_NAME = 'XHS_QUEUE';

View File

@ -1,7 +1,8 @@
import { redis } from '@/modules/redis.ts'; import { redis } from '@/modules/redis.ts';
import { Queue } from 'bullmq'; import { Queue } from 'bullmq';
import { nanoid } from 'nanoid'; 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, { export const queue = new Queue(XHS_QUEUE_NAME, {
connection: redis, connection: redis,
}); });

15
src/test/router.ts Normal file
View 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);