diff --git a/package.json b/package.json index 092dfd7..3d4b0d0 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "license": "UNLICENSED", "dependencies": { "@kevisual/local-app-manager": "0.1.9", - "@kevisual/permission": "workspace:*", "@kevisual/router": "0.0.9", "@kevisual/use-config": "^1.0.9", "@types/semver": "^7.5.8", @@ -64,6 +63,8 @@ }, "devDependencies": { "@kevisual/code-center-module": "workspace:*", + "@kevisual/permission": "workspace:*", + "@kevisual/oss": "workspace:*", "@kevisual/types": "^0.0.6", "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-commonjs": "^28.0.3", @@ -76,7 +77,7 @@ "@types/formidable": "^3.4.5", "@types/jsonwebtoken": "^9.0.9", "@types/lodash-es": "^4.17.12", - "@types/node": "^22.13.10", + "@types/node": "^22.13.11", "@types/react": "^19.0.12", "@types/uuid": "^10.0.0", "concurrently": "^9.1.2", @@ -85,7 +86,7 @@ "rimraf": "^6.0.1", "rollup": "^4.36.0", "rollup-plugin-copy": "^3.5.0", - "rollup-plugin-dts": "^6.2.0", + "rollup-plugin-dts": "^6.2.1", "tape": "^5.9.0", "tsx": "^4.19.3", "turbo": "^2.4.4", @@ -97,5 +98,5 @@ "picomatch": "^4.0.2" }, "pnpm": {}, - "packageManager": "pnpm@9.15.0" + "packageManager": "pnpm@10.6.5" } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 922d9f6..c25100e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -135,8 +135,8 @@ importers: specifier: ^4.17.12 version: 4.17.12 '@types/node': - specifier: ^22.13.10 - version: 22.13.10 + specifier: ^22.13.11 + version: 22.13.11 '@types/react': specifier: ^19.0.12 version: 19.0.12 @@ -162,8 +162,8 @@ importers: specifier: ^3.5.0 version: 3.5.0 rollup-plugin-dts: - specifier: ^6.2.0 - version: 6.2.0(rollup@4.36.0)(typescript@5.8.2) + specifier: ^6.2.1 + version: 6.2.1(rollup@4.36.0)(typescript@5.8.2) tape: specifier: ^5.9.0 version: 5.9.0 @@ -286,6 +286,15 @@ importers: specifier: ^5.8.2 version: 5.8.2 + submodules/oss: + devDependencies: + minio: + specifier: ^8.0.5 + version: 8.0.5 + tsup: + specifier: ^8.4.0 + version: 8.4.0(tsx@4.19.3)(typescript@5.8.2) + submodules/permission: devDependencies: tsup: @@ -853,6 +862,9 @@ packages: '@types/node@22.13.10': resolution: {integrity: sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==} + '@types/node@22.13.11': + resolution: {integrity: sha512-iEUCUJoU0i3VnrCmgoWCXttklWcvoCIx4jzcP22fioIVSdTmjgoEvmAO/QPw6TcS9k5FrNgn4w7q5lGOd1CT5g==} + '@types/react@19.0.10': resolution: {integrity: sha512-JuRQ9KXLEjaUNjTWpzuR231Z2WpIwczOkBEIvbHNCzQefFIT0L8IqE6NV6ULLyC1SI/i234JnDoMkfg+RjQj2g==} @@ -2287,8 +2299,8 @@ packages: rollup: ^3.29.4 || ^4 typescript: ^4.5 || ^5.0 - rollup-plugin-dts@6.2.0: - resolution: {integrity: sha512-iciY+z46mUbN5nCxtJqVynwgrZZljM8of6k8Rg5rVAmu4VHDxexFPgoCa2wrJG5mMsHSGrJmjQPCM4vD0Oe3Lg==} + rollup-plugin-dts@6.2.1: + resolution: {integrity: sha512-sR3CxYUl7i2CHa0O7bA45mCrgADyAQ0tVtGSqi3yvH28M+eg1+g5d7kQ9hLvEz5dorK3XVsH5L2jwHLQf72DzA==} engines: {node: '>=16'} peerDependencies: rollup: ^3.29.4 || ^4 @@ -3330,7 +3342,7 @@ snapshots: '@types/cors@2.8.17': dependencies: - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/crypto-js@4.2.2': {} @@ -3342,21 +3354,21 @@ snapshots: '@types/formidable@3.4.5': dependencies: - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/fs-extra@8.1.5': dependencies: - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/glob@7.2.0': dependencies: '@types/minimatch': 5.1.2 - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/jsonwebtoken@9.0.9': dependencies: '@types/ms': 0.7.34 - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/lodash-es@4.17.12': dependencies: @@ -3370,12 +3382,16 @@ snapshots: '@types/node-forge@1.3.11': dependencies: - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/node@22.13.10': dependencies: undici-types: 6.20.0 + '@types/node@22.13.11': + dependencies: + undici-types: 6.20.0 + '@types/react@19.0.10': dependencies: csstype: 3.1.3 @@ -3386,7 +3402,7 @@ snapshots: '@types/readdir-glob@1.1.5': dependencies: - '@types/node': 22.13.10 + '@types/node': 22.13.11 '@types/resolve@1.20.2': {} @@ -3797,7 +3813,7 @@ snapshots: dependencies: '@types/cookie': 0.4.1 '@types/cors': 2.8.17 - '@types/node': 22.13.10 + '@types/node': 22.13.11 accepts: 1.3.8 base64id: 2.0.0 cookie: 0.4.2 @@ -4949,7 +4965,7 @@ snapshots: optionalDependencies: '@babel/code-frame': 7.26.2 - rollup-plugin-dts@6.2.0(rollup@4.36.0)(typescript@5.8.2): + rollup-plugin-dts@6.2.1(rollup@4.36.0)(typescript@5.8.2): dependencies: magic-string: 0.30.17 rollup: 4.36.0 @@ -5575,7 +5591,7 @@ snapshots: wkx@0.5.0: dependencies: - '@types/node': 22.13.10 + '@types/node': 22.13.11 wrap-ansi@7.0.0: dependencies: diff --git a/src/routes/config/list.ts b/src/routes/config/list.ts index 6ce0e84..22b04d6 100644 --- a/src/routes/config/list.ts +++ b/src/routes/config/list.ts @@ -30,21 +30,27 @@ app .define(async (ctx) => { const tokernUser = ctx.state.tokenUser; const tuid = tokernUser.id; - const { id, key, data, ...rest } = ctx.query?.data || {}; + const { id, data, ...rest } = ctx.query?.data || {}; if (id) { const config = await ConfigModel.findByPk(id); + let keyIsChange = false; + if (rest?.key) { + keyIsChange = rest.key !== config?.key; + } if (config && config.uid === tuid) { - const keyConfig = await ConfigModel.findOne({ - where: { - key, - uid: tuid, - }, - }); - if (keyConfig && keyConfig.id !== id) { - ctx.throw(403, 'key is already exists'); + if (keyIsChange) { + const key = rest.key; + const keyConfig = await ConfigModel.findOne({ + where: { + key, + uid: tuid, + }, + }); + if (keyConfig && keyConfig.id !== id) { + ctx.throw(403, 'key is already exists'); + } } await config.update({ - key, data: { ...config.data, ...data, @@ -58,7 +64,9 @@ app } else { ctx.throw(403, 'no permission'); } - } else { + } else if (rest?.key) { + // id 不存在,key存在,则属于更新,key不能重复 + const key = rest.key; const keyConfig = await ConfigModel.findOne({ where: { key, @@ -66,16 +74,30 @@ app }, }); if (keyConfig) { - ctx.throw(403, 'key is already exists'); + await keyConfig.update({ + data: { ...keyConfig.data, ...data }, + ...rest, + }); + ctx.body = keyConfig; + } else { + const config = await ConfigModel.create({ + key, + ...rest, + data: data, + uid: tuid, + }); + ctx.body = config; } - const config = await ConfigModel.create({ - key, - ...rest, - data: data, - uid: tuid, - }); - ctx.body = config; } + if (id || rest?.key) return; + + // id和key不存在。创建一个新的配置 + const config = await ConfigModel.create({ + ...rest, + data: data, + uid: tuid, + }); + ctx.body = config; }) .addTo(app); diff --git a/src/routes/config/models/model.ts b/src/routes/config/models/model.ts index 5b822e9..485fb98 100644 --- a/src/routes/config/models/model.ts +++ b/src/routes/config/models/model.ts @@ -19,6 +19,9 @@ export class ConfigModel extends Model { declare title: string; declare description: string; declare tags: string[]; + /** + * 配置key, 默认可以为空,如何设置了,必须要唯一。 + */ declare key: string; declare data: ConfigData; // files declare uid: string; @@ -74,7 +77,7 @@ export class ConfigModel extends Model { key: 'upload', version: '1.0.0', }; - const config = await ConfigModel.getConfig('upload', { + const config = await ConfigModel.getConfig('upload.json', { uid: opts.uid, defaultData: defaultConfig, }); @@ -87,7 +90,7 @@ export class ConfigModel extends Model { }; } static async setUploadConfig(opts: { uid: string; data: { key?: string; version?: string } }) { - const config = await ConfigModel.setConfig('upload', { + const config = await ConfigModel.setConfig('upload.json', { uid: opts.uid, data: opts.data, }); diff --git a/src/routes/config/services/share.ts b/src/routes/config/services/share.ts index bf9e7e7..ddb300b 100644 --- a/src/routes/config/services/share.ts +++ b/src/routes/config/services/share.ts @@ -51,7 +51,7 @@ export class ShareConfigService extends ConfigModel { } static async expireShareConfig(key: string, username: string) { if (key && username) { - await redis.set(`config:share:${username}:${key}`, '', 'EX', 0); + await redis.set(`config:share:${username}:${key}`, '', 'EX', 1); } } } diff --git a/src/routes/user/me.ts b/src/routes/user/me.ts index 69dfac5..8b546fa 100644 --- a/src/routes/user/me.ts +++ b/src/routes/user/me.ts @@ -99,7 +99,15 @@ app key: 'logout', }) .define(async (ctx) => { + const { tokens = [] } = ctx.query?.data || {}; clearCookie(ctx); + for (const token of tokens) { + await User.oauth.delToken(token); + } + ctx.body = { + code: 200, + message: 'Logout Success', + }; }) .addTo(app); app