Skip to content

Commit

Permalink
Merge pull request #49 from AstroDogeDX/fixed-worlds-list-endpoint-fo…
Browse files Browse the repository at this point in the history
…r-latest-api-changes

Fixed world listing endpoint for the latest API changes
  • Loading branch information
AstroDogeDX authored Oct 15, 2023
2 parents 160b4bd + 172ac3e commit e62e0f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 19 additions & 7 deletions server/api_cvr_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ const utils = require('./utils');
const log = require('./logger').GetLogger('API_HTTP');

const APIAddress = 'https://api.abinteractive.net';
const APIVersion = '1';
const APIBase = `${APIAddress}/${APIVersion}`;
const APIBase = `${APIAddress}/1`;
const APIBase2 = `${APIAddress}/2`;

let CVRApi;
let CVRApiV2;

const UnauthenticatedCVRApi = axios.create({ baseURL: APIBase });

async function Get(url, authenticated = true) {
async function Get(url, authenticated = true, apiVersion = 1) {
try {
const response = await (authenticated ? CVRApi : UnauthenticatedCVRApi).get(url);
const response = await (authenticated ? (apiVersion === 1 ? CVRApi : CVRApiV2) : UnauthenticatedCVRApi).get(url);
log.debug(`[GET] [${response.status}] [${authenticated ? '' : 'Non-'}Auth] ${url}`, response.data);
return response.data.data;
}
Expand All @@ -24,9 +25,9 @@ async function Get(url, authenticated = true) {
}


async function Post(url, data, authenticated = true) {
async function Post(url, data, authenticated = true, apiVersion = 1) {
try {
const response = await (authenticated ? CVRApi : UnauthenticatedCVRApi).post(url, data);
const response = await (authenticated ? (apiVersion === 1 ? CVRApi : CVRApiV2) : UnauthenticatedCVRApi).post(url, data);
log.debug(`[Post] [${response.status}] [${authenticated ? '' : 'Non-'}Auth] ${url}`, response.data);
return response.data;
}
Expand Down Expand Up @@ -84,6 +85,17 @@ async function Authenticate(authType, credentialUser, credentialSecret) {
'CompatibleVersions': '0,1,2',
},
});
CVRApiV2 = axios.create({
baseURL: APIBase2,
headers: {
'Username': authentication.username,
'AccessKey': authentication.accessKey,
'User-Agent': utils.GetUserAgent(),
'MatureContentDlc': 'true',
'Platform': 'pc_standalone',
'CompatibleVersions': '0,1,2',
},
});
return authentication;
}

Expand Down Expand Up @@ -118,7 +130,7 @@ exports.SetWorldCategories = async (worldId, categoryIds) => await SetAvatarCate
// Worlds
exports.GetWorldById = async (worldId) => await Get(`/worlds/${worldId}`);
exports.GetWorldMetaById = async (worldId) => await Get(`/worlds/${worldId}/meta`);
exports.GetWorldsByCategory = async (worldCategoryId) => await Get(`/worlds/list/${worldCategoryId}`);
exports.GetWorldsByCategory = async (worldCategoryId) => await Get(`/worlds/list/${worldCategoryId}?page=0&direction=0`, true, 2);
exports.GetWorldPortalById = async (worldId) => await Get(`/portals/world/${worldId}`);
exports.SetWorldAsHome = async (worldId) => await Get(`/worlds/${worldId}/sethome`);

Expand Down
8 changes: 6 additions & 2 deletions server/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ class Core {

async UpdateWorldsByCategory(categoryId) {

const worlds = await CVRHttp.GetWorldsByCategory(categoryId);
const result = await CVRHttp.GetWorldsByCategory(categoryId);
//const totalPages = result.totalPages;
const worlds = result.entries;
for (const world of worlds) {
if (world?.imageUrl) {
await LoadImage(world.imageUrl, world);
Expand All @@ -671,7 +673,9 @@ class Core {
}

async ActiveInstancesRefresh() {
const activeWorlds = await CVRHttp.GetWorldsByCategory(WorldCategories.ActiveInstances);
const activeWorldsResult = await CVRHttp.GetWorldsByCategory(WorldCategories.ActiveInstances);
const activeWorlds = activeWorldsResult.entries;
// activeWorldsTotalPages = activeWorldsResult.totalPages;
const activeInstancesDetails = {};
for (const activeWorld of activeWorlds) {
const activeWorldDetails = await CVRHttp.GetWorldById(activeWorld.id);
Expand Down

0 comments on commit e62e0f1

Please sign in to comment.