Skip to content

Commit

Permalink
Merge branch 'main' into enchant
Browse files Browse the repository at this point in the history
  • Loading branch information
h5mcbox committed Jun 21, 2024
2 parents 3cbcbc4 + 4d22f15 commit 5ec8e44
Show file tree
Hide file tree
Showing 35 changed files with 232 additions and 219 deletions.
11 changes: 4 additions & 7 deletions docs/changelogs/CHANGELOG.v1.5.8.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# v1.5.8
# v1.5.9

QQ Version: Windows 9.9.11-24568 / Linux 3.2.9-24568
QQ Version: Windows 9.9.11-24815 / Linux 3.2.9-24815

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

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


新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)
14 changes: 14 additions & 0 deletions docs/changelogs/old/CHANGELOG.v1.5.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# v1.5.8

QQ Version: Windows 9.9.11-24568 / Linux 3.2.9-24568

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

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

新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)
4 changes: 2 additions & 2 deletions 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.8",
"version": "1.5.9",
"scripts": {
"watch:dev": "vite --mode development",
"watch:prod": "vite --mode production",
Expand Down Expand Up @@ -33,7 +33,7 @@
"@types/fluent-ffmpeg": "^2.1.24",
"@types/node": "^20.11.30",
"@types/qrcode-terminal": "^0.12.2",
"@types/uuid": "^9.0.8",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
Expand Down
80 changes: 40 additions & 40 deletions src/common/utils/MessageUnique.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import crypto from 'crypto';

class LimitedHashTable<K, V> {
private keyToValue: Map<K, V> = new Map();
private valueToKey: Map<V, K> = new Map();
private maxSize: number;
private KeyQueneList: K[] = [];
private ValueQueneList: V[] = [];
constructor(maxSize: number) {
this.maxSize = maxSize;
}
set(key: K, value: V): void {
this.keyToValue.set(key, value);
this.valueToKey.set(value, key);
if (this.KeyQueneList.length >= this.maxSize || this.ValueQueneList.length >= this.maxSize) {
this.KeyQueneList.shift();
this.ValueQueneList.shift();
}
}
private keyToValue: Map<K, V> = new Map();
private valueToKey: Map<V, K> = new Map();
private maxSize: number;
private KeyQueneList: K[] = [];
private ValueQueneList: V[] = [];
constructor(maxSize: number) {
this.maxSize = maxSize;
}
set(key: K, value: V): void {
this.keyToValue.set(key, value);
this.valueToKey.set(value, key);
if (this.KeyQueneList.length >= this.maxSize || this.ValueQueneList.length >= this.maxSize) {
this.KeyQueneList.shift();
this.ValueQueneList.shift();
}
}

getValue(key: K): V | undefined {
return this.keyToValue.get(key);
}
getValue(key: K): V | undefined {
return this.keyToValue.get(key);
}

getKey(value: V): K | undefined {
return this.valueToKey.get(value);
}
getKey(value: V): K | undefined {
return this.valueToKey.get(value);
}

delete(key: K): void {
const value = this.keyToValue.get(key);
if (value !== undefined) {
this.keyToValue.delete(key);
this.valueToKey.delete(value);
}
delete(key: K): void {
const value = this.keyToValue.get(key);
if (value !== undefined) {
this.keyToValue.delete(key);
this.valueToKey.delete(value);
}
}
}

class MessageUniqueWrapper {
private msgIdMap: LimitedHashTable<number, string> = new LimitedHashTable(1000);
createMsg(MsgId: string) {
let ShortId = parseInt(crypto.createHash('sha1').update('2345').digest('hex').slice(0, 8), 16);
this.msgIdMap.set(ShortId, MsgId);
return ShortId;
}
getMsgIdByShortId(ShortId: number) {
return this.msgIdMap.getValue(ShortId);
}
getShortIdByMsgId(MsgId: string) {
return this.msgIdMap.getKey(MsgId);
}
private msgIdMap: LimitedHashTable<number, string> = new LimitedHashTable(1000);
createMsg(MsgId: string) {
const ShortId = parseInt(crypto.createHash('sha1').update('2345').digest('hex').slice(0, 8), 16);
this.msgIdMap.set(ShortId, MsgId);
return ShortId;
}
getMsgIdByShortId(ShortId: number) {
return this.msgIdMap.getValue(ShortId);
}
getShortIdByMsgId(MsgId: string) {
return this.msgIdMap.getKey(MsgId);
}
}

export const MessageUnique = new MessageUniqueWrapper();
10 changes: 5 additions & 5 deletions src/common/utils/Packet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 方案一 MiniApp发包方案
// 前置条件: 处于GUI环境 存在MiniApp

import { NTQQSystemApi } from "@/core";
import { NTQQSystemApi } from '@/core';

// 前排提示: 开发验证仅Win平台开展
export class MiniAppUtil {
static async RunMiniAppWithGUI() {
//process.env.ELECTRON_RUN_AS_NODE = undefined;//没用还是得自己用cpp之类的语言写个程序转发参数
return NTQQSystemApi.BootMiniApp(process.execPath, "miniapp://open/1007?url=https%3A%2F%2Fm.q.qq.com%2Fa%2Fs%2Fedd0a83d3b8afe233dfa07adaaf8033f%3Fscene%3D1007%26min_refer%3D10001");
}
static async RunMiniAppWithGUI() {
//process.env.ELECTRON_RUN_AS_NODE = undefined;//没用还是得自己用cpp之类的语言写个程序转发参数
return NTQQSystemApi.BootMiniApp(process.execPath, 'miniapp://open/1007?url=https%3A%2F%2Fm.q.qq.com%2Fa%2Fs%2Fedd0a83d3b8afe233dfa07adaaf8033f%3Fscene%3D1007%26min_refer%3D10001');
}
}
// 方案二 MiniApp发包方案 替代MiniApp方案
// 前置条件: 无
Expand Down
3 changes: 2 additions & 1 deletion src/common/utils/QQBasicInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const qqPkgInfo: QQPkgInfo = JSON.parse(fs.readFileSync(pkgInfoPath).toSt
// appid: '537213764',
// platVer: '10.0.26100',
// clientVer: '9.9.9-23159',

//Android
//V1_AND_SQ_9.0.60_6478_YYB_D
// Linux
// app_version: '3.2.9-24568',
// qua: 'V1_LNX_NQ_3.2.9_24568_GW_B',
Expand Down
32 changes: 16 additions & 16 deletions src/common/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,23 @@ export function isEqual(obj1: any, obj2: any) {
}

export async function deleteOldFiles(directoryPath: string, daysThreshold: number) {
try {
const files = await fsPromise.readdir(directoryPath);
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);
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);
if (daysDifference > daysThreshold) {
await fsPromise.unlink(filePath); // Delete the file
//console.log(`Deleted: ${filePath}`);
}
}
} catch (error) {
//console.error('Error deleting files:', error);
}
}
4 changes: 2 additions & 2 deletions src/common/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class RequestUtil {
const formDataParts = [
`------${boundary}\r\n`,
`Content-Disposition: form-data; name="share_image"; filename="${filePath}"\r\n`,
`Content-Type: ` + type + `\r\n\r\n`
'Content-Type: ' + type + '\r\n\r\n'
];

const fileContent = readFileSync(filePath);
Expand Down Expand Up @@ -161,7 +161,7 @@ export class RequestUtil {
try {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
const responseJson = JSON.parse(responseBody) as retType;
resolve(responseJson.result?.url!);
resolve(responseJson.result!.url!);
} else {
reject(new Error(`Unexpected status code: ${res.statusCode}`));
}
Expand Down
2 changes: 1 addition & 1 deletion src/core
Submodule core updated from cd5ac2 to 35be10
22 changes: 11 additions & 11 deletions src/onebot11/action/extends/CreateCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { selfInfo } from '@/core/data';

const SchemaData = {
type: 'object',
properties: {
rawData: { type: 'string' },
brief: { type: 'string' }
},
required: ['brief', 'rawData'],
type: 'object',
properties: {
rawData: { type: 'string' },
brief: { type: 'string' }
},
required: ['brief', 'rawData'],
} as const satisfies JSONSchema;

type Payload = FromSchema<typeof SchemaData>;

export class CreateCollection extends BaseAction<Payload, any> {
actionName = ActionName.CreateCollection;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
return await NTQQCollectionApi.createCollection(selfInfo.uin, selfInfo.uid, selfInfo.nick, payload.brief, payload.rawData);
}
actionName = ActionName.CreateCollection;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
return await NTQQCollectionApi.createCollection(selfInfo.uin, selfInfo.uid, selfInfo.nick, payload.brief, payload.rawData);
}
}
22 changes: 11 additions & 11 deletions src/onebot11/action/extends/GetCollectionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { selfInfo } from '@/core/data';

