mirror of
https://github.com/ivabus/gui
synced 2025-06-07 15:50:27 +03:00
parent
b60a8b20d4
commit
b85c996c15
3 changed files with 15 additions and 4 deletions
|
@ -182,7 +182,17 @@ export async function cacheImage(url: string): Promise<string> {
|
||||||
log.info("creating folder:", folderPath);
|
log.info("creating folder:", folderPath);
|
||||||
await mkdirp(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 {
|
try {
|
||||||
await downloadImage(url, imagePath);
|
await downloadImage(url, imagePath);
|
||||||
log.info("Image downloaded and cached:", imagePath);
|
log.info("Image downloaded and cached:", imagePath);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "tea",
|
"name": "tea",
|
||||||
"version": "0.2.29",
|
"version": "0.2.30",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "tea gui app",
|
"description": "tea gui app",
|
||||||
"author": "tea.xyz",
|
"author": "tea.xyz",
|
||||||
|
|
|
@ -39,9 +39,10 @@
|
||||||
|
|
||||||
const getCache = async () => {
|
const getCache = async () => {
|
||||||
if (pkg.image_512_url) {
|
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);
|
const nextImage = await packagesStore.cachePkgImage(pkg);
|
||||||
loadImage(nextImage, true);
|
loadImage(nextImage + `?ts=${ts}`, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue