osu-api-extended
Version:
Advanced osu! api wrapper cover all V2 and V1 endpoints, and provide useful tools
94 lines (93 loc) • 4.33 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.build_url = exports.calculate_pp = exports.calculate_net_pp = exports.calculate_hits = exports.calculate_total_passed_objects = exports.calculate_rank = exports.country_details = exports.calculate_mods = exports.calculate_accuracy = exports.download_beatmaps = void 0;
const handleErrors_1 = require("../utility/handleErrors");
var beatmaps_download_1 = require("../api/v2/beatmaps_download");
Object.defineProperty(exports, "download_beatmaps", { enumerable: true, get: function () { return beatmaps_download_1.beatmaps_download; } });
var accuracy_1 = require("./accuracy");
Object.defineProperty(exports, "calculate_accuracy", { enumerable: true, get: function () { return accuracy_1.calculate_accuracy; } });
var mods_1 = require("./mods");
Object.defineProperty(exports, "calculate_mods", { enumerable: true, get: function () { return mods_1.calculate_mods; } });
var country_1 = require("./country");
Object.defineProperty(exports, "country_details", { enumerable: true, get: function () { return country_1.country_details; } });
var rank_1 = require("./rank");
Object.defineProperty(exports, "calculate_rank", { enumerable: true, get: function () { return rank_1.calculate_rank; } });
var objects_1 = require("./objects");
Object.defineProperty(exports, "calculate_total_passed_objects", { enumerable: true, get: function () { return objects_1.calculate_total_passed_objects; } });
Object.defineProperty(exports, "calculate_hits", { enumerable: true, get: function () { return objects_1.calculate_hits; } });
var net_pp_1 = require("./net-pp");
Object.defineProperty(exports, "calculate_net_pp", { enumerable: true, get: function () { return net_pp_1.calculate_net_pp; } });
const calculate_pp = () => {
return (0, handleErrors_1.handleErrors)(new Error('Use rosu-pp-js instead'));
};
exports.calculate_pp = calculate_pp;
/**
* Builder that returns a link an 'user', a score, a beatmap, etc.
*
*
*
* ### Parameters
* - `params._direct?` - Return osu direct link for type `beatmap` and `beatmapset`
* - `params.mode?` - Return legacy link for type `score`
* - `params.type` - Type of the link
* - `params.value` - Link url value, for example `beatmap id` or `user id`
*
*
*
* ### Usage Example
* ```js
* const { tools } = require('osu-api-extended');
*
* function main() {
* try {
* const result = tools.build_url({ type: 'beatmap', value: 4397592 });
*
* console.log(result);
* } catch (error) {
* console.log(error);
* };
* };
*
* main();
* ```
*/
const build_url = (params) => {
const { _direct, type, mode, value } = params || {};
switch (type) {
case 'beatmap':
return _direct == true ? `osu://b/${value}` : `https://osu.ppy.sh/b/${value}`;
case 'beatmapset':
return _direct == true ? `osu://s/${value}` : `https://osu.ppy.sh/s/${value}`;
case 'news':
return `https://osu.ppy.sh/home/news/${value}`;
case 'editor_timing':
return `osu://edit/${value}`;
case 'match':
return `https://osu.ppy.sh/community/matches/${value}`;
case 'avatar':
return `https://a.ppy.sh/${value}`;
case 'user':
return `https://osu.ppy.sh/users/${value}`;
case 'badge':
return `https://assets.ppy.sh/profile-badges/${value}`;
case 'score':
return `https://osu.ppy.sh/scores/${mode ? "/" + mode : ''}${value}`;
default:
return `Unsupported type: ${params === null || params === void 0 ? void 0 : params.type}`;
}
;
};
exports.build_url = build_url;
// const postDataArray = (field_name: string, array: any[]) => {
// const data = array.map((data, index) => {
// return postDataObject(`${field_name}[${index}]`, data);
// }).join('&');
// return data;
// };
// const postDataObject = (field_name: string, object: object) => {
// return Object.entries(object).map(([key, value]) => {
// if (field_name == '')
// return `${key}=${encodeURIComponent(value as any)}`;
// return `${field_name}[${key}]=${encodeURIComponent(value as any)}`;
// }).join('&');
// };
;