remove pino

This commit is contained in:
熊潇 2025-05-08 23:43:56 +08:00
parent aa4d2b5451
commit c3b24ec29c
9 changed files with 1945 additions and 200 deletions

View File

@ -38,16 +38,17 @@
],
"license": "UNLICENSED",
"dependencies": {
"@kevisual/local-app-manager": "0.1.11-beta.2",
"@kevisual/router": "0.0.9",
"@kevisual/use-config": "^1.0.10",
"@kevisual/local-app-manager": "0.1.17",
"@kevisual/logger": "^0.0.1",
"@kevisual/router": "0.0.13",
"@kevisual/use-config": "^1.0.15",
"@types/semver": "^7.7.0",
"archiver": "^7.0.1",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.13",
"dotenv": "^16.4.7",
"formidable": "^3.5.2",
"ioredis": "^5.6.0",
"dotenv": "^16.5.0",
"formidable": "^3.5.4",
"ioredis": "^5.6.1",
"json5": "^2.2.3",
"jsonwebtoken": "^9.0.2",
"lodash-es": "^4.17.21",
@ -55,9 +56,7 @@
"nanoid": "^5.1.5",
"node-fetch": "^3.3.2",
"p-queue": "^8.1.0",
"pg": "^8.14.1",
"pino": "^9.6.0",
"pino-pretty": "^13.0.0",
"pg": "^8.15.6",
"pm2": "^6.0.5",
"rollup-plugin-esbuild": "^6.2.1",
"semver": "^7.7.1",
@ -66,13 +65,13 @@
"strip-ansi": "^7.1.0",
"tar": "^7.4.3",
"uuid": "^11.1.0",
"zod": "^3.24.2"
"zod": "^3.24.4"
},
"devDependencies": {
"@kevisual/code-center-module": "workspace:*",
"@kevisual/oss": "workspace:*",
"@kevisual/permission": "workspace:*",
"@kevisual/types": "^0.0.6",
"@kevisual/types": "^0.0.9",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-commonjs": "^28.0.3",
"@rollup/plugin-json": "^6.1.0",
@ -84,20 +83,20 @@
"@types/formidable": "^3.4.5",
"@types/jsonwebtoken": "^9.0.9",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.13.14",
"@types/react": "^19.0.12",
"@types/node": "^22.15.17",
"@types/react": "^19.1.3",
"@types/uuid": "^10.0.0",
"concurrently": "^9.1.2",
"cross-env": "^7.0.3",
"nodemon": "^3.1.9",
"nodemon": "^3.1.10",
"rimraf": "^6.0.1",
"rollup": "^4.38.0",
"rollup": "^4.40.2",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dts": "^6.2.1",
"tape": "^5.9.0",
"tsx": "^4.19.3",
"turbo": "^2.4.4",
"typescript": "^5.8.2"
"tsx": "^4.19.4",
"turbo": "^2.5.3",
"typescript": "^5.8.3"
},
"resolutions": {
"inflight": "latest",
@ -105,5 +104,5 @@
"picomatch": "^4.0.2"
},
"pnpm": {},
"packageManager": "pnpm@10.7.0"
"packageManager": "pnpm@10.10.0"
}

