修复下载信息,清除部分日志
This commit is contained in:
@@ -124,23 +124,16 @@ class PixivAuth {
|
||||
include_policy: true
|
||||
};
|
||||
|
||||
console.log('请求数据:', data);
|
||||
|
||||
const headers = {
|
||||
...this.getDefaultHeaders(),
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
};
|
||||
|
||||
console.log('请求头部:', headers);
|
||||
|
||||
const response = await this.axiosInstance.post('https://oauth.secure.pixiv.net/auth/token',
|
||||
stringify(data),
|
||||
{ headers }
|
||||
);
|
||||
|
||||
console.log('响应状态:', response.status);
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
const tokenData = response.data.response;
|
||||
|
||||
this.accessToken = tokenData.access_token;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ const PixivAuth = require('./auth');
|
||||
const DownloadService = require('./services/download');
|
||||
|
||||
// 配置文件路径
|
||||
const CONFIG_FILE_DIR = require('appdata-path').getAppDataPath('pxder');
|
||||
const CONFIG_FILE_DIR = require('appdata-path').getAppDataPath('pmanager');
|
||||
const CONFIG_FILE = Path.resolve(CONFIG_FILE_DIR, 'config.json');
|
||||
|
||||
// 默认配置
|
||||
|
||||
@@ -650,41 +650,4 @@ router.get('/stats', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 强制重新检查作品下载状态
|
||||
* POST /api/download/force-check/:artworkId
|
||||
*/
|
||||
router.post('/force-check/:artworkId', async (req, res) => {
|
||||
try {
|
||||
const { artworkId } = req.params;
|
||||
|
||||
if (!artworkId || isNaN(parseInt(artworkId))) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'Invalid artwork ID'
|
||||
});
|
||||
}
|
||||
|
||||
const downloadService = req.backend.getDownloadService();
|
||||
|
||||
// 强制重新检查,包括清理不完整的文件
|
||||
const result = await downloadService.forceCheckArtworkDownloaded(parseInt(artworkId));
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: {
|
||||
artwork_id: parseInt(artworkId),
|
||||
is_downloaded: result.is_downloaded,
|
||||
cleaned_files: result.cleaned_files || 0,
|
||||
message: result.message
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -319,7 +319,11 @@ class DownloadService {
|
||||
|
||||
// 检查作品信息文件 - 这是最可靠的判断标准
|
||||
const infoPath = path.join(artworkPath, 'artwork_info.json');
|
||||
if (!(await this.fileManager.fileExists(infoPath))) {
|
||||
let artworkInfo;
|
||||
try {
|
||||
const infoContent = await fs.readFile(infoPath, 'utf8');
|
||||
artworkInfo = JSON.parse(infoContent);
|
||||
} catch (error) {
|
||||
console.log(`作品 ${artworkId} 缺少信息文件,认为未下载`);
|
||||
return false;
|
||||
}
|
||||
@@ -333,8 +337,15 @@ class DownloadService {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 有信息文件且有图片文件,认为已下载
|
||||
console.log(`作品 ${artworkId} 已下载,有信息文件和 ${imageFiles.length} 个图片文件`);
|
||||
// 检查图片数量是否与artwork_info.json中记录的一致
|
||||
const expectedImageCount = artworkInfo.page_count || 1;
|
||||
if (imageFiles.length < expectedImageCount) {
|
||||
console.log(`作品 ${artworkId} 图片数量不匹配: 期望 ${expectedImageCount} 个,实际 ${imageFiles.length} 个`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 有信息文件、有图片文件且数量匹配,认为已下载
|
||||
console.log(`作品 ${artworkId} 已完整下载,有信息文件和 ${imageFiles.length}/${expectedImageCount} 个图片文件`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -347,83 +358,6 @@ class DownloadService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制重新检查作品下载状态,包括清理不完整的文件
|
||||
*/
|
||||
async forceCheckArtworkDownloaded(artworkId) {
|
||||
try {
|
||||
const downloadPath = await this.fileManager.getDownloadPath();
|
||||
let cleanedFiles = 0;
|
||||
|
||||
// 扫描所有作者目录
|
||||
const artistEntries = await this.fileManager.listDirectory(downloadPath);
|
||||
|
||||
for (const artistEntry of artistEntries) {
|
||||
const artistPath = path.join(downloadPath, artistEntry);
|
||||
const artistStat = await this.fileManager.getFileInfo(artistPath);
|
||||
|
||||
if (!artistStat.exists || !artistStat.isDirectory) continue;
|
||||
|
||||
// 扫描作者下的作品目录
|
||||
const artworkEntries = await this.fileManager.listDirectory(artistPath);
|
||||
|
||||
for (const artworkEntry of artworkEntries) {
|
||||
// 检查是否是目标作品目录(包含数字ID)
|
||||
const artworkMatch = artworkEntry.match(/^(\d+)_(.+)$/);
|
||||
if (artworkMatch && artworkMatch[1] === artworkId.toString()) {
|
||||
const artworkPath = path.join(artistPath, artworkEntry);
|
||||
|
||||
// 检查作品信息文件 - 这是最可靠的判断标准
|
||||
const infoPath = path.join(artworkPath, 'artwork_info.json');
|
||||
if (!(await this.fileManager.fileExists(infoPath))) {
|
||||
console.log(`作品 ${artworkId} 缺少信息文件,清理目录`);
|
||||
await this.fileManager.removeDirectory(artworkPath);
|
||||
return {
|
||||
is_downloaded: false,
|
||||
cleaned_files: 1,
|
||||
message: '作品目录不完整,已清理'
|
||||
};
|
||||
}
|
||||
|
||||
// 检查是否有图片文件
|
||||
const files = await this.fileManager.listDirectory(artworkPath);
|
||||
const imageFiles = files.filter(file => /\.(jpg|jpeg|png|gif|webp)$/i.test(file) && file !== 'artwork_info.json');
|
||||
|
||||
if (imageFiles.length === 0) {
|
||||
console.log(`作品 ${artworkId} 有信息文件但没有图片文件,清理目录`);
|
||||
await this.fileManager.removeDirectory(artworkPath);
|
||||
return {
|
||||
is_downloaded: false,
|
||||
cleaned_files: 1,
|
||||
message: '作品目录没有图片文件,已清理'
|
||||
};
|
||||
}
|
||||
|
||||
// 有信息文件且有图片文件,认为已下载
|
||||
return {
|
||||
is_downloaded: true,
|
||||
cleaned_files: cleanedFiles,
|
||||
message: `作品已下载,有信息文件和 ${imageFiles.length} 个图片文件`
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
is_downloaded: false,
|
||||
cleaned_files: cleanedFiles,
|
||||
message: '作品未找到'
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('强制检查作品下载状态失败:', error);
|
||||
return {
|
||||
is_downloaded: false,
|
||||
cleaned_files: 0,
|
||||
message: `检查失败: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载单个作品
|
||||
*/
|
||||
|
||||
@@ -466,10 +466,12 @@ class RepositoryService {
|
||||
|
||||
// 检查作品信息文件 - 这是最可靠的判断标准
|
||||
const infoPath = path.join(artworkPath, 'artwork_info.json')
|
||||
let artworkInfo;
|
||||
try {
|
||||
await fs.access(infoPath)
|
||||
const infoContent = await fs.readFile(infoPath, 'utf8')
|
||||
artworkInfo = JSON.parse(infoContent)
|
||||
} catch (error) {
|
||||
// 信息文件不存在,认为未下载
|
||||
// 信息文件不存在或无法读取,认为未下载
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -480,7 +482,16 @@ class RepositoryService {
|
||||
return false
|
||||
}
|
||||
|
||||
// 有信息文件且有图片文件,认为已下载
|
||||
// 检查图片数量是否与artwork_info.json中记录的一致
|
||||
const expectedImageCount = artworkInfo.page_count || 1
|
||||
if (files.length < expectedImageCount) {
|
||||
// 图片文件数量不足,认为下载不完整
|
||||
console.log(`作品 ${artworkId} 图片数量不匹配: 期望 ${expectedImageCount} 个,实际 ${files.length} 个`)
|
||||
return false
|
||||
}
|
||||
|
||||
// 有信息文件、有图片文件且数量匹配,认为已下载
|
||||
console.log(`作品 ${artworkId} 已完整下载: ${files.length}/${expectedImageCount} 个图片文件`)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user