mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
75f67caa1b | ||
![]() |
d760ce54b7 | ||
![]() |
956976ebd5 | ||
![]() |
f9c2d4ca6c | ||
![]() |
dd5cc3c38c | ||
![]() |
daed4cc13e | ||
![]() |
6ff614dd18 | ||
![]() |
eb70ac4266 | ||
![]() |
a3a431adb7 | ||
![]() |
e12c72ab98 | ||
![]() |
9f8549b831 | ||
![]() |
b2de256f87 | ||
![]() |
7f32a5cf9e | ||
![]() |
56f8314d29 |
17
.github/workflows/release.yml
vendored
17
.github/workflows/release.yml
vendored
@@ -98,11 +98,16 @@ jobs:
|
|||||||
|
|
||||||
- name: Compress subdirectories
|
- name: Compress subdirectories
|
||||||
run: |
|
run: |
|
||||||
for dir in */; do
|
cd ./NapCat.Shell/
|
||||||
base=$(basename "$dir")
|
zip -q -r NapCat.Shell.zip *
|
||||||
zip -r "${base}.zip" "$dir"
|
cd ..
|
||||||
done
|
cd ./NapCat.Framework/
|
||||||
|
zip -q -r NapCat.Framework.zip *
|
||||||
|
cd ..
|
||||||
|
rm ./NapCat.Shell.zip -rf
|
||||||
|
rm ./NapCat.Framework.zip -rf
|
||||||
|
mv ./NapCat.Shell/NapCat.Shell.zip ./
|
||||||
|
mv ./NapCat.Framework/NapCat.Framework.zip ./
|
||||||
- name: Extract version from tag
|
- name: Extract version from tag
|
||||||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
|
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
|
||||||
|
|
||||||
@@ -118,6 +123,4 @@ jobs:
|
|||||||
files: |
|
files: |
|
||||||
NapCat.Framework.zip
|
NapCat.Framework.zip
|
||||||
NapCat.Shell.zip
|
NapCat.Shell.zip
|
||||||
# NapCat.darwin.x64.zip
|
|
||||||
# NapCat.darwin.arm64.zip
|
|
||||||
draft: true
|
draft: true
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "2.0.21",
|
"version": "2.0.23",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.0.21",
|
"version": "2.0.23",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:framework": "vite build --mode framework",
|
"build:framework": "vite build --mode framework",
|
||||||
"build:shell": "vite build --mode shell",
|
"build:shell": "vite build --mode shell",
|
||||||
|
@@ -2,7 +2,7 @@ import path, { dirname } from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export const napcat_version = '2.0.21';
|
export const napcat_version = '2.0.23';
|
||||||
|
|
||||||
export class NapCatPathWrapper {
|
export class NapCatPathWrapper {
|
||||||
binaryPath: string;
|
binaryPath: string;
|
||||||
|
@@ -165,118 +165,98 @@ type Uri2LocalRes = {
|
|||||||
path: string,
|
path: string,
|
||||||
isLocal: boolean
|
isLocal: boolean
|
||||||
}
|
}
|
||||||
|
export async function checkFileV2(filePath: string) {
|
||||||
export async function uri2local(TempDir: string, UriOrPath: string, fileName: string | null = null): Promise<Uri2LocalRes> {
|
|
||||||
const res = {
|
|
||||||
success: false,
|
|
||||||
errMsg: '',
|
|
||||||
fileName: '',
|
|
||||||
ext: '',
|
|
||||||
path: '',
|
|
||||||
isLocal: false,
|
|
||||||
};
|
|
||||||
if (!fileName) fileName = randomUUID();
|
|
||||||
let filePath = path.join(TempDir, fileName);//临时目录
|
|
||||||
let url = null;
|
|
||||||
//区分path和uri
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(UriOrPath)) url = new URL('file://' + UriOrPath);
|
const ext: string | undefined = (await fileType.fileTypeFromFile(filePath))?.ext;
|
||||||
} catch (error: any) {
|
if (ext) {
|
||||||
|
fs.renameSync(filePath, filePath + `.${ext}`);
|
||||||
|
filePath += `.${ext}`;
|
||||||
|
return { success: true, ext: ext, path: filePath };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// log("获取文件类型失败", filePath,e.stack)
|
||||||
|
}
|
||||||
|
return { success: false, ext: '', path: filePath };
|
||||||
|
}
|
||||||
|
export enum FileUriType {
|
||||||
|
Unknown = 0,
|
||||||
|
Local = 1,
|
||||||
|
Remote = 2,
|
||||||
|
Base64 = 3
|
||||||
|
}
|
||||||
|
export async function checkUriType(Uri: string) {
|
||||||
|
//先判断是否是本地文件
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(Uri)) return { Uri: Uri, Type: FileUriType.Local };
|
||||||
|
} catch (error) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
url = new URL(UriOrPath);
|
//再判断是否是Http
|
||||||
} catch (error: any) {
|
if (Uri.startsWith('http://') || Uri.startsWith('https://')) {
|
||||||
}
|
return { Uri: Uri, Type: FileUriType.Remote };
|
||||||
|
|
||||||
//验证url
|
|
||||||
if (!url) {
|
|
||||||
res.errMsg = `UriOrPath ${UriOrPath} 解析失败,可能${UriOrPath}不存在`;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url.protocol == 'base64:') {
|
|
||||||
// base64转成文件
|
|
||||||
const base64Data = UriOrPath.split('base64://')[1];
|
|
||||||
try {
|
|
||||||
const buffer = Buffer.from(base64Data, 'base64');
|
|
||||||
fs.writeFileSync(filePath, buffer);
|
|
||||||
} catch (e: any) {
|
|
||||||
res.errMsg = 'base64文件下载失败,' + e.toString();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
} else if (url.protocol == 'http:' || url.protocol == 'https:') {
|
//再判断是否是Base64
|
||||||
// 下载文件
|
if (Uri.startsWith('base64://')) {
|
||||||
let buffer: Buffer | null = null;
|
return { Uri: Uri, Type: FileUriType.Base64 };
|
||||||
try {
|
|
||||||
buffer = await httpDownload(UriOrPath);
|
|
||||||
} catch (e: any) {
|
|
||||||
res.errMsg = `${url}下载失败,` + e.toString();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
try {
|
if (Uri.startsWith('file://')) {
|
||||||
const pathInfo = path.parse(decodeURIComponent(url.pathname));
|
let pathname: string;
|
||||||
if (pathInfo.name) {
|
let filePath: string;
|
||||||
fileName = pathInfo.name;
|
|
||||||
if (pathInfo.ext) {
|
|
||||||
fileName += pathInfo.ext;
|
|
||||||
// res.ext = pathInfo.ext
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fileName = fileName.replace(/[/\\:*?"<>|]/g, '_');
|
|
||||||
res.fileName = fileName;
|
|
||||||
filePath = path.join(TempDir, randomUUID() + fileName);
|
|
||||||
fs.writeFileSync(filePath, buffer);
|
|
||||||
} catch (e: any) {
|
|
||||||
res.errMsg = `${url}下载失败,` + e.toString();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let pathname: string;
|
|
||||||
if (url.protocol === 'file:') {
|
|
||||||
// await fs.copyFile(url.pathname, filePath);
|
// await fs.copyFile(url.pathname, filePath);
|
||||||
pathname = decodeURIComponent(url.pathname);
|
pathname = decodeURIComponent(new URL(Uri).pathname);
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
filePath = pathname.slice(1);
|
filePath = pathname.slice(1);
|
||||||
} else {
|
} else {
|
||||||
filePath = pathname;
|
filePath = pathname;
|
||||||
}
|
}
|
||||||
} else {
|
return { Uri: filePath, Type: FileUriType.Local };
|
||||||
// 26702执行forword file文件操作 不应该在这里乱来
|
|
||||||
// const cache = await dbUtil.getFileCacheByName(uri);
|
|
||||||
// if (cache) {
|
|
||||||
// filePath = cache.path;
|
|
||||||
// } else {
|
|
||||||
// filePath = uri;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
res.isLocal = true;
|
} catch (error) {
|
||||||
}
|
}
|
||||||
// else{
|
return { Uri: Uri, Type: FileUriType.Unknown };
|
||||||
// res.errMsg = `不支持的file协议,` + url.protocol
|
|
||||||
// return res
|
|
||||||
// }
|
|
||||||
// if (isGIF(filePath) && !res.isLocal) {
|
|
||||||
// await fs.rename(filePath, filePath + ".gif");
|
|
||||||
// filePath += ".gif";
|
|
||||||
// }
|
|
||||||
if (!res.isLocal && !res.ext) {
|
|
||||||
try {
|
|
||||||
const ext: string | undefined = (await fileType.fileTypeFromFile(filePath))?.ext;
|
|
||||||
if (ext) {
|
|
||||||
fs.renameSync(filePath, filePath + `.${ext}`);
|
|
||||||
filePath += `.${ext}`;
|
|
||||||
res.fileName += `.${ext}`;
|
|
||||||
res.ext = ext;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// log("获取文件类型失败", filePath,e.stack)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res.success = true;
|
|
||||||
res.path = filePath;
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
export async function uri2local(dir: string, uri: string, filename: string | undefined = undefined): Promise<Uri2LocalRes> {
|
||||||
|
let { Uri: HandledUri, Type: UriType } = await checkUriType(uri);
|
||||||
|
//解析失败
|
||||||
|
|
||||||
|
if (UriType == FileUriType.Unknown) {
|
||||||
|
return { success: false, errMsg: '未知文件类型', fileName: '', ext: '', path: '', isLocal: false };
|
||||||
|
}
|
||||||
|
//解析File协议和本地文件
|
||||||
|
if (UriType == FileUriType.Local) {
|
||||||
|
const fileExt = path.extname(HandledUri);
|
||||||
|
const filename = path.basename(HandledUri, fileExt);
|
||||||
|
return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: HandledUri, isLocal: true };
|
||||||
|
}
|
||||||
|
//接下来都要有文件名
|
||||||
|
if (!filename) filename = randomUUID();
|
||||||
|
//解析Http和Https协议
|
||||||
|
if (UriType == FileUriType.Remote) {
|
||||||
|
const fileExt = path.extname(HandledUri);
|
||||||
|
|
||||||
|
const fileName = filename + fileExt;
|
||||||
|
const filePath = path.join(dir, fileName);
|
||||||
|
const buffer = await httpDownload(HandledUri);
|
||||||
|
fs.writeFileSync(filePath, buffer);
|
||||||
|
return { success: true, errMsg: '', fileName: fileName, ext: fileExt, path: filePath, isLocal: true };
|
||||||
|
}
|
||||||
|
//解析Base64
|
||||||
|
if (UriType == FileUriType.Base64) {
|
||||||
|
const base64 = HandledUri.replace(/^base64:\/\//, '');
|
||||||
|
const buffer = Buffer.from(base64, 'base64');
|
||||||
|
let filePath = path.join(dir, filename);
|
||||||
|
let fileExt = '';
|
||||||
|
fs.writeFileSync(filePath, buffer);
|
||||||
|
const { success, ext, path: fileTypePath } = await checkFileV2(filePath);
|
||||||
|
if (success) {
|
||||||
|
filePath = fileTypePath;
|
||||||
|
fileExt = ext;
|
||||||
|
filename = path.basename(filePath, fileExt);
|
||||||
|
}
|
||||||
|
return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath, isLocal: true };
|
||||||
|
}
|
||||||
|
return { success: false, errMsg: '未知文件类型', fileName: '', ext: '', path: '', isLocal: false };
|
||||||
|
}
|
||||||
export async function copyFolder(sourcePath: string, destPath: string, logger: LogWrapper) {
|
export async function copyFolder(sourcePath: string, destPath: string, logger: LogWrapper) {
|
||||||
try {
|
try {
|
||||||
const entries = await fsPromise.readdir(sourcePath, { withFileTypes: true });
|
const entries = await fsPromise.readdir(sourcePath, { withFileTypes: true });
|
||||||
|
@@ -127,25 +127,7 @@ export class NTQQUserApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getUserDetailInfo(uid: string) {
|
async getUserDetailInfo(uid: string) {
|
||||||
if (this.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
return this.fetchUserDetailInfo(uid);
|
||||||
return this.fetchUserDetailInfo(uid);
|
|
||||||
}
|
|
||||||
return this.getUserDetailInfoOld(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUserDetailInfoOld(uid: string) {
|
|
||||||
type EventService = NodeIKernelProfileService['getUserDetailInfoWithBizInfo'];
|
|
||||||
type EventListener = NodeIKernelProfileListener['onProfileDetailInfoChanged'];
|
|
||||||
const [_retData, profile] = await this.core.eventWrapper.CallNormalEvent<EventService, EventListener>(
|
|
||||||
'NodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
|
||||||
'NodeIKernelProfileListener/onProfileDetailInfoChanged',
|
|
||||||
2,
|
|
||||||
5000,
|
|
||||||
(profile) => profile.uid === uid,
|
|
||||||
uid,
|
|
||||||
[0],
|
|
||||||
);
|
|
||||||
return profile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async modifySelfProfile(param: ModifyProfileParams) {
|
async modifySelfProfile(param: ModifyProfileParams) {
|
||||||
|
@@ -56,7 +56,7 @@ const _handlers: {
|
|||||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||||
|
|
||||||
// then the qq is a group member
|
// then the qq is a group member
|
||||||
// Mlikiowa V2.0.21 Refactor Todo
|
// Mlikiowa V2.0.23 Refactor Todo
|
||||||
const uid = await coreContext.apis.UserApi.getUidByUinV2(`${atQQ}`);
|
const uid = await coreContext.apis.UserApi.getUidByUinV2(`${atQQ}`);
|
||||||
if (!uid) throw new Error('Get Uid Error');
|
if (!uid) throw new Error('Get Uid Error');
|
||||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
||||||
@@ -161,7 +161,7 @@ const _handlers: {
|
|||||||
} else {
|
} else {
|
||||||
postData = data;
|
postData = data;
|
||||||
}
|
}
|
||||||
// Mlikiowa V2.0.21 Refactor Todo
|
// Mlikiowa V2.0.23 Refactor Todo
|
||||||
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
||||||
if (!signUrl) {
|
if (!signUrl) {
|
||||||
if (data.type === 'qq') {
|
if (data.type === 'qq') {
|
||||||
|
@@ -417,7 +417,7 @@ export class OB11Constructor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//log("group msg", msg);
|
//log("group msg", msg);
|
||||||
// Mlikiowa V2.0.21 Refactor Todo
|
// Mlikiowa V2.0.23 Refactor Todo
|
||||||
// if (msg.senderUin && msg.senderUin !== '0') {
|
// if (msg.senderUin && msg.senderUin !== '0') {
|
||||||
// const member = await getGroupMember(msg.peerUid, msg.senderUin);
|
// const member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||||
// if (member && member.cardName !== msg.sendMemberName) {
|
// if (member && member.cardName !== msg.sendMemberName) {
|
||||||
|
@@ -4,6 +4,7 @@ import http from 'http';
|
|||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { OB11Response } from '../action/OB11Response';
|
import { OB11Response } from '../action/OB11Response';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
|
import cors from 'cors';
|
||||||
|
|
||||||
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
private app: Express | undefined;
|
private app: Express | undefined;
|
||||||
@@ -43,21 +44,11 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
this.server?.close();
|
this.server?.close();
|
||||||
this.app = undefined;
|
this.app = undefined;
|
||||||
}
|
}
|
||||||
cors(): any {
|
|
||||||
return (req: Request, res: Response, next: any) => {
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
private initializeServer() {
|
private initializeServer() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
this.server = http.createServer(this.app);
|
this.server = http.createServer(this.app);
|
||||||
|
|
||||||
this.app.use(this.cors());
|
this.app.use(cors());
|
||||||
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
|
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
|
||||||
this.app.use((req, res, next) => {
|
this.app.use((req, res, next) => {
|
||||||
// 兼容处理没有带content-type的请求
|
// 兼容处理没有带content-type的请求
|
||||||
@@ -70,7 +61,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.use((req, res, next) => this.authorize(this.token, req, res, next));
|
this.app.use((req, res, next) => this.authorize(this.token, req, res, next));
|
||||||
this.app.use((req, res) => this.handleRequest(req, res));
|
this.app.use((req, res) => this.handleRequest(req, res));
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
undefined,
|
undefined,
|
||||||
SettingButton('V2.0.21', 'napcat-update-button', 'secondary'),
|
SettingButton('V2.0.23', 'napcat-update-button', 'secondary'),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
void 0,
|
void 0,
|
||||||
SettingButton("V2.0.21", "napcat-update-button", "secondary")
|
SettingButton("V2.0.23", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
Reference in New Issue
Block a user