mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 22:33:50 +02:00
use internal http request
This commit is contained in:
122
html/src/app.js
122
html/src/app.js
@@ -13,12 +13,13 @@ import locale from 'element-ui/lib/locale/lang/en';
|
||||
|
||||
import sharedRepository from './repository/shared.js';
|
||||
import configRepository from './repository/config.js';
|
||||
|
||||
window.sharedRepository = sharedRepository;
|
||||
window.configRepository = configRepository;
|
||||
import webApiService from './service/webapi.js';
|
||||
|
||||
(async function () {
|
||||
await CefSharp.BindObjectAsync(
|
||||
'WebApi',
|
||||
'VRCX',
|
||||
'SharedVariable', // DO NOT DIRECT ACCESS
|
||||
'VRCXStorage',
|
||||
@@ -330,30 +331,25 @@ window.configRepository = configRepository;
|
||||
API.pendingGetRequests = new Map();
|
||||
|
||||
API.call = function (endpoint, options) {
|
||||
var resource = `https://api.vrchat.cloud/api/1/${endpoint}`;
|
||||
var init = {
|
||||
url: `https://api.vrchat.cloud/api/1/${endpoint}`,
|
||||
method: 'GET',
|
||||
mode: 'cors',
|
||||
credentials: 'include',
|
||||
cache: 'no-cache',
|
||||
redirect: 'follow',
|
||||
referrerPolicy: 'no-referrer',
|
||||
...options
|
||||
};
|
||||
var { params } = init;
|
||||
var isGetRequest = init.method === 'GET';
|
||||
if (isGetRequest) {
|
||||
if (isGetRequest === true) {
|
||||
// transform body to url
|
||||
if (params === Object(params)) {
|
||||
var url = new URL(resource);
|
||||
var url = new URL(init.url);
|
||||
var { searchParams } = url;
|
||||
for (var key in params) {
|
||||
searchParams.set(key, params[key]);
|
||||
}
|
||||
resource = url.toString();
|
||||
init.url = url.toString();
|
||||
}
|
||||
// merge requests
|
||||
var req = this.pendingGetRequests.get(resource);
|
||||
var req = this.pendingGetRequests.get(init.url);
|
||||
if (req !== undefined) {
|
||||
return req;
|
||||
}
|
||||
@@ -366,45 +362,50 @@ window.configRepository = configRepository;
|
||||
? JSON.stringify(params)
|
||||
: '{}';
|
||||
}
|
||||
var req = fetch(resource, init).catch((err) => {
|
||||
var req = webApiService.execute(init).catch((err) => {
|
||||
this.$throw(0, err);
|
||||
}).then((res) => res.json().catch(() => {
|
||||
if (res.ok) {
|
||||
}).then((response) => {
|
||||
try {
|
||||
response.data = JSON.parse(response.data);
|
||||
return response;
|
||||
} catch (e) {
|
||||
}
|
||||
if (response.status === 200) {
|
||||
this.$throw(0, 'Invalid JSON response');
|
||||
}
|
||||
this.$throw(res.status);
|
||||
}).then((json) => {
|
||||
if (res.ok) {
|
||||
if (json.success === Object(json.success)) {
|
||||
new Noty({
|
||||
type: 'success',
|
||||
text: escapeTag(json.success.message)
|
||||
}).show();
|
||||
}).then(({ data, status }) => {
|
||||
if (data === Object(data)) {
|
||||
if (status === 200) {
|
||||
if (data.success === Object(data.success)) {
|
||||
new Noty({
|
||||
type: 'success',
|
||||
text: escapeTag(data.success.message)
|
||||
}).show();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
if (json === Object(json)) {
|
||||
if (json.error === Object(json.error)) {
|
||||
if (data.error === Object(data.error)) {
|
||||
this.$throw(
|
||||
json.error.status_code || res.status,
|
||||
json.error.message,
|
||||
json.error.data
|
||||
data.error.status_code || status,
|
||||
data.error.message,
|
||||
data.error.data
|
||||
);
|
||||
} else if (typeof json.error === 'string') {
|
||||
} else if (typeof data.error === 'string') {
|
||||
this.$throw(
|
||||
json.status_code || res.status,
|
||||
json.error
|
||||
data.status_code || status,
|
||||
data.error
|
||||
);
|
||||
}
|
||||
}
|
||||
this.$throw(res.status, json);
|
||||
return json;
|
||||
}));
|
||||
if (isGetRequest) {
|
||||
this.$throw(status, data);
|
||||
return data;
|
||||
});
|
||||
if (isGetRequest === true) {
|
||||
req.finally(() => {
|
||||
this.pendingGetRequests.delete(resource);
|
||||
this.pendingGetRequests.delete(init.url);
|
||||
});
|
||||
this.pendingGetRequests.set(resource, req);
|
||||
this.pendingGetRequests.set(init.url, req);
|
||||
}
|
||||
return req;
|
||||
};
|
||||
@@ -817,7 +818,7 @@ window.configRepository = configRepository;
|
||||
API.currentUser = {};
|
||||
|
||||
API.$on('LOGOUT', function () {
|
||||
VRCX.DeleteAllCookies();
|
||||
webApiService.clearCookies();
|
||||
this.isLoggedIn = false;
|
||||
});
|
||||
|
||||
@@ -3341,28 +3342,33 @@ window.configRepository = configRepository;
|
||||
return style;
|
||||
};
|
||||
|
||||
$app.methods.checkAppVersion = function () {
|
||||
var url = 'https://api.github.com/repos/pypy-vrc/VRCX/releases/latest';
|
||||
fetch(url).then((res) => res.json()).then((json) => {
|
||||
if (json === Object(json) &&
|
||||
json.name &&
|
||||
json.published_at) {
|
||||
this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`;
|
||||
if (json.name > this.appVersion) {
|
||||
new Noty({
|
||||
type: 'info',
|
||||
text: `Update available!!<br>${this.latestAppVersion}`,
|
||||
timeout: 60000,
|
||||
callbacks: {
|
||||
onClick: () => VRCX.OpenLink('https://github.com/pypy-vrc/VRCX/releases')
|
||||
}
|
||||
}).show();
|
||||
this.notifyMenu('more');
|
||||
}
|
||||
} else {
|
||||
this.latestAppVersion = 'Error occured';
|
||||
$app.methods.checkAppVersion = async function () {
|
||||
var response = await webApiService.execute({
|
||||
url: 'https://api.github.com/repos/pypy-vrc/VRCX/releases/latest',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'User-Agent': 'VRCX'
|
||||
}
|
||||
});
|
||||
var json = JSON.parse(response.data);
|
||||
if (json === Object(json) &&
|
||||
json.name &&
|
||||
json.published_at) {
|
||||
this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`;
|
||||
if (json.name > this.appVersion) {
|
||||
new Noty({
|
||||
type: 'info',
|
||||
text: `Update available!!<br>${this.latestAppVersion}`,
|
||||
timeout: 60000,
|
||||
callbacks: {
|
||||
onClick: () => VRCX.OpenLink('https://github.com/pypy-vrc/VRCX/releases')
|
||||
}
|
||||
}).show();
|
||||
this.notifyMenu('more');
|
||||
}
|
||||
} else {
|
||||
this.latestAppVersion = 'Error occured';
|
||||
}
|
||||
};
|
||||
|
||||
$app.methods.updateLoop = function () {
|
||||
|
||||
Reference in New Issue
Block a user