优化 素材库新增处理优化,提速,其余bug处理
This commit is contained in:
1 parent
ad774d8a22
commit
4bce6f5d72
67 files changed
+4861
-3111
No files matched your search
@@ -103,52 +103,32 @@ router.get('/:id', asyncHandler(async (req, res) => {
|
||||
router.get('/thumbnail/:libraryId/:filename', (req, res) => {
|
||||
const { libraryId, filename } = req.params;
|
||||
|
||||
console.log(`[Thumbnail] ========== NEW REQUEST ==========`);
|
||||
console.log(`[Thumbnail] LibraryId: ${libraryId}, Filename: ${filename}`);
|
||||
|
||||
try {
|
||||
const config = require('../../utils/config').loadConfig();
|
||||
console.log(`[Thumbnail] All libraries:`, config.libraries.map(l => ({ id: l.id, type: typeof l.id })));
|
||||
|
||||
// 尝试两种方式查找:数字和字符串
|
||||
let library = config.libraries.find(lib => lib.id === parseInt(libraryId));
|
||||
if (!library) {
|
||||
library = config.libraries.find(lib => lib.id == libraryId); // 使用 == 宽松比较
|
||||
library = config.libraries.find(lib => lib.id == libraryId);
|
||||
}
|
||||
|
||||
if (!library) {
|
||||
console.log(`[Thumbnail] Library not found: ${libraryId} (type: ${typeof libraryId})`);
|
||||
return res.status(404).send('Library not found');
|
||||
}
|
||||
|
||||
console.log(`[Thumbnail] Library path: ${library.path}`);
|
||||
|
||||
// 使用分片结构:取文件名前2个字符作为分片目录
|
||||
const hash = filename.replace(/\.[^/.]+$/, ''); // 移除扩展名
|
||||
const hash = filename.replace(/\.[^/.]+$/, '');
|
||||
const shard = hash.slice(0, 2);
|
||||
const flypicPath = getFlypicPath(library.path);
|
||||
const thumbnailPath = path.join(flypicPath, 'thumbnails', shard, filename);
|
||||
|
||||
console.log(`[Thumbnail] Hash: ${hash}, Shard: ${shard}`);
|
||||
console.log(`[Thumbnail] Full path: ${thumbnailPath}`);
|
||||
console.log(`[Thumbnail] File exists: ${fs.existsSync(thumbnailPath)}`);
|
||||
|
||||
if (!fs.existsSync(thumbnailPath)) {
|
||||
// 列出分片目录的内容
|
||||
const shardDir = path.join(flypicPath, 'thumbnails', shard);
|
||||
if (fs.existsSync(shardDir)) {
|
||||
const files = fs.readdirSync(shardDir);
|
||||
console.log(`[Thumbnail] Files in shard dir (${shard}):`, files.slice(0, 5));
|
||||
} else {
|
||||
console.log(`[Thumbnail] Shard directory does not exist: ${shardDir}`);
|
||||
}
|
||||
return res.status(404).send('Thumbnail not found');
|
||||
}
|
||||
|
||||
console.log(`[Thumbnail] ✅ Serving file`);
|
||||
res.sendFile(thumbnailPath);
|
||||
} catch (error) {
|
||||
console.error('[Thumbnail] Error:', error);
|
||||
console.error('❌ 缩略图错误:', error.message);
|
||||
res.status(500).send('Error serving thumbnail');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user