Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
froquede committed Sep 13, 2022
1 parent 76ad44e commit d28f5bd
Show file tree
Hide file tree
Showing 9 changed files with 1,454 additions and 30 deletions.
30 changes: 18 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (app_path) => {

last_maps = {};

function listMaps(filter = "mtimeMs") {
function listMaps(filter = "mtimeMs", sorting = "desc") {
return new Promise((resolve, reject) => {
glob(maps_path + "**/*", { dot: true }, async (err, files) => {
if(!err) {
Expand All @@ -19,7 +19,7 @@ module.exports = (app_path) => {
if(path.extname(file) == "") {
const stat = await fs.promises.lstat(path.resolve(maps_path, file));
let name = file.toLowerCase().split(maps_path.toLowerCase()).join("");
if(stat.isFile()) maps[name] = { file, ...stat };
if(stat.isFile()) maps[name] = { file, name, ...stat };
}
if(path.extname(file) == ".jpg" || path.extname(file) == ".png") {
let name = file.toLowerCase().split(".jpg").join("").split(".png").join("");
Expand All @@ -31,7 +31,11 @@ module.exports = (app_path) => {
}

last_maps = maps;
let result = Object.entries(maps).sort((a, b) => b[1][filter] - a[1][filter]);
let result = Object.entries(maps).sort((a, b) => {
if(b[1][filter] < a[1][filter]) return sorting == "desc" ? -1 : 1
if(b[1][filter] > a[1][filter]) return sorting == "desc" ? 1 : -1
return 0;
});
resolve(Object.fromEntries(result));
}
else reject(err);
Expand All @@ -40,11 +44,13 @@ module.exports = (app_path) => {
}

const request = require("request");
const token = "Bearer eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiUlNBLU9BRVAiLCJjdHkiOiJKV1QiLCJ6aXAiOiJERUYiLCJ4NXQiOiJzR0pJLUJhTmhlTDctUjBMejJFdlhhNlQweGsifQ.MEkyRzv6AV7YlJ4YAPESBSR5zzbOlFX94PixboHBrfnz8WZksyD8gbiE-5O1ntPcdkmLFrd87htACW37vEynXlkA8j86-wtfDqauDQoABUs9jaOv4sAAAoUSUgf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7Q8ULFJPks6yAB12fkYx3h-ZIdK5r050tCkia4QfYp3R_zWVexP-6Jqr3llI7XWytVqkAZbBAWU7Jh8FwI1J7OX525xY-hJwcZtXvvU-9bkCUV1hTJta-5dR462NrDkFN50PRQsstw9z5k9QOawMxJ2A4dgEUoB4L5s4lON3PwYNjUtLiFLf372eGQ8I3oVoyLDUpwh3OLdHnQVVYIT9BfuGt7TyDyxsteH8RfCagKf33t2Ps.ZHJZ6AvheYNqGmq0jFuk4Q";
function listModioMaps(page = 0) {
let sort = "-date_updated", offset = 20 * page, limit = 20;
const ignore = ["console_selected_xbox", "console_selected_ps4", "console_selected_switch", "console_recheck_xbox", "console_recheck_ps4", "console_recheck_switch"].join(",");
function listModioMaps(page = 0, token, filter = "date_updated", sorting = "desc", search = "") {
if(filter == "downloads" || filter == "rating") sorting = sorting == "desc" ? "asc" : "desc";
let sort = (sorting == "desc" ? "-" : "") + filter, offset = 20 * page, limit = 20;
return new Promise((resolve, reject) => {
request(`https://api.mod.io/v1/games/629/mods?tags=Map&_sort=${sort}&_offset=${offset}&_limit=${limit}`, {headers: {Authorization: token}}, (err, res, body) => {
//console.log(`https://api.mod.io/v1/games/629/mods?tags=Map&tags-not-in=${ignore}&_sort=${sort}&_offset=${offset}&_limit=${limit}&name-not-lk=*dropper*&name-lk=*${search}*`);
request(`https://api.mod.io/v1/games/629/mods?tags=Map&tags-not-in=${ignore}&_sort=${sort}&_offset=${offset}&_limit=${limit}&name-not-lk=*dropper*&name-lk=*${search}*`, {headers: {Authorization: "Bearer " + token}}, (err, res, body) => {
try {
body = JSON.parse(body);
} catch(err) {
Expand All @@ -65,8 +71,8 @@ const DecompressZip = require('decompress-zip');
let download_queue = [];
let queue_running = false;

function addToDownloadQueue(id) {
request(`https://api.mod.io/v1/games/629/mods/${id}`, {headers: {Authorization: token}}, (err, res, body) => {
function addToDownloadQueue(id, token) {
request(`https://api.mod.io/v1/games/629/mods/${id}`, {headers: {Authorization: "Bearer " + token}}, (err, res, body) => {
try {
body = JSON.parse(body);
} catch(err) {
Expand Down Expand Up @@ -173,15 +179,15 @@ const bp = require('body-parser');
app.use(bp.json())

app.get('/modio/maps', (req, res) => {
listModioMaps(req.query.page).then(maps => {
listModioMaps(req.query.page, req.query.token, req.query.filter, req.query.sorting, req.query.search).then(maps => {
res.send(maps);
}).catch(err => {
res.status(500).send(err);
})
});

app.get('/local/maps', (req, res) => {
listMaps().then(maps => {
listMaps(req.query.filter, req.query.sorting).then(maps => {
res.send(maps);
}).catch(err => {
res.status(500).send(err);
Expand All @@ -205,7 +211,7 @@ app.get('/internal/open', (req, res) => {

app.post('/modio/download', (req, res) => {
if(req.body.id) {
addToDownloadQueue(req.body.id);
addToDownloadQueue(req.body.id, req.body.token);
res.status(200).send();
}
else {
Expand Down
6 changes: 6 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ function createWindow () {
webPreferences: {},
icon: nativeImage.createFromPath(path.resolve(app_path, './webapp/MapHubIcon.ico'))
});
mainWindow.webContents.setFrameRate(60);
mainWindow.resizable = false;
mainWindow.loadURL('http://localhost:420')
mainWindow.setMenuBarVisibility(false);

// mainWindow.webContents.on('new-window', (e, url) => {
// e.preventDefault();
// require('electron').shell.openExternal(url);
// });
}

let icon;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
},
"config": {
"forge": {
"packagerConfig": {},
"packagerConfig": {
"icon": "./webapp/MapHubIcon.ico"
},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
Expand Down
Loading

0 comments on commit d28f5bd

Please sign in to comment.