epicwar
Version:
Epicwar.com maps download
39 lines (38 loc) • 1.31 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.epicwarGetMap = void 0;
const axios_1 = __importDefault(require("axios"));
const jsdom_1 = require("jsdom");
const utils_1 = require("./utils");
const epicwar_enum_1 = require("../epicwar.enum");
async function epicwarGetMap(mapId, download) {
const content = (await axios_1.default({
method: 'GET',
url: `${epicwar_enum_1.EpicwarEnum.BASE_URL}/maps/${mapId}`
})).data;
const dom = new jsdom_1.JSDOM(content);
const cells = dom.window.document.getElementsByClassName('listentry');
const id = utils_1.getMapID(cells);
const name = utils_1.getMapName(cells);
const url = utils_1.getMapUrl(cells);
const description = utils_1.getMapDescription(cells);
const details = utils_1.getMapDetails(cells);
const image = utils_1.getMapImage(cells);
if (!id) {
throw new Error('Map not found');
}
const file = download ? await utils_1.getFile(url) : undefined;
return {
id,
name,
url,
description,
details,
image,
file
};
}
exports.epicwarGetMap = epicwarGetMap;