mirror of
https://git.roussel.pro/public-website/singapore_rain_radar.git
synced 2026-02-09 02:20:17 +01:00
video generation working
This commit is contained in:
@@ -30,7 +30,7 @@ function downloadImage(time_string, filepath) {
|
||||
"Sec-Fetch-Dest": "image",
|
||||
"Sec-Fetch-Mode": "no-cors",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
"Priority": "u=5, i",
|
||||
"Priority": "i",
|
||||
"Pragma": "no-cache",
|
||||
"Cache-Control": "no-cache",
|
||||
"TE": "trailers",
|
||||
@@ -61,12 +61,12 @@ function downloadImage(time_string, filepath) {
|
||||
}
|
||||
|
||||
export async function initImages(count) {
|
||||
let files = fs.readdirSync('images/');
|
||||
let files = fs.readdirSync('images/raw');
|
||||
let downloaded = 0;
|
||||
let i = 0;
|
||||
while(downloaded < count) {
|
||||
let time_string = getTimeString(i);
|
||||
let filename = `images/${time_string}.png`;
|
||||
let filename = `images/raw/${time_string}.png`;
|
||||
if (files.includes(`${time_string}.png`)) {
|
||||
downloaded++;
|
||||
i++;
|
||||
@@ -90,7 +90,7 @@ export async function updateImages(count) {
|
||||
for (let i = count; i >= 0; i--) {
|
||||
time_strings.push(getTimeString(i));
|
||||
}
|
||||
let files = fs.readdirSync('images/');
|
||||
let files = fs.readdirSync('images/raw');
|
||||
let image_count = files.length;
|
||||
|
||||
let updated = false;
|
||||
@@ -99,12 +99,11 @@ export async function updateImages(count) {
|
||||
for (let time_string of time_strings) {
|
||||
if (!files.includes(`${time_string}.png`)) {
|
||||
try {
|
||||
await downloadImage(time_string, `images/${time_string}.png`);
|
||||
await downloadImage(time_string, `images/raw/${time_string}.png`);
|
||||
updated = true;
|
||||
image_count++;
|
||||
} catch (error) {
|
||||
console.log("No more images available");
|
||||
break;
|
||||
console.log("Skipped image " + time_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +111,7 @@ export async function updateImages(count) {
|
||||
//Remove old files
|
||||
for (let file of files.sort().slice(0, image_count - count)) {
|
||||
console.log(`Deleting ${file}`);
|
||||
fs.unlinkSync(`images/${file}`);
|
||||
fs.unlinkSync(`images/raw/${file}`);
|
||||
}
|
||||
|
||||
return updated;
|
||||
|
||||
Reference in New Issue
Block a user