rblx.js
Version:
A JavaScript wrapper for interacting with the ROBLOX OpenCloud API.
69 lines (68 loc) • 2.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const urlcat_1 = __importDefault(require("urlcat"));
const axios_1 = __importDefault(require("axios"));
const BASE_URL = "https://apis.roblox.com/datastores/v1/universes";
async function main(apiKey, universeid, prefix, limit, cursor) {
try {
BigInt(universeid);
Number(limit);
}
catch (e) {
throw new Error("Invalid universeid: " + universeid);
}
if (universeid) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores", { universeid });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.get(res_url, config); // .catch(err => { throw((err.message).toString().substring(11)) })
return await response.data;
}
if (prefix) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores?prefix=:prefix", { universeid, prefix });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.get(res_url, config);
return await response.data;
}
if (limit) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores?limit=:limit", { universeid, limit });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.get(res_url, config).catch(err => { throw (err.substr(11)); });
return await response.data;
}
if (cursor) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores?cursor=:cursor", { universeid, cursor });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.get(res_url, config);
return await response.data;
}
if (prefix && limit && cursor) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores?prefix=:prefix&limit=:limit&cursor=:cursor", { universeid, prefix, limit, cursor });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.get(res_url, config);
return await response.data;
}
}
exports.default = main;