Enhance image fetching logic to load existing images from images.json and skip downloading if already present. This improves efficiency by avoiding redundant downloads.
This commit is contained in:
parent
395a5ad6e6
commit
7a17c8cc71
@ -32,6 +32,13 @@ async function getAlbumAssets() {
|
||||
fs.mkdirSync(config.outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Load existing images.json if it exists
|
||||
let existingImages = [];
|
||||
const imagesJsonPath = './images.json';
|
||||
if (fs.existsSync(imagesJsonPath)) {
|
||||
existingImages = JSON.parse(fs.readFileSync(imagesJsonPath, 'utf8'));
|
||||
}
|
||||
|
||||
const url = `${config.baseUrl}/api/albums/${config.albumId}`;
|
||||
console.log('Fetching album data from:', url);
|
||||
|
||||
@ -53,6 +60,15 @@ async function getAlbumAssets() {
|
||||
for (const asset of response.data.assets) {
|
||||
const originalUrl = `${config.baseUrl}/api/assets/${asset.id}/original`;
|
||||
const fileName = `${asset.id}_${asset.originalFileName || 'untitled'}`;
|
||||
const outputPath = path.join(config.outputDir, fileName);
|
||||
|
||||
// Check if file already exists and is in our metadata
|
||||
const existingImage = existingImages.find(img => img.id === asset.id);
|
||||
if (existingImage && fs.existsSync(existingImage.localPath)) {
|
||||
console.log(`Skipping existing file: ${fileName}`);
|
||||
images.push(existingImage);
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`Downloading: ${fileName}`);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user