Skip to content

Commit

Permalink
fix: CQ:image file 为 url 时不能正确缓存搜图结果 #465
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed May 17, 2024
1 parent 5dbd0ae commit 1c9e1fb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/psCache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Path from 'path';
import { encode, decode } from '@msgpack/msgpack';
import Fs from 'fs-extra';
import klaw from 'klaw-sync';
import md5 from 'md5';
import emitter from './emitter.mjs';
import logError from './logError.mjs';
import { getDirname } from './path.mjs';
Expand Down Expand Up @@ -49,7 +50,12 @@ class PSCache {
* @private
*/
getCachePath(img, db) {
return Path.resolve(__dirname, '../../data/pscache', `${img.file}.${db}.psc`);
let key = img.file;
if (key.includes('/')) {
const match = /\/\d+-\d+-([0-9a-zA-Z]+)\//.exec(key) || /(?:&|\?)fileid=([^&]+)/.exec(key);
key = match ? match[1] : md5(key);
}
return Path.resolve(__dirname, '../../data/pscache', `${key}.${db}.psc`);
}

/**
Expand Down

0 comments on commit 1c9e1fb

Please sign in to comment.