Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/AstroDogeDX/CVRX
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroDogeDX committed Oct 15, 2023
2 parents 3dd68ef + e62e0f1 commit e13d8aa
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 200 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"comma-dangle": ["error", "always-multiline"],
"dot-notation": "error",
"eqeqeq": "error",
"no-alert": "error"
"no-alert": "error",
"indent": ["error", 4, { "SwitchCase": 1 }]
}
}
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
36 changes: 18 additions & 18 deletions server/api_cvr_ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ const MAP_WORLD = Object.freeze({
});

const MAP_INVITE = Object.freeze({
'Id': 'id',
'User': {
root: 'user',
mapping: MAP_USER,
},
'World': {
root: 'world',
mapping: MAP_WORLD,
},
'InstanceId': 'instanceId',
'InstanceName': 'instanceName',
'ReceiverId': 'receiverId',
'Id': 'id',
'User': {
root: 'user',
mapping: MAP_USER,
},
'World': {
root: 'world',
mapping: MAP_WORLD,
},
'InstanceId': 'instanceId',
'InstanceName': 'instanceName',
'ReceiverId': 'receiverId',
});

const MAP_REQUEST_INVITE = Object.freeze({
'Id': 'id',
'Sender': {
root: 'sender',
mapping: MAP_USER,
},
'ReceiverId': 'receiverId',
'Id': 'id',
'Sender': {
root: 'sender',
mapping: MAP_USER,
},
'ReceiverId': 'receiverId',
});


Expand Down
43 changes: 41 additions & 2 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const CVRExecutableName = 'ChilloutVR.exe';
const CVRDataFolderName = 'ChilloutVR_Data';

const FileType = Object.freeze({
CONFIG: 'CONFIG',
CREDENTIALS: 'CREDENTIALS',
CONFIG: 'CONFIG',
CREDENTIALS: 'CREDENTIALS',
});


Expand Down Expand Up @@ -59,6 +59,7 @@ exports.Load = async () => {
ActiveUsername: null,
ActiveUserID: null,
CacheMaxSizeInMegabytes: 1000,
CloseToSystemTray: false,
CVRExecutable: path.join(CVRExecutableDefaultFolderPath, CVRExecutableName),
UpdaterIgnoreVersion: null,
};
Expand Down Expand Up @@ -240,8 +241,46 @@ exports.ClearCredentials = async (username) => {
await UpdateJsonFile(FileType.CREDENTIALS);
};

exports.UpdateConfig = async (newConfigSettings) => {

log.info('[UpdateConfig] Attempting to update the config', newConfigSettings);

if (Object.prototype.hasOwnProperty.call(newConfigSettings, 'CacheMaxSizeInMegabytes')) {
const cacheSize = newConfigSettings.CacheMaxSizeInMegabytes;

if (!Number.isInteger(cacheSize) || cacheSize < 500 || cacheSize > 2000) {
throw new Error('[UpdateConfig] CacheMaxSizeInMegabytes should be an integer between 500 and 2000.');
}

config.CacheMaxSizeInMegabytes = cacheSize;
}

if (Object.prototype.hasOwnProperty.call(newConfigSettings, 'CloseToSystemTray')) {
const closeToTray = newConfigSettings.CloseToSystemTray;

if (typeof closeToTray !== 'boolean') {
throw new Error('[UpdateConfig] CloseToSystemTray should be a boolean value.');
}

config.CloseToSystemTray = closeToTray;
}

await UpdateJsonFile(FileType.CONFIG);

return exports.GetConfig();
};


exports.GetConfig = () => ({
CacheMaxSizeInMegabytes: config.CacheMaxSizeInMegabytes,
CloseToSystemTray: config.CloseToSystemTray,
});


exports.GetMaxCacheSize = () => config.CacheMaxSizeInMegabytes;

exports.GetCloseToSystemTray = () => config.CloseToSystemTray;

exports.GetUpdaterIgnoreVersion = () => config.UpdaterIgnoreVersion;
exports.SetUpdaterIgnoreVersion = async (versionToIgnore) => {
config.UpdaterIgnoreVersion = versionToIgnore;
Expand Down
32 changes: 20 additions & 12 deletions server/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class Core {
ipcMain.handle('block-user', (_event, userId) => CVRWebsocket.BlockUser(userId));
ipcMain.handle('unblock-user', (_event, userId) => CVRWebsocket.UnblockUser(userId));

// Config
ipcMain.handle('config-get', () => Config.GetConfig());
ipcMain.handle('config-update', (_event, newConfigSettings) => Config.UpdateConfig(newConfigSettings));

// Socket Events
CVRWebsocket.EventEmitter.on(CVRWebsocket.SocketEvents.CONNECTED, () => this.recentActivityInitialFriends = true);
CVRWebsocket.EventEmitter.on(CVRWebsocket.SocketEvents.DEAD, () => this.SendToRenderer('socket-died'));
Expand Down Expand Up @@ -329,16 +333,16 @@ class Core {
await Config.ClearActiveCredentials();
this.app.quit();
}
// const authentication = {
// username: 'XXXXXXXXX',
// accessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
// userId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentAvatar: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentHomeWorld: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// videoUrlResolverExecutable: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe',
// videoUrlResolverHashes: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/SHA2-256SUMS',
// blockedUsers: [],
// }
// const authentication = {
// username: 'XXXXXXXXX',
// accessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
// userId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentAvatar: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentHomeWorld: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// videoUrlResolverExecutable: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe',
// videoUrlResolverHashes: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/SHA2-256SUMS',
// blockedUsers: [],
// }
}

async SendToLoginPage() {
Expand Down Expand Up @@ -646,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 @@ -667,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
Loading

0 comments on commit e13d8aa

Please sign in to comment.