ingest now downloads borders
This commit is contained in:
parent
19a94f927e
commit
5e0c7153b9
4 changed files with 109 additions and 5 deletions
|
@ -1,4 +1,3 @@
|
|||
console.log("a");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Prisma = require("@prisma/client");
|
||||
|
@ -14,9 +13,10 @@ const folder = path.join(
|
|||
cwd.includes("util") ? ".." : "",
|
||||
"public/images"
|
||||
);
|
||||
|
||||
const list = fs.readdirSync(folder);
|
||||
|
||||
(async () => {
|
||||
let catalogue = async () => {
|
||||
let numAdded = 0;
|
||||
for (let item of list) {
|
||||
// console.log(item);
|
||||
|
@ -31,6 +31,7 @@ const list = fs.readdirSync(folder);
|
|||
data: {
|
||||
id: 0,
|
||||
imageName: item,
|
||||
borderName: "Default",
|
||||
},
|
||||
});
|
||||
numAdded++;
|
||||
|
@ -46,4 +47,62 @@ const list = fs.readdirSync(folder);
|
|||
}
|
||||
}
|
||||
console.log(`Processed ${numAdded} new images.`);
|
||||
})();
|
||||
};
|
||||
|
||||
let download = async () => {
|
||||
const fetch = await import("node-fetch");
|
||||
const filePath = path.join(
|
||||
cwd,
|
||||
cwd.includes("util") ? ".." : "",
|
||||
"util/border_data.json"
|
||||
);
|
||||
const json_data = JSON.parse(fs.readFileSync(filePath));
|
||||
let numAdded = 0;
|
||||
for (let value of json_data) {
|
||||
if (!value) continue;
|
||||
const filename_regex =
|
||||
/https:\/\/cdn.akamai.steamstatic.com\/steamcommunity\/public\/images\/items\/\d+\/(.+\.png)/gi;
|
||||
const filename = filename_regex.exec(value.borderURL)[1];
|
||||
|
||||
if (!list.includes(filename)) {
|
||||
console.log("N", filename);
|
||||
let data = await fetch.default(value.borderURL);
|
||||
data.body.pipe(fs.createWriteStream(path.join(folder, filename)));
|
||||
}
|
||||
|
||||
const result = await prisma.borderImage.findFirst({
|
||||
where: {
|
||||
imageName: filename,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result.appId || !result.appName || !result.borderName) {
|
||||
const added = await prisma.borderImage.upsert({
|
||||
create: {
|
||||
imageName: filename,
|
||||
appId: value.appInfo.appid,
|
||||
appName: value.appInfo.name,
|
||||
borderName: value.name,
|
||||
},
|
||||
update: {
|
||||
imageName: filename,
|
||||
appId: value.appInfo.appid,
|
||||
appName: value.appInfo.name,
|
||||
borderName: value.name,
|
||||
},
|
||||
where: {
|
||||
imageName: filename,
|
||||
},
|
||||
});
|
||||
console.log(added);
|
||||
numAdded++;
|
||||
}
|
||||
}
|
||||
console.log(`Upserted ${numAdded} values.`);
|
||||
};
|
||||
|
||||
download().then(() => {
|
||||
catalogue().then(() => {
|
||||
console.log("done.");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue