Files
OpenParty/core/helper.js
ibratabian17 ea941aaaad initial
2024-06-15 19:57:02 +08:00

36 lines
1.0 KiB
JavaScript

//JDPARTY CLONE OBJECT
const fs = require('fs');
const axios = require('axios');
const downloader = {
};
function CloneObject(ObjectC) {
return JSON.parse(JSON.stringify(ObjectC))
}
function readDatabaseJson(path) {
return JSON.parse(fs.readFileSync(`${__dirname}/../database/${path}`, 'utf8'));
}
downloader.getJson = async (url, options) => {
const response = await axios.get(url, options);
return response.data;
}
function extractSkuIdInfo(url) {
// Split the URL by '/'
const parts = url.split('/');
// Get the last part of the URL
const lastPart = parts[parts.length - 1];
// Remove the file extension (.json)
const filename = lastPart.split('.')[0];
const filenameParts = filename.split('-');
let version = filenameParts[0];
version = version.slice(2);
const platform = filenameParts[1];
const type = filenameParts.slice(2).join('-')
return { version, platform, type };
}
module.exports = {
CloneObject, readDatabaseJson, downloader, extractSkuIdInfo
}