Skip to content

Commit

Permalink
fix: 下载 QQ 图片有时证书错误
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Jul 11, 2024
1 parent 2f9cc7b commit f8c5907
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main/src/models/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else {

export default {
capture(event: string, properties: Record<string, any>) {
if (typeof properties?.error === 'object' && properties.error.stack) {
if (typeof properties?.error === 'object' && properties.error.stack && JSON.stringify(properties.error) === '{}') {
properties.error = properties.error.stack;
}
properties.repo = env.REPO;
Expand Down
8 changes: 7 additions & 1 deletion main/src/utils/urls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import { Friend, Group } from '@icqqjs/icqq';
import * as https from 'node:https';

export function getAvatarUrl(room: number | bigint | Friend | Group): string {
if (!room) return '';
Expand All @@ -22,9 +23,14 @@ export function getBigFaceUrl(file: string) {
return `https://gxh.vip.qq.com/club/item/parcel/item/${file.substring(0, 2)}/${file.substring(0, 32)}/300x300.png`;
}

const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});

export async function fetchFile(url: string): Promise<Buffer> {
const res = await axios.get(url, {
responseType: 'arraybuffer',
httpsAgent,
});
return res.data;
}
Expand All @@ -34,5 +40,5 @@ export function getAvatar(room: number | Friend | Group) {
}

export function isContainsUrl(msg: string): boolean {
return msg.includes("https://") || msg.includes("http://")
return msg.includes('https://') || msg.includes('http://');
}

0 comments on commit f8c5907

Please sign in to comment.