Skip to content

Commit

Permalink
fix: old version handle
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Nov 20, 2024
1 parent d5f4927 commit 16195ca
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/core/apis/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,17 @@ export class NTQQFileApi {
}

const url: string = element.originImageUrl ?? '';

const md5HexStr = element.md5HexStr;
const fileMd5 = element.md5HexStr;

if (url) {
const parsedUrl = new URL(IMAGE_HTTP_HOST + url);
const parsedUrl = new URL(IMAGE_HTTP_HOST + url);
const imageAppid = parsedUrl.searchParams.get('appid');
const isNTV2 = imageAppid && ['1406', '1407'].includes(imageAppid);
const imageFileId = parsedUrl.searchParams.get('fileid');
if (url && isNTV2 && imageFileId) {
const rkeyData = await this.getRkeyData();
return this.getImageUrlFromParsedUrl(parsedUrl, rkeyData);
return this.getImageUrlFromParsedUrl(imageFileId, imageAppid, rkeyData);
}

return this.getImageUrlFromMd5(fileMd5, md5HexStr);
}

Expand Down Expand Up @@ -462,19 +464,12 @@ export class NTQQFileApi {
return rkeyData;
}

private getImageUrlFromParsedUrl(parsedUrl: URL, rkeyData: any): string {
const imageAppid = parsedUrl.searchParams.get('appid');
const isNTV2 = imageAppid && ['1406', '1407'].includes(imageAppid);
const imageFileId = parsedUrl.searchParams.get('fileid');
if (isNTV2 && rkeyData.online_rkey) {
const rkey = imageAppid === '1406' ? rkeyData.private_rkey : rkeyData.group_rkey;
return IMAGE_HTTP_HOST_NT + `/download?appid=${imageAppid}&fileid=${imageFileId}&rkey=${rkey}`;
} else if (isNTV2 && imageFileId) {
const rkey = imageAppid === '1406' ? rkeyData.private_rkey : rkeyData.group_rkey;
return IMAGE_HTTP_HOST + `/download?appid=${imageAppid}&fileid=${imageFileId}&rkey=${rkey}`;
private getImageUrlFromParsedUrl(imageFileId: string, appid: string, rkeyData: any): string {
const rkey = appid === '1406' ? rkeyData.private_rkey : rkeyData.group_rkey;
if (rkeyData.online_rkey) {
return IMAGE_HTTP_HOST_NT + `/download?appid=${appid}&fileid=${imageFileId}&rkey=${rkey}`;
}

return '';
return IMAGE_HTTP_HOST + `/download?appid=${appid}&fileid=${imageFileId}&rkey=${rkey}`;
}

private getImageUrlFromMd5(fileMd5: string | undefined, md5HexStr: string | undefined): string {
Expand Down

0 comments on commit 16195ca

Please sign in to comment.