@kevisual/api 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/api",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "mod.ts",
6
6
  "scripts": {
@@ -18,11 +18,12 @@
18
18
  "keywords": [],
19
19
  "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
20
20
  "license": "MIT",
21
- "packageManager": "pnpm@10.26.1",
21
+ "packageManager": "pnpm@10.26.2",
22
22
  "type": "module",
23
23
  "devDependencies": {
24
+ "@kevisual/cache": "^0.0.4",
24
25
  "@kevisual/query": "^0.0.33",
25
- "@kevisual/router": "^0.0.41",
26
+ "@kevisual/router": "^0.0.51",
26
27
  "@kevisual/types": "^0.0.10",
27
28
  "@kevisual/use-config": "^1.0.21",
28
29
  "@types/bun": "^1.3.5",
@@ -31,6 +32,7 @@
31
32
  "fast-glob": "^3.3.3"
32
33
  },
33
34
  "dependencies": {
35
+ "@kevisual/load": "^0.0.6",
34
36
  "es-toolkit": "^1.43.0",
35
37
  "nanoid": "^5.1.6"
36
38
  }
@@ -1,27 +1,21 @@
1
1
  {
2
- "$schema": "https://kevisual.xiongxiao.me/root/ai/kevisual/tools/kevisual-sync/schema.json?v=2",
3
2
  "metadata": {
3
+ "name": "kevisual",
4
4
  "share": "public"
5
5
  },
6
- "checkDir": {
7
- "src/query": {
8
- "url": "https://kevisual.cn/root/ai/code/template/registry/query",
6
+ "registry": "https://kevisual.cn/root/ai/kevisual/common/query/api",
7
+ "clone": {
8
+ ".": {
9
9
  "enabled": true
10
10
  }
11
11
  },
12
- "syncDirectory": [
12
+ "syncd": [
13
13
  {
14
14
  "files": [
15
15
  "**/*"
16
16
  ],
17
- "ignore": [],
18
- "registry": "https://kevisual.cn/root/ai/code/template/registry/query"
17
+ "registry": ""
19
18
  }
20
19
  ],
21
- "sync": {
22
- "kevisual.json": {
23
- "url": "https://kevisual.cn/root/ai/code/template/registry/query/kevisual.json",
24
- "type": "none"
25
- }
26
- }
20
+ "sync": {}
27
21
  }
@@ -3,7 +3,7 @@ import type { Result, DataOpts } from '@kevisual/query/query';
3
3
  import { setBaseResponse } from '@kevisual/query/query';
4
4
  import { LoginCacheStore, CacheStore } from './login-cache.ts';
5
5
  import { Cache } from './login-cache.ts';
6
-
6
+ import { BaseLoad } from '@kevisual/load';
7
7
  export type QueryLoginOpts = {
8
8
  query?: Query;
9
9
  isBrowser?: boolean;
@@ -418,6 +418,12 @@ export class QueryLogin extends BaseQuery {
418
418
  }
419
419
  /**
420
420
  * 使用web登录,创建url地址, 需要MD5和jsonwebtoken
421
+ *
422
+ *
423
+
424
+ import MD5 from 'crypto-js/md5.js';
425
+ import jsonwebtoken from 'jsonwebtoken';
426
+
421
427
  */
422
428
  loginWithWeb(baseURL: string, { MD5, jsonwebtoken }: { MD5: any; jsonwebtoken: any }) {
423
429
  const randomId = Math.random().toString(36).substring(2, 15);
@@ -431,4 +437,46 @@ export class QueryLogin extends BaseQuery {
431
437
  const url = `${baseURL}/api/router?path=user&key=webLogin&p&loginToken=${token}&sign=${sign}&randomId=${randomId}`;
432
438
  return { url, token, tokenSecret };
433
439
  }
440
+ /**
441
+ *轮询登录状态
442
+ *
443
+ *
444
+ *
445
+ const res = queryLogin.loginWithWeb(baseURL, { MD5, jsonwebtoken });
446
+ await pollLoginStatus(res.token, { tokenSecret: res.tokenSecret });
447
+ * 轮询登录状态
448
+ */
449
+ async pollLoginStatus(data: { token: string; tokenSecret: string }) {
450
+ const token = data.token;
451
+ const load = new BaseLoad();
452
+ load.load(
453
+ async () => {
454
+ const res = await this.checkLoginStatus(token);
455
+ if (res.code === 500) {
456
+ load.cancel('check-login-status');
457
+ }
458
+ return res;
459
+ },
460
+ {
461
+ key: 'check-login-status',
462
+ isReRun: true,
463
+ checkSuccess: (data) => {
464
+ return data?.code === 200;
465
+ },
466
+ },
467
+ );
468
+ const res = await load.hasLoaded('check-login-status', {
469
+ timeout: 60 * 3 * 1000, // 3分钟超时
470
+ });
471
+ if (res.code === 200 && res.data?.code === 200) {
472
+ try {
473
+ console.log('网页登录成功');
474
+ return;
475
+ } catch (error) {
476
+ console.log('登录失败', error);
477
+ return;
478
+ }
479
+ }
480
+ console.log('登录失败', res);
481
+ }
434
482
  }
package/readme.md CHANGED
@@ -1,3 +1,169 @@
1
- # query-awesome
1
+ # @kevisual/api
2
2
 
3
- 对 kevisual 相关的query router 的模块整理
3
+ 对 kevisual 相关的query router 的模块整理
4
+
5
+ 包含的模块:
6
+
7
+ ## query-config - 配置管理模块
8
+
9
+ 提供配置的增删改查功能,支持默认配置项管理。
10
+
11
+ **主要功能:**
12
+ - 配置的获取、更新、删除
13
+ - 上传配置管理
14
+ - 默认配置项支持(upload.json, workspace.json, ai.json, user.json, life.json)
15
+ - 配置检测功能
16
+
17
+ **使用示例:**
18
+ ```typescript
19
+ import { QueryConfig } from './query-config/query-config';
20
+
21
+ const config = new QueryConfig();
22
+ await config.getConfig({ key: 'upload.json' });
23
+ await config.updateConfig({ key: 'config.json', data: { setting: true } });
24
+ ```
25
+
26
+ ## query-secret - 密钥管理模块
27
+
28
+ 用于管理敏感信息和密钥的存储与检索。
29
+
30
+ **主要功能:**
31
+ - 密钥的存储和获取
32
+ - 支持按ID或key检索
33
+ - 密钥列表管理
34
+
35
+ ## query-proxy - 代理路由模块
36
+
37
+ 提供动态路由代理功能,可以将请求转发到不同的后端服务。
38
+
39
+ **主要功能:**
40
+ - 动态路由注册
41
+ - 请求转发代理
42
+ - 路由列表管理
43
+ - Token认证支持
44
+
45
+ **使用示例:**
46
+ ```typescript
47
+ import { QueryProxy } from './query-proxy/index';
48
+
49
+ const proxy = new QueryProxy({
50
+ query: new Query(),
51
+ token: 'your-token'
52
+ });
53
+ await proxy.init(); // 初始化路由
54
+ const result = await proxy.run({ path: 'api', key: 'getData' });
55
+ ```
56
+
57
+ ## query-upload - 文件上传模块
58
+
59
+ 功能完整的文件上传解决方案,支持多种上传方式。
60
+
61
+ **主要功能:**
62
+ - 普通文件上传
63
+ - 分片上传(大文件)
64
+ - 上传进度跟踪
65
+ - 文件过滤工具
66
+ - 文件格式转换
67
+
68
+ **核心组件:**
69
+ - `uploadFiles` - 基础文件上传
70
+ - `uploadFileChunked` - 分片上传
71
+ - `UploadProgress` - 进度管理
72
+ - `filterFiles` - 文件过滤
73
+ - `toFile` - 格式转换
74
+
75
+ **使用示例:**
76
+ ```typescript
77
+ import { uploadFiles, UploadProgress } from './query-upload/query-upload';
78
+
79
+ const progress = new UploadProgress();
80
+ await uploadFiles(files, {
81
+ onProgress: (loaded, total) => {
82
+ console.log(`上传进度: ${loaded}/${total}`);
83
+ }
84
+ });
85
+ ```
86
+
87
+ ## query-app - 应用管理模块
88
+
89
+ 管理应用的注册、获取和列表功能。
90
+
91
+ **主要功能:**
92
+ - 获取应用列表
93
+ - 获取公开应用
94
+ - 获取私有应用
95
+ - 应用定义管理
96
+
97
+ ## query-shop - 应用商店模块
98
+
99
+ 应用商店功能,处理应用的安装和获取。
100
+
101
+ **主要功能:**
102
+ - 应用安装
103
+ - 商店应用管理
104
+
105
+ ## query-ai - AI对话模块
106
+
107
+ 集成AI聊天功能,支持多种模型和对话管理。
108
+
109
+ **主要功能:**
110
+ - AI对话(支持GPT等模型)
111
+ - 模型列表获取
112
+ - 聊天使用统计
113
+ - 缓存管理
114
+ - 使用限制管理
115
+
116
+ **使用示例:**
117
+ ```typescript
118
+ import { QueryAI } from './query-ai/query-ai';
119
+
120
+ const ai = new QueryAI({ query: new Query() });
121
+ const models = await ai.getModelList();
122
+ const response = await ai.chat(
123
+ { message: '你好' },
124
+ { username: 'user', model: 'gpt-3.5', group: 'default' }
125
+ );
126
+ ```
127
+
128
+ ## query-login - 登录认证模块
129
+
130
+ 完整的登录认证解决方案,支持token管理和缓存。
131
+
132
+ **主要功能:**
133
+ - 用户登录认证
134
+ - Token管理(access/refresh token)
135
+ - 登录状态缓存
136
+ - 浏览器/Node.js环境支持
137
+ - 自动token刷新
138
+
139
+ **核心组件:**
140
+ - `QueryLogin` - 主登录类
141
+ - `LoginCacheStore` - 登录缓存
142
+ - `Cache` - 通用缓存接口
143
+
144
+ ## query-resources - 资源管理模块
145
+
146
+ 管理用户资源的访问和获取。
147
+
148
+ **主要功能:**
149
+ - 资源文件获取
150
+ - 资源列表管理
151
+ - 用户认证支持
152
+ - 文件预览功能
153
+
154
+ **使用示例:**
155
+ ```typescript
156
+ import { QueryResources } from './query-resources/index';
157
+
158
+ const resources = new QueryResources({ username: 'user' });
159
+ const fileList = await resources.getList('images/');
160
+ const fileContent = await resources.fetchFile('document.pdf');
161
+ ```
162
+
163
+ ## 架构特点
164
+
165
+ - **模块化设计**:每个模块职责单一,可独立使用
166
+ - **统一接口**:基于 `@kevisual/query` 的统一查询接口
167
+ - **环境兼容**:支持浏览器和Node.js环境
168
+ - **类型安全**:完整的TypeScript类型定义
169
+ - **扩展性**:易于扩展和自定义