Bugfix image updating (#680)

cache expire after 24h
This commit is contained in:
Neil 2023-06-26 13:44:14 +08:00 committed by GitHub
parent b60a8b20d4
commit b85c996c15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View file

@ -182,7 +182,17 @@ export async function cacheImage(url: string): Promise<string> {
log.info("creating folder:", folderPath);
await mkdirp(folderPath);
if (!fs.existsSync(imagePath)) {
let expired = false;
const exists = await fs.existsSync(imagePath);
if (exists) {
const stats = await fs.statSync(imagePath);
const now = new Date();
const diff = now.getTime() - stats.birthtime.getTime();
const hours = Math.floor(diff / 1000 / 60 / 60);
expired = hours > 24;
}
if (!exists || expired) {
try {
await downloadImage(url, imagePath);
log.info("Image downloaded and cached:", imagePath);

View file

@ -1,6 +1,6 @@
{
"name": "tea",
"version": "0.2.29",
"version": "0.2.30",
"private": true,
"description": "tea gui app",
"author": "tea.xyz",

View file

@ -39,9 +39,10 @@
const getCache = async () => {
if (pkg.image_512_url) {
loadImage(pkg.image_512_url, true).finally(async () => {
const ts = +new Date();
loadImage(pkg.image_512_url + `?ts=${ts}`, true).finally(async () => {
const nextImage = await packagesStore.cachePkgImage(pkg);
loadImage(nextImage, true);
loadImage(nextImage + `?ts=${ts}`, true);
});
}
};