const SchemaData = {
type: 'object',
properties: {
category: { type: 'number' },
count: { type: 'number' }
},
required: ['category', 'count'],
type: 'object',
properties: {
category: { type: 'number' },
count: { type: 'number' }
},
required: ['category', 'count'],
} as const satisfies JSONSchema;

type Payload = FromSchema<typeof SchemaData>;

export class GetCollectionList extends BaseAction<Payload, any> {
actionName = ActionName.GetCollectionList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
}
actionName = ActionName.GetCollectionList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
}
}
18 changes: 14 additions & 4 deletions src/onebot11/action/extends/GetFriendWithCategory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { rawFriends } from '@/core/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { BuddyCategoryType } from '@/core/entities/';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { NTQQFriendApi } from '@/core';

export class GetFriendWithCategory extends BaseAction<void, Array<BuddyCategoryType>> {
const SchemaData = {
type: 'object',
properties: {
no_cache: { type: ['boolean', 'string'] },
}
} as const satisfies JSONSchema;

type Payload = FromSchema<typeof SchemaData>;

export class GetFriendWithCategory extends BaseAction<Payload, BuddyCategoryType[]> {
actionName = ActionName.GetFriendsWithCategory;

protected async _handle(payload: void) {
return rawFriends;
protected async _handle(payload: Payload) {
return await NTQQFriendApi.getFriendsRaw(payload?.no_cache?.toString() === 'true');
}
}
22 changes: 11 additions & 11 deletions src/onebot11/action/extends/SetLongNick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { NTQQUserApi } from '@/core/apis';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';

const SchemaData = {
type: 'object',
properties: {
longNick: { type: 'string' },
},
required: [ 'longNick'],
type: 'object',
properties: {
longNick: { type: 'string' },
},
required: [ 'longNick'],
} as const satisfies JSONSchema;

type Payload = FromSchema<typeof SchemaData>;

export class SetLongNick extends BaseAction<Payload, any> {
actionName = ActionName.SetLongNick;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
let ret = await NTQQUserApi.setLongNick(payload.longNick)
return ret;
}
actionName = ActionName.SetLongNick;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const ret = await NTQQUserApi.setLongNick(payload.longNick);
return ret;
}
}
Loading

0 comments on commit 5ec8e44

Please sign in to comment.