2022-02-23 09:11:04 +00:00
|
|
|
import axios from 'axios';
|
2023-06-30 11:26:45 +00:00
|
|
|
import { Friend, Group } from 'icqq';
|
2022-02-23 09:11:04 +00:00
|
|
|
|
2023-01-13 09:57:00 +00:00
|
|
|
export function getAvatarUrl(room: number | bigint | Friend | Group): string {
|
2022-03-27 11:24:56 +00:00
|
|
|
if (!room) return '';
|
|
|
|
if (room instanceof Friend) {
|
|
|
|
room = room.user_id;
|
|
|
|
}
|
|
|
|
if (room instanceof Group) {
|
2022-07-14 10:16:44 +00:00
|
|
|
room = -room.group_id;
|
2022-03-27 11:24:56 +00:00
|
|
|
}
|
|
|
|
return room < 0 ?
|
|
|
|
`https://p.qlogo.cn/gh/${-room}/${-room}/0` :
|
|
|
|
`https://q1.qlogo.cn/g?b=qq&nk=${room}&s=0`;
|
2022-02-20 10:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getImageUrlByMd5(md5: string) {
|
|
|
|
return 'https://gchat.qpic.cn/gchatpic_new/0/0-0-' + md5.toUpperCase() + '/0';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getBigFaceUrl(file: string) {
|
2022-02-24 10:27:06 +00:00
|
|
|
return `https://gxh.vip.qq.com/club/item/parcel/item/${file.substring(0, 2)}/${file.substring(0, 32)}/300x300.png`;
|
2022-02-20 10:01:07 +00:00
|
|
|
}
|
2022-02-23 09:11:04 +00:00
|
|
|
|
2022-02-24 10:27:06 +00:00
|
|
|
export async function fetchFile(url: string): Promise<Buffer> {
|
|
|
|
const res = await axios.get(url, {
|
2022-02-23 09:11:04 +00:00
|
|
|
responseType: 'arraybuffer',
|
|
|
|
});
|
|
|
|
return res.data;
|
|
|
|
}
|
2022-02-24 10:27:06 +00:00
|
|
|
|
2022-03-27 11:24:56 +00:00
|
|
|
export function getAvatar(room: number | Friend | Group) {
|
|
|
|
return fetchFile(getAvatarUrl(room));
|
2022-02-24 10:27:06 +00:00
|
|
|
}
|