Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
h5mcbox committed Jun 19, 2024
2 parents 876b29d + ae0277f commit a219c9c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 15 deletions.
7 changes: 4 additions & 3 deletions docs/changelogs/CHANGELOG.v1.5.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
QQ Version: Windows 9.9.11-24568 / Linux 3.2.9-24568

## 修复与优化
* 修复文件残留问题
* 修复视频文件残留问题
* 重构 getcookies接口 支持大部分常见域

## 新增与调整
* 日志清理
* 支持QQ音乐 图文卡片
* 日志大小限制
* 支持 QQ音乐 卡片 无签名支持时 启用内置方法(缺点没有封面 限速1min/条)
* 支持Window X86-32机器

新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "napcat",
"private": true,
"type": "module",
"version": "1.5.7",
"version": "1.5.8",
"scripts": {
"watch:dev": "vite --mode development",
"watch:prod": "vite --mode production",
Expand Down
26 changes: 24 additions & 2 deletions src/common/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs/promises';
import { log, logDebug } from './log';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

import * as fsPromise from 'node:fs/promises';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -261,4 +261,26 @@ export function isEqual(obj1: any, obj2: any) {
if (!isEqual(obj1[key], obj2[key])) return false;
}
return true;
}
}

export async function deleteOldFiles(directoryPath: string, daysThreshold: number) {
try {
const files = await fsPromise.readdir(directoryPath);

for (const file of files) {
const filePath = path.join(directoryPath, file);
const stats = await fsPromise.stat(filePath);
const lastModifiedTime = stats.mtimeMs;
const currentTime = Date.now();
const timeDifference = currentTime - lastModifiedTime;
const daysDifference = timeDifference / (1000 * 60 * 60 * 24);

if (daysDifference > daysThreshold) {
await fsPromise.unlink(filePath); // Delete the file
//console.log(`Deleted: ${filePath}`);
}
}
} catch (error) {
//console.error('Error deleting files:', error);
}
}
2 changes: 1 addition & 1 deletion src/common/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const logConfig: Configuration = {
FileAppender: { // 输出到文件的appender
type: 'file',
filename: logPath, // 指定日志文件的位置和文件名
maxLoogSize: 10485760, // 日志文件的最大大小(单位:字节),这里设置为10MB
maxLogSize: 10485760, // 日志文件的最大大小(单位:字节),这里设置为10MB
layout: {
type: 'pattern',
pattern: '%d{yyyy-MM-dd hh:mm:ss} [%p] %X{userInfo} | %m'
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { log, logDebug, logError, LogLevel, logWarn, setLogLevel } from '@/commo
import { NapCatOnebot11 } from '@/onebot11/main';
import { InitWebUi } from './webui/index';
import { WebUiDataRuntime } from './webui/src/helper/Data';
import { UpdateConfig } from './common/utils/helper';
import { deleteOldFiles, UpdateConfig } from './common/utils/helper';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
Expand All @@ -22,6 +22,7 @@ program
.option('-q, --qq <type>', 'QQ号')
.parse(process.argv);

//deleteOldFiles(path.join(__dirname, 'logs'), 3).then().catch();
// UpdateConfig().catch(logError); 移除支持
// 启动WebUi
InitWebUi();
Expand All @@ -40,10 +41,10 @@ checkVersion().then(async (remoteVersion: string) => {
break;
}
}
logDebug(tagColor('[NapCat]'),'当前已是最新版本');
logDebug(tagColor('[NapCat]'), '当前已是最新版本');
return;
}).catch((e) => {
logError(tagColor('[NapCat]'),'检测更新失败', e);
logError(tagColor('[NapCat]'), '检测更新失败', e);
});
// 不是很好待优化
const NapCat_OneBot11 = new NapCatOnebot11();
Expand Down
6 changes: 4 additions & 2 deletions src/onebot11/action/msg/SendMsg/create-send-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ const _handlers: {
const uri2LocalRes = await uri2local(thumb);
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
}

return SendMsgElementConstructor.video(path, fileName, thumb);
let videoEle = await SendMsgElementConstructor.video(path, fileName, thumb);
//未测试
context.deleteAfterSentFiles.push(videoEle.videoElement.filePath);
return videoEle;
},
[OB11MessageDataType.miniapp]: async ({ data: any }) => SendMsgElementConstructor.miniapp(),

Expand Down
2 changes: 1 addition & 1 deletion src/onebot11/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '1.5.7';
export const version = '1.5.8';
2 changes: 1 addition & 1 deletion src/webui/ui/NapCat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function onSettingWindowCreated(view: Element) {
SettingItem(
'<span id="napcat-update-title">Napcat</span>',
undefined,
SettingButton('V1.5.7', 'napcat-update-button', 'secondary')
SettingButton('V1.5.8', 'napcat-update-button', 'secondary')
),
]),
SettingList([
Expand Down
2 changes: 1 addition & 1 deletion static/assets/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async function onSettingWindowCreated(view) {
SettingItem(
'<span id="napcat-update-title">Napcat</span>',
void 0,
SettingButton("V1.5.7", "napcat-update-button", "secondary")
SettingButton("V1.5.8", "napcat-update-button", "secondary")
)
]),
SettingList([
Expand Down

0 comments on commit a219c9c

Please sign in to comment.