Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions main/src/client/NapCatClient/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class NapCatClient extends QQClient {
}
category.friends.push(NapCatFriend.createExisted(this, {
nickname: it.nick || it.nickname,
uid: parseInt(it.uin),
uid: parseInt(it.uin || it.user_id),
remark: it.remark,
}));
}
Expand All @@ -225,8 +225,8 @@ export class NapCatClient extends QQClient {
return data.map(it => ({
name: it.categoryName || (it as any).categroyName, // typo in API
friends: it.buddyList.map(friend => NapCatFriend.createExisted(this, {
nickname: friend.nick,
uid: parseInt(friend.uin),
nickname: friend.nick || friend.nickname,
uid: parseInt(friend.uin || friend.user_id),
remark: friend.remark,
})),
}));
Expand Down
1 change: 1 addition & 0 deletions main/src/helpers/forwardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export default {
},

generateRichHeaderUrl(apiKey: string, userId: number, messageHeader = '') {
if (!env.WEB_ENDPOINT) return '';
const url = new URL(`${env.WEB_ENDPOINT}/richHeader/${apiKey}/${userId}`);
// 防止群名片刷新慢
messageHeader && url.searchParams.set('hash', md5Hex(messageHeader).substring(0, 10));
Expand Down
10 changes: 8 additions & 2 deletions main/src/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ export default class ConfigService {
private async onSelectChatPersonal(entity: Friend | Group) {
const roomId = 'uin' in entity ? entity.uin : -entity.gid;
const name = 'uin' in entity ? entity.remark || entity.nickname : entity.name;
const avatar = await getAvatar(roomId);
let avatar: Buffer;
try {
avatar = await getAvatar(roomId);
}
catch (e) {
avatar = null;
}
const message = await (await this.owner).sendMessage({
message: await getAboutText(entity, true),
buttons: [
Comment on lines 75 to 86
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk):avatar 的类型和错误处理方式与其可能为 null 的情况对齐。

avatar 被声明为 Buffer 类型,但在 catch 中被赋值为 null,这会破坏严格类型检查,并且会悄悄吞掉 getAvatar 的失败。建议使用可空类型并记录错误日志,例如:

let avatar: Buffer | null = null;
try {
  avatar = await getAvatar(roomId);
} catch (e) {
  this.logger?.warn?.('Failed to load avatar', { roomId, error: e });
}

const file = avatar
  ? new CustomFile('avatar.png', avatar.length, '', avatar)
  : undefined;
Suggested change
const roomId = 'uin' in entity ? entity.uin : -entity.gid;
const name = 'uin' in entity ? entity.remark || entity.nickname : entity.name;
const avatar = await getAvatar(roomId);
let avatar: Buffer;
try {
avatar = await getAvatar(roomId);
}
catch (e) {
avatar = null;
}
const message = await (await this.owner).sendMessage({
message: await getAboutText(entity, true),
buttons: [
const roomId = 'uin' in entity ? entity.uin : -entity.gid;
const name = 'uin' in entity ? entity.remark || entity.nickname : entity.name;
let avatar: Buffer | null = null;
try {
avatar = await getAvatar(roomId);
} catch (e) {
this.logger?.warn?.('Failed to load avatar', { roomId, error: e });
}
const message = await (await this.owner).sendMessage({
message: await getAboutText(entity, true),
buttons: [
}))],
[Button.url('手动选择现有群组', this.getAssociateLink(roomId))],
],
file: avatar ? new CustomFile('avatar.png', avatar.length, '', avatar) : undefined,
});
Original comment in English

suggestion (bug_risk): Align avatar typing and error handling with the possibility of null.

avatar is typed as Buffer but assigned null in the catch, which breaks strict typing and silently hides getAvatar failures. Consider using a nullable type and logging the error, e.g.

let avatar: Buffer | null = null;
try {
  avatar = await getAvatar(roomId);
} catch (e) {
  this.logger?.warn?.('Failed to load avatar', { roomId, error: e });
}

const file = avatar
  ? new CustomFile('avatar.png', avatar.length, '', avatar)
  : undefined;
Suggested change
const roomId = 'uin' in entity ? entity.uin : -entity.gid;
const name = 'uin' in entity ? entity.remark || entity.nickname : entity.name;
const avatar = await getAvatar(roomId);
let avatar: Buffer;
try {
avatar = await getAvatar(roomId);
}
catch (e) {
avatar = null;
}
const message = await (await this.owner).sendMessage({
message: await getAboutText(entity, true),
buttons: [
const roomId = 'uin' in entity ? entity.uin : -entity.gid;
const name = 'uin' in entity ? entity.remark || entity.nickname : entity.name;
let avatar: Buffer | null = null;
try {
avatar = await getAvatar(roomId);
} catch (e) {
this.logger?.warn?.('Failed to load avatar', { roomId, error: e });
}
const message = await (await this.owner).sendMessage({
message: await getAboutText(entity, true),
buttons: [
}))],
[Button.url('手动选择现有群组', this.getAssociateLink(roomId))],
],
file: avatar ? new CustomFile('avatar.png', avatar.length, '', avatar) : undefined,
});

Expand All @@ -85,7 +91,7 @@ export default class ConfigService {
}))],
[Button.url('手动选择现有群组', this.getAssociateLink(roomId))],
],
file: new CustomFile('avatar.png', avatar.length, '', avatar),
file: avatar ? new CustomFile('avatar.png', avatar.length, '', avatar) : undefined,
});
}

Expand Down
1 change: 1 addition & 0 deletions main/src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const httpsAgent = new https.Agent({
});

export async function fetchFile(url: string): Promise<Buffer> {
if (!url) return Buffer.alloc(0);
const res = await axios.get(url, {
responseType: 'arraybuffer',
httpsAgent,
Expand Down