import { main, rankCalc } from "./site.js"; import e from "express"; let { site = 'darflen', route = './test.txt', pageLimit = 0.1, blackList = '', greyList = '', discardThreshold = 1, delay = 100, depth = 1, isRelative = false, fetchRate = 15, user = 'paradock', matrixIterations = 3, useArchive = true, isGpu = false, mode = 'cli', port = 6952, arrayMax = 800 } = process.env; let settings = { site, route, pageLimit, blackList, greyList, discardThreshold, delay, depth, isRelative, fetchRate, user, matrixIterations, useArchive, isGpu, arrayMax }; if (mode == 'cli') { main(settings); } else if (mode == 'site') { const app = e(); app.get('/top', async (req, res) => { let json = await fetch("https://nbg.dervland.net/api/followjson.php"); json = await json.json(); let { ref } = req.query; let data = {}; for (let entryI in json) { let entry = json[entryI]; let user = data[entry.username] || {}; let target = data[entry.target] || {}; let f1 = user.following = user.following || []; let f2 = user.followers = user.followers || []; let f3 = target.following = target.following || []; let f4 = target.followers = target.followers || []; f3.push(entry.username); f2.push(entry.target); data[entry.username] = user; data[entry.target] = target; } let calcedRank = rankCalc(data, matrixIterations, ref ? [ref] : [], false, settings.isGpu, settings.arrayMax); let dat = Object.entries(calcedRank); dat = dat.sort((a, b) => b[1] - a[1]); console.log(`Graph is calculated with ${dat.length} entries`); let dat2 = {}; for (let d of dat) { dat2[d[0]] = d[1] * 100 + "%"; } res.send(JSON.stringify(dat2)) }) app.listen(port); console.log(`App listening on port ${port}`) }