mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Ensure final asset directory exists before writing cached files (#12418)
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
parent
cec4af8fe5
commit
25baa4ed0c
2 changed files with 8 additions and 3 deletions
5
.changeset/thick-shrimps-hammer.md
Normal file
5
.changeset/thick-shrimps-hammer.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix cached image redownloading if it is the first asset
|
|
@ -153,6 +153,9 @@ export async function generateImagesForPath(
|
||||||
const isLocalImage = isESMImportedImage(options.src);
|
const isLocalImage = isESMImportedImage(options.src);
|
||||||
const finalFileURL = new URL('.' + filepath, env.clientRoot);
|
const finalFileURL = new URL('.' + filepath, env.clientRoot);
|
||||||
|
|
||||||
|
const finalFolderURL = new URL('./', finalFileURL);
|
||||||
|
await fs.promises.mkdir(finalFolderURL, { recursive: true });
|
||||||
|
|
||||||
// For remote images, instead of saving the image directly, we save a JSON file with the image data and expiration date from the server
|
// For remote images, instead of saving the image directly, we save a JSON file with the image data and expiration date from the server
|
||||||
const cacheFile = basename(filepath) + (isLocalImage ? '' : '.json');
|
const cacheFile = basename(filepath) + (isLocalImage ? '' : '.json');
|
||||||
const cachedFileURL = new URL(cacheFile, env.assetsCacheDir);
|
const cachedFileURL = new URL(cacheFile, env.assetsCacheDir);
|
||||||
|
@ -194,9 +197,6 @@ export async function generateImagesForPath(
|
||||||
// If the cache file doesn't exist, just move on, and we'll generate it
|
// If the cache file doesn't exist, just move on, and we'll generate it
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalFolderURL = new URL('./', finalFileURL);
|
|
||||||
await fs.promises.mkdir(finalFolderURL, { recursive: true });
|
|
||||||
|
|
||||||
// The original filepath or URL from the image transform
|
// The original filepath or URL from the image transform
|
||||||
const originalImagePath = isLocalImage
|
const originalImagePath = isLocalImage
|
||||||
? (options.src as ImageMetadata).src
|
? (options.src as ImageMetadata).src
|
||||||
|
|
Loading…
Reference in a new issue