shiro.gg
Version:
An api wrapper for shiro.gg
70 lines (69 loc) • 2.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetImage = void 0;
//Modules
const axios_1 = __importDefault(require("axios"));
//The base url
const BaseURL = 'https://api.dbot.dev/';
/**
* gets image from the api
* @parameter {__endpoint} string: The endpoint of the api
*
* @example
* SFW
* ```js
* GetImage('pat').then(console.log)
* //Or,
* GetImage('pat', { nsfw: false }).then(console.log)
* ```
* NSFW
* ```js
* GetImage('hentai', { nsfw: true }).then(console.log)
* ```
*
* @private
*/
const GetImage = async (__endpoint, __options) => {
return new Promise((resolve, reject) => {
if (!__endpoint.length) {
//In case empty string is provided
const __argErr = new Error('Invalid arguments provided for Api Endpoints');
__argErr.name = 'ArgumentError';
reject(__argErr);
}
if (!__options) {
// If no options is provided we'll think it's sfw request
__options = {
nsfw: false
};
}
let _requestURL;
if (__options.nsfw) {
_requestURL = `${BaseURL}images/nsfw/${__endpoint}`;
}
else {
_requestURL = `${BaseURL}images/${__endpoint}`;
}
/**
* URL endpoint format:
* SFW: https://shiro.gg/api/images/:enpoint
* NSFW: https://shiro.gg/api/images/nsfw/:endpoint
*/
axios_1.default.get(_requestURL).then((_res) => {
// If okay / success
if (_res.data.code == 200) {
const result = {
url: _res.data.url,
type: _res.data.fileType
};
resolve(result);
}
}).catch((_err) => {
reject(_err);
});
});
};
exports.GetImage = GetImage;