1988
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,10 @@
import { pino } from 'pino';
import { useConfig } from '@kevisual/use-config/env';
import { Logger } from '@kevisual/logger';
const config = useConfig();
export const logger = pino({
export const logger = new Logger({
level: config.LOG_LEVEL || 'info',
transport: {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:standard',
ignore: 'pid,hostname',
},
},
serializers: {
error: pino.stdSerializers.err,
req: pino.stdSerializers.req,
res: pino.stdSerializers.res,
},
base: {
app: 'code-center',
env: process.env.NODE_ENV || 'production',
},
showTime: true,
});
export const logError = (message: string, data?: any) => logger.error({ data }, message);

View File

@ -9,6 +9,8 @@ import { User } from '@/models/user.ts';
import fs from 'fs';
import { ConfigModel } from '@/routes/config/models/model.ts';
import { validateDirectory } from './util.ts';
import { pick } from 'lodash-es';
import { getFileStat } from '@/routes/file/index.ts';
const cacheFilePath = useFileStore('cache-file', { needExists: true });
@ -16,6 +18,77 @@ router.get('/api/s1/resources/upload', async (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Upload API is ready');
});
export const parseIfJson = (data = '{}') => {
try {
const _data = JSON.parse(data);
if (typeof _data === 'object') return _data;
return {};
} catch (error) {
return {};
}
};
router.post('/api/s1/resources/upload/check', async (req, res) => {
const { tokenUser, token } = await checkAuth(req, res);
if (!tokenUser) {
res.end(error('Token is invalid.'));
return;
}
console.log('data', req.url);
const data = await router.getBody(req);
type Data = {
appKey: string;
version: string;
username: string;
directory: string;
files: { path: string; hash: string }[];
};
let { appKey, version, username, directory, files } = pick(data, ['appKey', 'version', 'username', 'directory', 'files']) as Data;
let uid = tokenUser.id;
if (username) {
const user = await User.getUserByToken(token);
const has = await user.hasUser(username, true);
if (!has) {
res.end(error('username is not found'));
return;
}
const _user = await User.findOne({ where: { username } });
uid = _user?.id || '';
}
if (!appKey || !version) {
res.end(error('appKey and version is required'));
}
const { code, message } = validateDirectory(directory);
if (code !== 200) {
res.end(error(message));
return;
}
type CheckResult = {
path: string;
stat: any;
resourcePath: string;
hash: string;
uploadHash: string;
isUpload?: boolean;
};
const checkResult: CheckResult[] = [];
for (let i = 0; i < files.length; i++) {
const file = files[i];
const relativePath = file.path;
const minioPath = `${username || tokenUser.username}/${appKey}/${version}${directory ? `/${directory}` : ''}/${relativePath}`;
let stat = await getFileStat(minioPath, true);
const statHash = stat?.etag || '';
checkResult.push({
path: relativePath,
uploadHash: file.hash,
resourcePath: minioPath,
isUpload: statHash === file.hash,
stat,
hash: statHash,
});
}
res.end(JSON.stringify({ code: 200, data: checkResult }));
});
// /api/s1/resources/upload
router.post('/api/s1/resources/upload', async (req, res) => {
@ -26,6 +99,7 @@ router.post('/api/s1/resources/upload', async (req, res) => {
}
const url = new URL(req.url || '', 'http://localhost');
const share = !!url.searchParams.get('public');
const meta = parseIfJson(url.searchParams.get('meta'));
const noCheckAppFiles = !!url.searchParams.get('noCheckAppFiles');
// 使用 formi dable 解析 multipart/form-data
const form = new IncomingForm({
@ -106,6 +180,7 @@ router.post('/api/s1/resources/upload', async (req, res) => {
if (share) {
metadata.share = 'public';
}
Object.assign(metadata, meta);
await minioClient.fPutObject(bucketName, minioPath, tempPath, {
'Content-Type': getContentType(relativePath),
'app-source': 'user-app',

View File

@ -88,7 +88,7 @@ app
}
const newApp = await app.update({ data: newData, ...rest });
ctx.body = newApp;
if (app.status !== 'running') {
if (app.status !== 'running' || data?.share || rest?.status) {
setExpire(newApp.key, app.user);
}
} else {

View File

@ -1,7 +1,7 @@
import dayjs from 'dayjs';
import { minioClient } from '../../../modules/minio.ts';
import { bucketName } from '../../../modules/minio.ts';
import { CopyDestinationOptions, CopySourceOptions } from 'minio';
import { BucketItemStat, CopyDestinationOptions, CopySourceOptions } from 'minio';
type MinioListOpt = {
prefix: string;
recursive?: boolean;
@ -43,7 +43,7 @@ export const getMinioList = async <IS_FILE extends boolean>(opts: MinioListOpt):
});
return res as IS_FILE extends true ? MinioFile[] : MinioDirectory[];
};
export const getFileStat = async (prefix: string, isFile?: boolean): Promise<any> => {
export const getFileStat = async (prefix: string, isFile?: boolean): Promise<BucketItemStat | null> => {
try {
const obj = await minioClient.statObject(bucketName, prefix);
if (isFile && obj.size === 0) {
@ -174,7 +174,8 @@ export const mvUserAToUserB = async (usernameA: string, usernameB: string, clear
const source = new CopySourceOptions({ Bucket: bucketName, Object: item.name });
const stat = await getFileStat(item.name);
const newName = item.name.slice(oldPrefix.length);
const metadata = stat?.userMetadata;
// @ts-ignore
const metadata = stat?.userMetadata || stat.metaData;
const destination = new CopyDestinationOptions({
Bucket: bucketName,
Object: `${newPrefix}${newName}`,

View File

@ -9,6 +9,7 @@ export type MarkData = {
mdList?: string[]; // markdown list
type?: string; // 类型 markdown | json | html | image | video | audio | code | link | file
data?: any;
key?: string; // 文件的名称, 唯一
push?: boolean; // 是否推送到elasticsearch
pushTime?: Date; // 推送时间
summary?: string; // 摘要
@ -47,7 +48,7 @@ export class MarkModel extends Model {
declare description: string; // 描述可以ai生成
declare cover: string; // 封面可以ai生成
declare thumbnail: string; // 缩略图
declare key: string; // 文件路径
declare markType: string; // markdown | json | html | image | video | audio | code | link | file
declare link: string; // 访问链接
declare tags: string[]; // 标签
@ -231,6 +232,10 @@ export const MarkMInit = async <T = any>(opts: MarkInitOpts<T>, sync?: Opts) =>
type: DataTypes.TEXT,
defaultValue: '',
},
key: {
type: DataTypes.TEXT,
defaultValue: '',
},
markType: {
type: DataTypes.TEXT,
defaultValue: 'md', // markdown | json | html | image | video | audio | code | link | file
@ -316,4 +321,4 @@ export const syncMarkModel = async (sync?: Opts) => {
await MarkMInit({ sequelize, tableName: 'micro_mark' }, sync);
};
syncMarkModel({ sync: true, alter: true, logging: false });
syncMarkModel({ sync: true, alter: true, logging: false });

View File

@ -38,7 +38,7 @@ export const changeRootPassword = async () => {
});
const user = await User.findOne({ where: { username: 'root' } });
if (user) {
await user.createPassword('123456');
await user.createPassword('Abear123456x');
await user.save();
console.log('change root password done');
process.exit(0);

@ -1 +1 @@
Subproject commit 6309a577f73fd27ab284270f56a7f83c5d8e4569
Subproject commit 460f80657c8b8adc93dd34f41c3eec1704f86c46