Theme Switcher
This commit is contained in:
parent
a13c9a8587
commit
9e455f7a50
|
Before Width: | Height: | Size: 12 MiB After Width: | Height: | Size: 12 MiB |
|
|
@ -65,6 +65,7 @@ export class Paths {
|
|||
resolvePublicGeneratedPath(domain: string = this.domainName): string {
|
||||
return `${SERVICE_DATA}/${PUBLIC_GENERATED}/${domain}`;
|
||||
}
|
||||
|
||||
getStorageDir(): string {
|
||||
return `${SERVICE_DATA}/${PUBLIC_GENERATED}/${STORAGE}/${this.domainName}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,13 @@ class ImageWarmUp {
|
|||
const outputDir = generatedDir;
|
||||
|
||||
return limit(async () => {
|
||||
if (await this.isAlreadyProcessed(outputDir, entry.name)) {
|
||||
if (
|
||||
await this.isAlreadyProcessed(
|
||||
outputDir,
|
||||
entry.name,
|
||||
fullPath,
|
||||
)
|
||||
) {
|
||||
if (verbose)
|
||||
console.log(
|
||||
`⏩ Already processed: ${newRelativePath}`,
|
||||
|
|
@ -151,29 +157,47 @@ class ImageWarmUp {
|
|||
}
|
||||
|
||||
/** 🔍 Sprawdza czy plik już został przetworzony */
|
||||
/** 🔍 Sprawdza czy plik już został przetworzony i czy nie jest nowszy */
|
||||
private async isAlreadyProcessed(
|
||||
outputDir: string,
|
||||
filename: string,
|
||||
sourcePath: string, // dodajemy pełną ścieżkę do oryginału
|
||||
): Promise<boolean> {
|
||||
const base = path.parse(filename).name;
|
||||
|
||||
// Dla generowanych obrazów sprawdzamy, czy pliki webp i avif istnieją
|
||||
if (this.pictureType === PictureType.generated) {
|
||||
const webpPath = path.join(outputDir, `${base}.webp`);
|
||||
const avifPath = path.join(outputDir, `${base}.avif`);
|
||||
try {
|
||||
await fs.access(webpPath);
|
||||
await fs.access(avifPath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Dla skompresowanych obrazów, wystarczy sprawdzić dowolny plik z tą samą nazwą
|
||||
try {
|
||||
const files = await fs.readdir(outputDir);
|
||||
return files.some((f) => path.parse(f).name === base);
|
||||
const sourceStat = await fs.stat(sourcePath);
|
||||
|
||||
if (this.pictureType === PictureType.generated) {
|
||||
const webpPath = path.join(outputDir, `${base}.webp`);
|
||||
const avifPath = path.join(outputDir, `${base}.avif`);
|
||||
|
||||
const webpStat = await fs.stat(webpPath).catch(() => null);
|
||||
const avifStat = await fs.stat(avifPath).catch(() => null);
|
||||
|
||||
if (!webpStat || !avifStat) return false;
|
||||
|
||||
// jeśli oryginał jest nowszy -> trzeba przetworzyć
|
||||
return (
|
||||
webpStat.mtime >= sourceStat.mtime &&
|
||||
avifStat.mtime >= sourceStat.mtime
|
||||
);
|
||||
} else {
|
||||
const files = await fs.readdir(outputDir).catch(() => []);
|
||||
const candidate = files.find(
|
||||
(f) => path.parse(f).name === base,
|
||||
);
|
||||
|
||||
if (!candidate) return false;
|
||||
|
||||
const compressedStat = await fs
|
||||
.stat(path.join(outputDir, candidate))
|
||||
.catch(() => null);
|
||||
|
||||
return (
|
||||
!!compressedStat && compressedStat.mtime >= sourceStat.mtime
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue