style(repo): clear workspace lint violations
Align existing managed source with the repository lint rules so the workspace can adopt one reliable root validation command. This normalizes the private file upload block, removes stale test suppressions, makes an error boundary explicit, and records a stable settings dependency without changing user-facing behavior. The cleanup creates a deterministic baseline before lint becomes a required pull request gate.
This commit is contained in:
4 files changed
+122
-121
No files matched your search
@@ -396,51 +396,51 @@ export class GroupFileApi {
|
|||||||
// md510MCheckSum in the same single pass.
|
// md510MCheckSum in the same single pass.
|
||||||
const staged = await stageSourceToDisk(source, FILE_UPLOAD_MAX_BYTES);
|
const staged = await stageSourceToDisk(source, FILE_UPLOAD_MAX_BYTES);
|
||||||
try {
|
try {
|
||||||
if (staged.fileSize === 0) throw new Error('private file is empty');
|
if (staged.fileSize === 0) throw new Error('private file is empty');
|
||||||
|
|
||||||
const targetUid = await this.ctx.resolveUserUid(userId);
|
const targetUid = await this.ctx.resolveUserUid(userId);
|
||||||
const selfUid = await resolveSelfUid(this.ctx);
|
const selfUid = await resolveSelfUid(this.ctx);
|
||||||
|
|
||||||
const senderUin = toInt(this.ctx.identity.uin);
|
const senderUin = toInt(this.ctx.identity.uin);
|
||||||
if (senderUin <= 0) throw new Error('invalid self uin for private file upload');
|
if (senderUin <= 0) throw new Error('invalid self uin for private file upload');
|
||||||
|
|
||||||
const fileName = normalizeUploadFileName(name, staged.fileName);
|
const fileName = normalizeUploadFileName(name, staged.fileName);
|
||||||
const guardStat = await fsp.stat(staged.filePath); // mutation-guard baseline
|
const guardStat = await fsp.stat(staged.filePath); // mutation-guard baseline
|
||||||
const hashes = await hashFileStreaming(staged.filePath, { headLimit: MD5_HEAD_LIMIT });
|
const hashes = await hashFileStreaming(staged.filePath, { headLimit: MD5_HEAD_LIMIT });
|
||||||
|
|
||||||
const upload = await UploadPrivateFileRequest.invoke(this.ctx, {
|
const upload = await UploadPrivateFileRequest.invoke(this.ctx, {
|
||||||
senderUid: selfUid,
|
senderUid: selfUid,
|
||||||
receiverUid: targetUid,
|
receiverUid: targetUid,
|
||||||
fileName,
|
fileName,
|
||||||
fileSize: staged.fileSize,
|
fileSize: staged.fileSize,
|
||||||
fileSha1: hashes.sha1,
|
fileSha1: hashes.sha1,
|
||||||
fileMd5: hashes.md5,
|
fileMd5: hashes.md5,
|
||||||
md510MCheckSum: hashes.headMd5!,
|
md510MCheckSum: hashes.headMd5!,
|
||||||
});
|
});
|
||||||
ensureRetCodeZero('private file upload', upload.retCode, upload.retMsg, undefined);
|
ensureRetCodeZero('private file upload', upload.retCode, upload.retMsg, undefined);
|
||||||
|
|
||||||
const fileId = typeof upload.uuid === 'string' && upload.uuid ? upload.uuid : null;
|
const fileId = typeof upload.uuid === 'string' && upload.uuid ? upload.uuid : null;
|
||||||
const fileHash = typeof upload.fileAddon === 'string' && upload.fileAddon ? upload.fileAddon : null;
|
const fileHash = typeof upload.fileAddon === 'string' && upload.fileAddon ? upload.fileAddon : null;
|
||||||
if (!fileId) throw new Error('private file upload response missing file_id');
|
if (!fileId) throw new Error('private file upload response missing file_id');
|
||||||
|
|
||||||
// Cache the metadata so a later `send_private_msg` carrying just
|
// Cache the metadata so a later `send_private_msg` carrying just
|
||||||
// `{type:'file', file_id}` can resurrect the full c2c-file packet
|
// `{type:'file', file_id}` can resurrect the full c2c-file packet
|
||||||
// (NotOnlineFile { fileSize, fileMd5, fileName, fileHash }). Without
|
// (NotOnlineFile { fileSize, fileMd5, fileName, fileHash }). Without
|
||||||
// this the recipient sees a 0-byte file because the OneBot send path
|
// this the recipient sees a 0-byte file because the OneBot send path
|
||||||
// has no way to recover those fields from the file_id alone.
|
// has no way to recover those fields from the file_id alone.
|
||||||
this.ctx.rememberUploadedFile({
|
this.ctx.rememberUploadedFile({
|
||||||
fileId,
|
fileId,
|
||||||
scope: 'private',
|
scope: 'private',
|
||||||
userId,
|
userId,
|
||||||
fileName,
|
fileName,
|
||||||
fileSize: staged.fileSize,
|
fileSize: staged.fileSize,
|
||||||
fileMd5: hashes.md5,
|
fileMd5: hashes.md5,
|
||||||
fileSha1: hashes.sha1,
|
fileSha1: hashes.sha1,
|
||||||
fileHash: fileHash ?? '',
|
fileHash: fileHash ?? '',
|
||||||
rememberedAt: Date.now(),
|
rememberedAt: Date.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!upload.boolFileExist && uploadFile) {
|
if (!upload.boolFileExist && uploadFile) {
|
||||||
// Host selection.
|
// Host selection.
|
||||||
//
|
//
|
||||||
// Current QQ-NT server rollout has stopped populating the legacy
|
// Current QQ-NT server rollout has stopped populating the legacy
|
||||||
@@ -462,93 +462,93 @@ export class GroupFileApi {
|
|||||||
// uploadDns), so we fall through to those after rtpMediaPlatform.
|
// uploadDns), so we fall through to those after rtpMediaPlatform.
|
||||||
// Pair an HTTPS-flavored host with `uploadHttpsPort` if that's
|
// Pair an HTTPS-flavored host with `uploadHttpsPort` if that's
|
||||||
// what we picked.
|
// what we picked.
|
||||||
const rtpFirst = (Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
const rtpFirst = (Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
||||||
&& upload.rtpMediaPlatformUploadAddress[0])
|
&& upload.rtpMediaPlatformUploadAddress[0])
|
||||||
? upload.rtpMediaPlatformUploadAddress[0] : null;
|
? upload.rtpMediaPlatformUploadAddress[0] : null;
|
||||||
const rtpInIP = rtpFirst && typeof rtpFirst.inIP === 'number' && rtpFirst.inIP !== 0
|
const rtpInIP = rtpFirst && typeof rtpFirst.inIP === 'number' && rtpFirst.inIP !== 0
|
||||||
? int32ToIpv4Dotted(rtpFirst.inIP) : '';
|
? int32ToIpv4Dotted(rtpFirst.inIP) : '';
|
||||||
const rtpInPort = rtpFirst && typeof rtpFirst.inPort === 'number'
|
const rtpInPort = rtpFirst && typeof rtpFirst.inPort === 'number'
|
||||||
? rtpFirst.inPort : 0;
|
? rtpFirst.inPort : 0;
|
||||||
const ipListFirst = (Array.isArray(upload.uploadIpList) && upload.uploadIpList[0])
|
const ipListFirst = (Array.isArray(upload.uploadIpList) && upload.uploadIpList[0])
|
||||||
? upload.uploadIpList[0] : '';
|
? upload.uploadIpList[0] : '';
|
||||||
const uploadHost = (rtpInIP)
|
const uploadHost = (rtpInIP)
|
||||||
|| (typeof upload.uploadIp === 'string' && upload.uploadIp)
|
|| (typeof upload.uploadIp === 'string' && upload.uploadIp)
|
||||||
|| (typeof upload.uploadDomain === 'string' && upload.uploadDomain)
|
|| (typeof upload.uploadDomain === 'string' && upload.uploadDomain)
|
||||||
|| (ipListFirst)
|
|| (ipListFirst)
|
||||||
|| (typeof upload.uploadHttpsDomain === 'string' && upload.uploadHttpsDomain)
|
|| (typeof upload.uploadHttpsDomain === 'string' && upload.uploadHttpsDomain)
|
||||||
|| (typeof upload.uploadDns === 'string' && upload.uploadDns)
|
|| (typeof upload.uploadDns === 'string' && upload.uploadDns)
|
||||||
|| '';
|
|| '';
|
||||||
const httpsHostUsed = !rtpInIP && !upload.uploadIp && !upload.uploadDomain && !ipListFirst
|
const httpsHostUsed = !rtpInIP && !upload.uploadIp && !upload.uploadDomain && !ipListFirst
|
||||||
&& typeof upload.uploadHttpsDomain === 'string' && !!upload.uploadHttpsDomain;
|
&& typeof upload.uploadHttpsDomain === 'string' && !!upload.uploadHttpsDomain;
|
||||||
const uploadPort = rtpInIP && rtpInPort > 0
|
const uploadPort = rtpInIP && rtpInPort > 0
|
||||||
? rtpInPort
|
? rtpInPort
|
||||||
: httpsHostUsed && toInt(upload.uploadHttpsPort) > 0
|
: httpsHostUsed && toInt(upload.uploadHttpsPort) > 0
|
||||||
? toInt(upload.uploadHttpsPort)
|
? toInt(upload.uploadHttpsPort)
|
||||||
: toInt(upload.uploadPort);
|
: toInt(upload.uploadPort);
|
||||||
if (!uploadHost || uploadPort <= 0) {
|
if (!uploadHost || uploadPort <= 0) {
|
||||||
const rtpDump = Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
const rtpDump = Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
||||||
? JSON.stringify(upload.rtpMediaPlatformUploadAddress.map((e) => ({
|
? JSON.stringify(upload.rtpMediaPlatformUploadAddress.map((e) => ({
|
||||||
outIP: e.outIP, outPort: e.outPort, inIP: e.inIP, inPort: e.inPort,
|
outIP: e.outIP, outPort: e.outPort, inIP: e.inIP, inPort: e.inPort,
|
||||||
iPType: e.iPType,
|
iPType: e.iPType,
|
||||||
})))
|
})))
|
||||||
: '[]';
|
: '[]';
|
||||||
log.warn(
|
log.warn(
|
||||||
'private file upload host missing — rtp=%s ip=%s domain=%s ipList=%s httpsDomain=%s dns=%s lanip=%s port=%s httpsPort=%s',
|
'private file upload host missing — rtp=%s ip=%s domain=%s ipList=%s httpsDomain=%s dns=%s lanip=%s port=%s httpsPort=%s',
|
||||||
rtpDump,
|
rtpDump,
|
||||||
upload.uploadIp ?? '', upload.uploadDomain ?? '',
|
upload.uploadIp ?? '', upload.uploadDomain ?? '',
|
||||||
JSON.stringify(upload.uploadIpList ?? []),
|
JSON.stringify(upload.uploadIpList ?? []),
|
||||||
upload.uploadHttpsDomain ?? '', upload.uploadDns ?? '',
|
upload.uploadHttpsDomain ?? '', upload.uploadDns ?? '',
|
||||||
upload.uploadLanip ?? '', upload.uploadPort ?? 0,
|
upload.uploadLanip ?? '', upload.uploadPort ?? 0,
|
||||||
upload.uploadHttpsPort ?? 0,
|
upload.uploadHttpsPort ?? 0,
|
||||||
);
|
);
|
||||||
throw new Error('private file upload host is invalid');
|
throw new Error('private file upload host is invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = buildPrivateFileUploadExt(
|
const ext = buildPrivateFileUploadExt(
|
||||||
senderUin,
|
senderUin,
|
||||||
fileName,
|
|
||||||
staged.fileSize,
|
|
||||||
hashes.md5,
|
|
||||||
hashes.sha1,
|
|
||||||
fileId,
|
|
||||||
upload.mediaPlatformUploadKey instanceof Uint8Array
|
|
||||||
? upload.mediaPlatformUploadKey
|
|
||||||
: (upload.uploadKey instanceof Uint8Array ? upload.uploadKey : new Uint8Array(0)),
|
|
||||||
uploadHost,
|
|
||||||
uploadPort,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fail cleanly if the source changed since hashing, then stream the PUT
|
|
||||||
// from disk. Session BEFORE opening the handle so uploadHighwayHttp (the
|
|
||||||
// handle's owner) is the next call and always closes it.
|
|
||||||
await assertUnchanged(staged.filePath, guardStat);
|
|
||||||
const session = await fetchHighwaySession(bridge);
|
|
||||||
const chunkSource = await FileChunkSource.open(staged.filePath, staged.fileSize);
|
|
||||||
await uploadHighwayHttp(bridge, session, 95, chunkSource, hashes.md5, ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stage 3: publish the file as a c2c chat message. C2C files use
|
|
||||||
// `RichText.notOnlineFile` (parallel to `elems`), so we go through
|
|
||||||
// the dedicated `sendC2cFile` on MessageApi instead of `sendPrivate`
|
|
||||||
// which only knows about elems[]. NapCat does the same atomic
|
|
||||||
// upload+send dance — without it the file sits on the server and
|
|
||||||
// the recipient sees nothing.
|
|
||||||
if (publishFile) {
|
|
||||||
try {
|
|
||||||
await this.ctx.apis.message.sendC2cFile(userId, targetUid, {
|
|
||||||
fileId,
|
|
||||||
fileName,
|
fileName,
|
||||||
fileSize: staged.fileSize,
|
staged.fileSize,
|
||||||
fileMd5: hashes.md5,
|
hashes.md5,
|
||||||
fileHash: fileHash ?? '',
|
hashes.sha1,
|
||||||
});
|
fileId,
|
||||||
} catch (err) {
|
upload.mediaPlatformUploadKey instanceof Uint8Array
|
||||||
log.warn('private file uploaded (fileId=%s) but chat post failed: %s',
|
? upload.mediaPlatformUploadKey
|
||||||
fileId, err instanceof Error ? err.message : String(err));
|
: (upload.uploadKey instanceof Uint8Array ? upload.uploadKey : new Uint8Array(0)),
|
||||||
}
|
uploadHost,
|
||||||
}
|
uploadPort,
|
||||||
|
);
|
||||||
|
|
||||||
return { fileId, fileHash };
|
// Fail cleanly if the source changed since hashing, then stream the PUT
|
||||||
|
// from disk. Session BEFORE opening the handle so uploadHighwayHttp (the
|
||||||
|
// handle's owner) is the next call and always closes it.
|
||||||
|
await assertUnchanged(staged.filePath, guardStat);
|
||||||
|
const session = await fetchHighwaySession(bridge);
|
||||||
|
const chunkSource = await FileChunkSource.open(staged.filePath, staged.fileSize);
|
||||||
|
await uploadHighwayHttp(bridge, session, 95, chunkSource, hashes.md5, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stage 3: publish the file as a c2c chat message. C2C files use
|
||||||
|
// `RichText.notOnlineFile` (parallel to `elems`), so we go through
|
||||||
|
// the dedicated `sendC2cFile` on MessageApi instead of `sendPrivate`
|
||||||
|
// which only knows about elems[]. NapCat does the same atomic
|
||||||
|
// upload+send dance — without it the file sits on the server and
|
||||||
|
// the recipient sees nothing.
|
||||||
|
if (publishFile) {
|
||||||
|
try {
|
||||||
|
await this.ctx.apis.message.sendC2cFile(userId, targetUid, {
|
||||||
|
fileId,
|
||||||
|
fileName,
|
||||||
|
fileSize: staged.fileSize,
|
||||||
|
fileMd5: hashes.md5,
|
||||||
|
fileHash: fileHash ?? '',
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('private file uploaded (fileId=%s) but chat post failed: %s',
|
||||||
|
fileId, err instanceof Error ? err.message : String(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { fileId, fileHash };
|
||||||
} finally {
|
} finally {
|
||||||
await staged.cleanup();
|
await staged.cleanup();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,15 +55,18 @@ export namespace RequestDbKey {
|
|||||||
success: true,
|
success: true,
|
||||||
dbKey: key,
|
dbKey: key,
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
const code = error?.code ?? -1;
|
const failure = typeof error === 'object' && error !== null
|
||||||
|
? error as { code?: number; serverMsg?: string; message?: string }
|
||||||
|
: {};
|
||||||
|
const code = failure.code ?? -1;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
errorCode: code,
|
errorCode: code,
|
||||||
errorMsg: code === 1006
|
errorMsg: code === 1006
|
||||||
? "数据库不匹配!检查数据库是否属于当前帐号"
|
? '数据库不匹配!检查数据库是否属于当前帐号'
|
||||||
: (error?.serverMsg || error?.message || "网络或包结构解析失败"),
|
: (failure.serverMsg || failure.message || '网络或包结构解析失败'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ describe('qzone feeds JS-literal parsing (issue #182)', () => {
|
|||||||
|
|
||||||
it('mapFeeds drops the undefined hole and normalises the feed', () => {
|
it('mapFeeds drops the undefined hole and normalises the feed', () => {
|
||||||
const data = parseQzoneCallback(SAMPLE);
|
const data = parseQzoneCallback(SAMPLE);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const result = mapFeeds(data as any);
|
const result = mapFeeds(data as any);
|
||||||
expect(result.feeds).toHaveLength(1);
|
expect(result.feeds).toHaveLength(1);
|
||||||
const f = result.feeds[0]!;
|
const f = result.feeds[0]!;
|
||||||
@@ -59,7 +58,6 @@ describe('qzone feeds JS-literal parsing (issue #182)', () => {
|
|||||||
|
|
||||||
it('does not pollute Object.prototype via a __proto__ key', () => {
|
it('does not pollute Object.prototype via a __proto__ key', () => {
|
||||||
parseQzoneCallback('_preloadCallback({"__proto__":{"polluted":1},"code":0})');
|
parseQzoneCallback('_preloadCallback({"__proto__":{"polluted":1},"code":0})');
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
expect(({} as any).polluted).toBeUndefined();
|
expect(({} as any).polluted).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export function NotificationsPanel() {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [api]);
|
}, [api, setMsg]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
|
|||||||
Reference in new issue
Block a user