blob: 9e89a50528b58a7ea06a9dd8ee49071f459507a8 (
plain) (
tree)
|
|
/**
* fetches the full news file and generates a json file with the first entry
* and another with the full archive
*/
const https = require("https");
const fs = require("fs");
const source = "https://themanaworld.github.io/tmwa-server-data/news.json";
console.info("Acquiring news from static site...");
https.get(source, res => {
let file = "";
res.on("data", chunk => file += chunk);
res.on("end", () => {
const news = JSON.parse(file);
const first = [];
console.info(`Received ${news.length} news entries; splitting...`);
if (news.length > 0) {
first.push(news[0]);
let data = new Uint8Array(Buffer.from(JSON.stringify(first)));
fs.writeFileSync("src/assets/news.json", data, {
encoding: "utf-8",
flag: "w+",
});
data = new Uint8Array(Buffer.from(file));
fs.writeFileSync("src/assets/news-full.json", data, {
encoding: "utf-8",
flag: "w+",
});
} else {
console.info("Creating dummy news files...");
let data = new Uint8Array(Buffer.from("[]"));
fs.writeFileSync("src/assets/news.json", data, {
encoding: "utf-8",
flag: "w+",
});
fs.writeFileSync("src/assets/news-full.json", data, {
encoding: "utf-8",
flag: "w+",
});
}
console.info("Success.");
});
});
|