educational variant
This commit is contained in:
37
index.js
37
index.js
@ -17,9 +17,22 @@ import { getRawData, generateAccountPage, editProfile, saveData, getUsers, isAdm
|
||||
import { callAI } from "./ai.js";
|
||||
import { Readable } from 'stream';
|
||||
import os from "node:os";
|
||||
import chokidar from 'chokidar';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
let recatters = JSON.parse(await fs.readFile("./data/recats.json"));
|
||||
const watcher = chokidar.watch('./data/recats.json', {
|
||||
persistent: true,
|
||||
awaitWriteFinish: {
|
||||
stabilityThreshold: 500,
|
||||
pollInterval: 100
|
||||
}
|
||||
});
|
||||
watcher.on('change', async (event, filePath) => {
|
||||
recatters = JSON.parse(await fs.readFile("./data/recats.json"));
|
||||
});
|
||||
|
||||
await findClientID();
|
||||
setInterval(async () => {
|
||||
await findClientID();
|
||||
@ -28,6 +41,15 @@ setInterval(async () => {
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
const app = express();
|
||||
|
||||
let recatFolder = express.static("./edu", { extensions: ["html"] });
|
||||
app.use((req, res, next) => {
|
||||
if(recatters.includes(req.hostname)) {
|
||||
return recatFolder(req, res, next);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
// why the fuck does this have to exist?
|
||||
app.use("/resources/semag/hotline-miami/", (req,res,next) => {
|
||||
if(req.method == "HEAD") {
|
||||
@ -186,6 +208,21 @@ app.use("/api/music/download", async (req, res, next) => {
|
||||
}
|
||||
res.end();
|
||||
});
|
||||
app.post("/api/recat", async (req, res) => {
|
||||
if(isAdmin(req.cookies.token)) {
|
||||
let domain = JSON.parse(req.body)["domain"];
|
||||
let message;
|
||||
if(recatters.includes(domain)) {
|
||||
recatters.pop(domain);
|
||||
message = `Successfully set ${domain} to Selenite.`
|
||||
} else {
|
||||
recatters.push(domain);
|
||||
message = `Successfully set ${domain} as educational.`
|
||||
}
|
||||
fs.writeFile("./data/recats.json", JSON.stringify(recatters));
|
||||
res.send(message);
|
||||
};
|
||||
})
|
||||
|
||||
// friends endpoints
|
||||
app.get("/api/friends/list", async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user