fix: 修改config和推出登陆

This commit is contained in:
xion 2025-03-22 19:49:35 +08:00
parent d739bd12b3
commit 5f63c4cf4b
6 changed files with 92 additions and 42 deletions

View File

@ -35,7 +35,6 @@
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
"@kevisual/local-app-manager": "0.1.9", "@kevisual/local-app-manager": "0.1.9",
"@kevisual/permission": "workspace:*",
"@kevisual/router": "0.0.9", "@kevisual/router": "0.0.9",
"@kevisual/use-config": "^1.0.9", "@kevisual/use-config": "^1.0.9",
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
@ -64,6 +63,8 @@
}, },
"devDependencies": { "devDependencies": {
"@kevisual/code-center-module": "workspace:*", "@kevisual/code-center-module": "workspace:*",
"@kevisual/permission": "workspace:*",
"@kevisual/oss": "workspace:*",
"@kevisual/types": "^0.0.6", "@kevisual/types": "^0.0.6",
"@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-commonjs": "^28.0.3", "@rollup/plugin-commonjs": "^28.0.3",
@ -76,7 +77,7 @@
"@types/formidable": "^3.4.5", "@types/formidable": "^3.4.5",
"@types/jsonwebtoken": "^9.0.9", "@types/jsonwebtoken": "^9.0.9",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/node": "^22.13.10", "@types/node": "^22.13.11",
"@types/react": "^19.0.12", "@types/react": "^19.0.12",
"@types/uuid": "^10.0.0", "@types/uuid": "^10.0.0",
"concurrently": "^9.1.2", "concurrently": "^9.1.2",
@ -85,7 +86,7 @@
"rimraf": "^6.0.1", "rimraf": "^6.0.1",
"rollup": "^4.36.0", "rollup": "^4.36.0",
"rollup-plugin-copy": "^3.5.0", "rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dts": "^6.2.0", "rollup-plugin-dts": "^6.2.1",
"tape": "^5.9.0", "tape": "^5.9.0",
"tsx": "^4.19.3", "tsx": "^4.19.3",
"turbo": "^2.4.4", "turbo": "^2.4.4",
@ -97,5 +98,5 @@
"picomatch": "^4.0.2" "picomatch": "^4.0.2"
}, },
"pnpm": {}, "pnpm": {},
"packageManager": "pnpm@9.15.0" "packageManager": "pnpm@10.6.5"
} }

48
pnpm-lock.yaml generated
View File

@ -135,8 +135,8 @@ importers:
specifier: ^4.17.12 specifier: ^4.17.12
version: 4.17.12 version: 4.17.12
'@types/node': '@types/node':
specifier: ^22.13.10 specifier: ^22.13.11
version: 22.13.10 version: 22.13.11
'@types/react': '@types/react':
specifier: ^19.0.12 specifier: ^19.0.12
version: 19.0.12 version: 19.0.12
@ -162,8 +162,8 @@ importers:
specifier: ^3.5.0 specifier: ^3.5.0
version: 3.5.0 version: 3.5.0
rollup-plugin-dts: rollup-plugin-dts:
specifier: ^6.2.0 specifier: ^6.2.1
version: 6.2.0(rollup@4.36.0)(typescript@5.8.2) version: 6.2.1(rollup@4.36.0)(typescript@5.8.2)
tape: tape:
specifier: ^5.9.0 specifier: ^5.9.0
version: 5.9.0 version: 5.9.0
@ -286,6 +286,15 @@ importers:
specifier: ^5.8.2 specifier: ^5.8.2
version: 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: submodules/permission:
devDependencies: devDependencies:
tsup: tsup:
@ -853,6 +862,9 @@ packages:
'@types/node@22.13.10': '@types/node@22.13.10':
resolution: {integrity: sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==} resolution: {integrity: sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==}
'@types/node@22.13.11':
resolution: {integrity: sha512-iEUCUJoU0i3VnrCmgoWCXttklWcvoCIx4jzcP22fioIVSdTmjgoEvmAO/QPw6TcS9k5FrNgn4w7q5lGOd1CT5g==}
'@types/react@19.0.10': '@types/react@19.0.10':
resolution: {integrity: sha512-JuRQ9KXLEjaUNjTWpzuR231Z2WpIwczOkBEIvbHNCzQefFIT0L8IqE6NV6ULLyC1SI/i234JnDoMkfg+RjQj2g==} resolution: {integrity: sha512-JuRQ9KXLEjaUNjTWpzuR231Z2WpIwczOkBEIvbHNCzQefFIT0L8IqE6NV6ULLyC1SI/i234JnDoMkfg+RjQj2g==}
@ -2287,8 +2299,8 @@ packages:
rollup: ^3.29.4 || ^4 rollup: ^3.29.4 || ^4
typescript: ^4.5 || ^5.0 typescript: ^4.5 || ^5.0
rollup-plugin-dts@6.2.0: rollup-plugin-dts@6.2.1:
resolution: {integrity: sha512-iciY+z46mUbN5nCxtJqVynwgrZZljM8of6k8Rg5rVAmu4VHDxexFPgoCa2wrJG5mMsHSGrJmjQPCM4vD0Oe3Lg==} resolution: {integrity: sha512-sR3CxYUl7i2CHa0O7bA45mCrgADyAQ0tVtGSqi3yvH28M+eg1+g5d7kQ9hLvEz5dorK3XVsH5L2jwHLQf72DzA==}
engines: {node: '>=16'} engines: {node: '>=16'}
peerDependencies: peerDependencies:
rollup: ^3.29.4 || ^4 rollup: ^3.29.4 || ^4
@ -3330,7 +3342,7 @@ snapshots:
'@types/cors@2.8.17': '@types/cors@2.8.17':
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/crypto-js@4.2.2': {} '@types/crypto-js@4.2.2': {}
@ -3342,21 +3354,21 @@ snapshots:
'@types/formidable@3.4.5': '@types/formidable@3.4.5':
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/fs-extra@8.1.5': '@types/fs-extra@8.1.5':
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/glob@7.2.0': '@types/glob@7.2.0':
dependencies: dependencies:
'@types/minimatch': 5.1.2 '@types/minimatch': 5.1.2
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/jsonwebtoken@9.0.9': '@types/jsonwebtoken@9.0.9':
dependencies: dependencies:
'@types/ms': 0.7.34 '@types/ms': 0.7.34
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/lodash-es@4.17.12': '@types/lodash-es@4.17.12':
dependencies: dependencies:
@ -3370,12 +3382,16 @@ snapshots:
'@types/node-forge@1.3.11': '@types/node-forge@1.3.11':
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/node@22.13.10': '@types/node@22.13.10':
dependencies: dependencies:
undici-types: 6.20.0 undici-types: 6.20.0
'@types/node@22.13.11':
dependencies:
undici-types: 6.20.0
'@types/react@19.0.10': '@types/react@19.0.10':
dependencies: dependencies:
csstype: 3.1.3 csstype: 3.1.3
@ -3386,7 +3402,7 @@ snapshots:
'@types/readdir-glob@1.1.5': '@types/readdir-glob@1.1.5':
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.11
'@types/resolve@1.20.2': {} '@types/resolve@1.20.2': {}
@ -3797,7 +3813,7 @@ snapshots:
dependencies: dependencies:
'@types/cookie': 0.4.1 '@types/cookie': 0.4.1
'@types/cors': 2.8.17 '@types/cors': 2.8.17
'@types/node': 22.13.10 '@types/node': 22.13.11
accepts: 1.3.8 accepts: 1.3.8
base64id: 2.0.0 base64id: 2.0.0
cookie: 0.4.2 cookie: 0.4.2
@ -4949,7 +4965,7 @@ snapshots:
optionalDependencies: optionalDependencies:
'@babel/code-frame': 7.26.2 '@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: dependencies:
magic-string: 0.30.17 magic-string: 0.30.17
rollup: 4.36.0 rollup: 4.36.0
@ -5575,7 +5591,7 @@ snapshots:
wkx@0.5.0: wkx@0.5.0:
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.11
wrap-ansi@7.0.0: wrap-ansi@7.0.0:
dependencies: dependencies:

View File

@ -30,10 +30,16 @@ app
.define(async (ctx) => { .define(async (ctx) => {
const tokernUser = ctx.state.tokenUser; const tokernUser = ctx.state.tokenUser;
const tuid = tokernUser.id; const tuid = tokernUser.id;
const { id, key, data, ...rest } = ctx.query?.data || {}; const { id, data, ...rest } = ctx.query?.data || {};
if (id) { if (id) {
const config = await ConfigModel.findByPk(id); const config = await ConfigModel.findByPk(id);
let keyIsChange = false;
if (rest?.key) {
keyIsChange = rest.key !== config?.key;
}
if (config && config.uid === tuid) { if (config && config.uid === tuid) {
if (keyIsChange) {
const key = rest.key;
const keyConfig = await ConfigModel.findOne({ const keyConfig = await ConfigModel.findOne({
where: { where: {
key, key,
@ -43,8 +49,8 @@ app
if (keyConfig && keyConfig.id !== id) { if (keyConfig && keyConfig.id !== id) {
ctx.throw(403, 'key is already exists'); ctx.throw(403, 'key is already exists');
} }
}
await config.update({ await config.update({
key,
data: { data: {
...config.data, ...config.data,
...data, ...data,
@ -58,7 +64,9 @@ app
} else { } else {
ctx.throw(403, 'no permission'); ctx.throw(403, 'no permission');
} }
} else { } else if (rest?.key) {
// id 不存在key存在则属于更新key不能重复
const key = rest.key;
const keyConfig = await ConfigModel.findOne({ const keyConfig = await ConfigModel.findOne({
where: { where: {
key, key,
@ -66,8 +74,12 @@ app
}, },
}); });
if (keyConfig) { 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({ const config = await ConfigModel.create({
key, key,
...rest, ...rest,
@ -76,6 +88,16 @@ app
}); });
ctx.body = config; 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); .addTo(app);

View File

@ -19,6 +19,9 @@ export class ConfigModel extends Model {
declare title: string; declare title: string;
declare description: string; declare description: string;
declare tags: string[]; declare tags: string[];
/**
* key
*/
declare key: string; declare key: string;
declare data: ConfigData; // files declare data: ConfigData; // files
declare uid: string; declare uid: string;
@ -74,7 +77,7 @@ export class ConfigModel extends Model {
key: 'upload', key: 'upload',
version: '1.0.0', version: '1.0.0',
}; };
const config = await ConfigModel.getConfig('upload', { const config = await ConfigModel.getConfig('upload.json', {
uid: opts.uid, uid: opts.uid,
defaultData: defaultConfig, defaultData: defaultConfig,
}); });
@ -87,7 +90,7 @@ export class ConfigModel extends Model {
}; };
} }
static async setUploadConfig(opts: { uid: string; data: { key?: string; version?: string } }) { 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, uid: opts.uid,
data: opts.data, data: opts.data,
}); });

View File

@ -51,7 +51,7 @@ export class ShareConfigService extends ConfigModel {
} }
static async expireShareConfig(key: string, username: string) { static async expireShareConfig(key: string, username: string) {
if (key && username) { if (key && username) {
await redis.set(`config:share:${username}:${key}`, '', 'EX', 0); await redis.set(`config:share:${username}:${key}`, '', 'EX', 1);
} }
} }
} }

View File

@ -99,7 +99,15 @@ app
key: 'logout', key: 'logout',
}) })
.define(async (ctx) => { .define(async (ctx) => {
const { tokens = [] } = ctx.query?.data || {};
clearCookie(ctx); clearCookie(ctx);
for (const token of tokens) {
await User.oauth.delToken(token);
}
ctx.body = {
code: 200,
message: 'Logout Success',
};
}) })
.addTo(app); .addTo(app);
app app