remove mark

This commit is contained in:
2025-12-04 10:31:37 +08:00
parent 46aa293cce
commit 2a55f2d3ef
35 changed files with 1837 additions and 726 deletions

View File

@@ -1,6 +1,6 @@
import { WxTokenResponse, fetchToken, getUserInfo, getUserInfoByMp, post } from './wx.ts';
import { useContextKey } from '@kevisual/use-config/context';
import { UserModel } from '@kevisual/code-center-module';
import { UserModel } from '../../../auth/index.ts';
import { Buffer } from 'buffer';
import { CustomError } from '@kevisual/router';
import { customAlphabet } from 'nanoid';

View File

@@ -10,7 +10,6 @@ const wx = {
appId: config.WX_MP_APP_ID,
appSecret: config.WX_MP_APP_SECRET,
}
console.log('wx config', wx, wxOpen);
export type WxTokenResponse = {
access_token: string;
expires_in: number;

View File

@@ -10,11 +10,11 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { page = 1, pageSize = 20, search, sort = 'DESC', orgId } = ctx.query;
const { page = 1, pageSize = 100, search, sort = 'DESC', orgId } = ctx.query;
const searchWhere: Record<string, any> = search
? {
[Op.or]: [{ title: { [Op.like]: `%${search}%` } }, { description: { [Op.like]: `%${search}%` } }],
}
[Op.or]: [{ title: { [Op.like]: `%${search}%` } }, { description: { [Op.like]: `%${search}%` } }],
}
: {};
if (orgId) {
searchWhere.orgId = orgId;
@@ -52,7 +52,7 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { id, updatedAt: _clear, createdAt: _clear2, token, ...rest } = ctx.query.data;
const { id, updatedAt: _clear, title = 'life', createdAt: _clear2, token, ...rest } = ctx.query.data;
let secret: UserSecret;
let isNew = false;
@@ -65,6 +65,13 @@ app
if (secret.userId !== tokenUser.userId) {
ctx.throw(403, 'No permission');
}
} else if (title) {
secret = await UserSecret.findOne({
where: {
userId: tokenUser.userId,
title,
},
});
} else {
secret = await UserSecret.createSecret(tokenUser);
isNew = true;
@@ -87,13 +94,27 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { id } = ctx.query.data || {};
const { id, title } = ctx.query.data || {};
if (!id) {
ctx.throw(400, 'id is required');
if (!id && !title) {
ctx.throw(400, 'id 或者 title 必须提供一个');
}
let secret: UserSecret;
const secret = await UserSecret.findByPk(id);
if (id) {
secret = await UserSecret.findByPk(id);
}
if (!secret && title) {
secret = await UserSecret.findOne({
where: {
userId: tokenUser.userId,
title,
},
});
if (!secret) {
ctx.throw(404, 'Secret not found');
}
}
if (!secret) {
ctx.throw(404, 'Secret not found');
@@ -115,19 +136,30 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { id } = ctx.query.data || {};
const { id, title } = ctx.query.data || {};
if (!id) {
ctx.throw(400, 'id is required');
if (!id && !title) {
ctx.throw(400, 'id 或者 title 必须提供一个');
}
const secret = await UserSecret.findByPk(id);
let secret: UserSecret | null = null;
if (id) {
secret = await UserSecret.findByPk(id);
} else if (title) {
secret = await UserSecret.findOne({
where: {
userId: tokenUser.userId,
title,
},
});
}
if (!secret) {
ctx.throw(404, 'Secret not found');
}
if (secret.userId !== tokenUser.uid) {
if (secret.userId !== tokenUser.userId) {
ctx.throw(403, 'No permission');
}

View File

@@ -1,7 +1,7 @@
import { app } from '@/app.ts';
import { User } from '@/models/user.ts';
import MD5 from 'crypto-js/md5.js';
import { authCan } from '@kevisual/code-center-module/models';
import { authCan } from '@/auth/index.ts';
import jsonwebtoken from 'jsonwebtoken';
import { redis } from '@/app.ts';