full rewrite
This commit is contained in:
23
src/getImages.js
Normal file
23
src/getImages.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const fs = require("fs");
|
||||
|
||||
const CSV_FILE = process.env.CSV_FILE || "./uploads/sha1.csv";
|
||||
const IMAGE_BASE_URL = process.env.IMAGE_BASE_URL || "https://placehold.co/";
|
||||
|
||||
function getImages() {
|
||||
if (!fs.existsSync(CSV_FILE)) return [];
|
||||
|
||||
return fs
|
||||
.readFileSync(CSV_FILE, "utf-8")
|
||||
.split("\n")
|
||||
.filter(line => line.includes(";"))
|
||||
.map(line => {
|
||||
const [hash, filename] = line.split(";");
|
||||
return {
|
||||
url: `${IMAGE_BASE_URL.replace(/\/$/, "")}/${filename.trim()}`,
|
||||
name: filename.trim(),
|
||||
hash: hash,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = getImages;
|
||||
Reference in New Issue
Block a user