$app.toggleCustomEndpoint()

This commit is contained in:
Natsumi
2022-02-12 19:26:37 +13:00
parent efa2597b6e
commit 1b135e1f15
2 changed files with 66 additions and 33 deletions
+62 -32
View File
@@ -362,10 +362,12 @@ speechSynthesis.getVoices();
API.pendingGetRequests = new Map(); API.pendingGetRequests = new Map();
API.failedGetRequests = new Map(); API.failedGetRequests = new Map();
API.endpointDomainVrchat = 'https://api.vrchat.cloud/api/1';
API.endpointDomain = 'https://api.vrchat.cloud/api/1';
API.call = function (endpoint, options) { API.call = function (endpoint, options) {
var init = { var init = {
url: `https://api.vrchat.cloud/api/1/${endpoint}`, url: `${API.endpointDomain}/${endpoint}`,
method: 'GET', method: 'GET',
...options ...options
}; };
@@ -998,10 +1000,6 @@ speechSynthesis.getVoices();
API.cachedUsers = new Map(); API.cachedUsers = new Map();
API.currentUser = {}; API.currentUser = {};
API.$on('LOGOUT', function () {
this.isLoggedIn = false;
});
API.$on('USER:CURRENT', function (args) { API.$on('USER:CURRENT', function (args) {
var {json} = args; var {json} = args;
args.ref = this.applyCurrentUser(json); args.ref = this.applyCurrentUser(json);
@@ -1965,11 +1963,16 @@ speechSynthesis.getVoices();
API.refreshFriends = async function () { API.refreshFriends = async function () {
this.isRefreshFriendsLoading = true; this.isRefreshFriendsLoading = true;
var onlineFriends = await this.refreshOnlineFriends(); try {
var offlineFriends = await this.refreshOfflineFriends(); var onlineFriends = await this.refreshOnlineFriends();
var friends = onlineFriends.concat(offlineFriends); var offlineFriends = await this.refreshOfflineFriends();
this.isRefreshFriendsLoading = false; var friends = onlineFriends.concat(offlineFriends);
return friends; this.isRefreshFriendsLoading = false;
return friends;
} catch (err) {
this.isRefreshFriendsLoading = false;
throw err;
}
}; };
API.refreshOnlineFriends = async function () { API.refreshOnlineFriends = async function () {
@@ -4146,6 +4149,7 @@ speechSynthesis.getVoices();
if (--this.nextFriendsRefresh <= 0) { if (--this.nextFriendsRefresh <= 0) {
this.nextFriendsRefresh = 7200; // 1hour this.nextFriendsRefresh = 7200; // 1hour
API.refreshFriends(); API.refreshFriends();
this.updateStoredUser(API.currentUser);
if (this.isGameRunning) { if (this.isGameRunning) {
API.refreshPlayerModerations(); API.refreshPlayerModerations();
} }
@@ -5798,12 +5802,15 @@ speechSynthesis.getVoices();
}); });
API.$on('LOGOUT', function () { API.$on('LOGOUT', function () {
new Noty({ if (this.isLoggedIn) {
type: 'success', new Noty({
text: `See you again, <strong>${escapeTag( type: 'success',
this.currentUser.displayName text: `See you again, <strong>${escapeTag(
)}</strong>!` this.currentUser.displayName
}).show(); )}</strong>!`
}).show();
}
this.isLoggedIn = false;
}); });
API.$on('LOGIN', function (args) { API.$on('LOGIN', function (args) {
@@ -5816,10 +5823,6 @@ speechSynthesis.getVoices();
$app.$refs.menu.activeIndex = 'feed'; $app.$refs.menu.activeIndex = 'feed';
}); });
API.$on('LOGIN', function (args) {
$app.updateStoredUser(args.ref);
});
API.$on('LOGOUT', function () { API.$on('LOGOUT', function () {
$app.updateStoredUser(this.currentUser); $app.updateStoredUser(this.currentUser);
webApiService.clearCookies(); webApiService.clearCookies();
@@ -5849,8 +5852,7 @@ speechSynthesis.getVoices();
}; };
$app.data.enablePrimaryPassword = configRepository.getBool( $app.data.enablePrimaryPassword = configRepository.getBool(
'enablePrimaryPassword', 'enablePrimaryPassword'
false
); );
$app.data.enablePrimaryPasswordDialog = { $app.data.enablePrimaryPasswordDialog = {
visible: false, visible: false,
@@ -5969,6 +5971,11 @@ speechSynthesis.getVoices();
if (user.cookies) { if (user.cookies) {
webApiService.setCookies(user.cookies); webApiService.setCookies(user.cookies);
} }
if (loginParmas.endpoint) {
API.endpointDomain = loginParmas.endpoint;
} else {
API.endpointDomain = API.endpointDomainVrchat;
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.enablePrimaryPassword) { if (this.enablePrimaryPassword) {
API.logout(); API.logout();
@@ -5981,7 +5988,8 @@ speechSynthesis.getVoices();
.then(() => { .then(() => {
API.login({ API.login({
username: loginParmas.username, username: loginParmas.username,
password: loginParmas.password password: loginParmas.password,
endpoint: loginParmas.endpoint
}) })
.catch(() => { .catch(() => {
this.loginForm.loading = false; this.loginForm.loading = false;
@@ -6031,6 +6039,7 @@ speechSynthesis.getVoices();
loading: true, loading: true,
username: '', username: '',
password: '', password: '',
endpoint: '',
saveCredentials: false, saveCredentials: false,
savedCredentials: savedCredentials:
configRepository.getString('lastUserLoggedIn') !== null configRepository.getString('lastUserLoggedIn') !== null
@@ -6057,6 +6066,11 @@ speechSynthesis.getVoices();
this.$refs.loginForm.validate((valid) => { this.$refs.loginForm.validate((valid) => {
if (valid && !this.loginForm.loading) { if (valid && !this.loginForm.loading) {
this.loginForm.loading = true; this.loginForm.loading = true;
if (this.loginForm.endpoint) {
API.endpointDomain = this.loginForm.endpoint;
} else {
API.endpointDomain = API.endpointDomainVrchat;
}
API.getConfig() API.getConfig()
.catch((err) => { .catch((err) => {
this.loginForm.loading = false; this.loginForm.loading = false;
@@ -6101,6 +6115,9 @@ speechSynthesis.getVoices();
password: password:
this.loginForm this.loginForm
.password, .password,
endpoint:
this.loginForm
.endpoint,
saveCredentials: saveCredentials:
this.loginForm this.loginForm
.saveCredentials, .saveCredentials,
@@ -6110,6 +6127,8 @@ speechSynthesis.getVoices();
''; '';
this.loginForm.password = this.loginForm.password =
''; '';
this.loginForm.endpoint =
'';
}); });
}); });
}); });
@@ -6122,6 +6141,7 @@ speechSynthesis.getVoices();
API.login({ API.login({
username: this.loginForm.username, username: this.loginForm.username,
password: this.loginForm.password, password: this.loginForm.password,
endpoint: this.loginForm.endpoint,
saveCredentials: this.loginForm.saveCredentials saveCredentials: this.loginForm.saveCredentials
}).finally(() => { }).finally(() => {
this.loginForm.username = ''; this.loginForm.username = '';
@@ -7349,8 +7369,7 @@ speechSynthesis.getVoices();
} }
}; };
$app.data.robotUrl = $app.data.robotUrl = `${API.endpointDomain}/file/file_0e8c4e32-7444-44ea-ade4-313c010d4bae/1/file`;
'https://api.vrchat.cloud/api/1/file/file_0e8c4e32-7444-44ea-ade4-313c010d4bae/1/file';
API.$on('USER:UPDATE', async function (args) { API.$on('USER:UPDATE', async function (args) {
var {ref, props} = args; var {ref, props} = args;
@@ -15040,7 +15059,7 @@ speechSynthesis.getVoices();
} }
var userIcon = ''; var userIcon = '';
if (fileId) { if (fileId) {
userIcon = `https://api.vrchat.cloud/api/1/file/${fileId}/1`; userIcon = `${API.endpointDomain}/file/${fileId}/1`;
} }
if (userIcon === API.currentUser.userIcon) { if (userIcon === API.currentUser.userIcon) {
return; return;
@@ -16396,7 +16415,7 @@ speechSynthesis.getVoices();
var {fileId, fileVersion} = args.params; var {fileId, fileVersion} = args.params;
var parmas = { var parmas = {
id: $app.avatarImage.avatarId, id: $app.avatarImage.avatarId,
imageUrl: `https://api.vrchat.cloud/api/1/file/${fileId}/${fileVersion}/file` imageUrl: `${API.endpointDomain}/file/${fileId}/${fileVersion}/file`
}; };
this.setAvatarImage(parmas); this.setAvatarImage(parmas);
}); });
@@ -16730,7 +16749,7 @@ speechSynthesis.getVoices();
var {fileId, fileVersion} = args.params; var {fileId, fileVersion} = args.params;
var parmas = { var parmas = {
id: $app.worldImage.worldId, id: $app.worldImage.worldId,
imageUrl: `https://api.vrchat.cloud/api/1/file/${fileId}/${fileVersion}/file` imageUrl: `${API.endpointDomain}/file/${fileId}/${fileVersion}/file`
}; };
this.setWorldImage(parmas); this.setWorldImage(parmas);
}); });
@@ -16953,7 +16972,7 @@ speechSynthesis.getVoices();
this.changeAvatarImageDialogLoading = true; this.changeAvatarImageDialogLoading = true;
var parmas = { var parmas = {
id: this.avatarDialog.id, id: this.avatarDialog.id,
imageUrl: `https://api.vrchat.cloud/api/1/file/${this.previousImagesTableFileId}/${image.version}/file` imageUrl: `${API.endpointDomain}/file/${this.previousImagesTableFileId}/${image.version}/file`
}; };
API.setAvatarImage(parmas).finally(() => { API.setAvatarImage(parmas).finally(() => {
this.changeAvatarImageDialogLoading = false; this.changeAvatarImageDialogLoading = false;
@@ -16991,7 +17010,7 @@ speechSynthesis.getVoices();
this.changeWorldImageDialogLoading = true; this.changeWorldImageDialogLoading = true;
var parmas = { var parmas = {
id: this.worldDialog.id, id: this.worldDialog.id,
imageUrl: `https://api.vrchat.cloud/api/1/file/${this.previousImagesTableFileId}/${image.version}/file` imageUrl: `${API.endpointDomain}/file/${this.previousImagesTableFileId}/${image.version}/file`
}; };
API.setWorldImage(parmas).finally(() => { API.setWorldImage(parmas).finally(() => {
this.changeWorldImageDialogLoading = false; this.changeWorldImageDialogLoading = false;
@@ -17027,7 +17046,7 @@ speechSynthesis.getVoices();
$app.methods.compareCurrentImage = function (image) { $app.methods.compareCurrentImage = function (image) {
if ( if (
`https://api.vrchat.cloud/api/1/file/${this.previousImagesTableFileId}/${image.version}/file` === `${API.endpointDomain}/file/${this.previousImagesTableFileId}/${image.version}/file` ===
this.avatarDialog.ref.imageUrl this.avatarDialog.ref.imageUrl
) { ) {
return true; return true;
@@ -18204,7 +18223,7 @@ speechSynthesis.getVoices();
} }
var profilePicOverride = ''; var profilePicOverride = '';
if (fileId) { if (fileId) {
profilePicOverride = `https://api.vrchat.cloud/api/1/file/${fileId}/1`; profilePicOverride = `${API.endpointDomain}/file/${fileId}/1`;
} }
if (profilePicOverride === API.currentUser.profilePicOverride) { if (profilePicOverride === API.currentUser.profilePicOverride) {
return; return;
@@ -19025,6 +19044,17 @@ speechSynthesis.getVoices();
}; };
$app.methods.setDatetimeFormat(); $app.methods.setDatetimeFormat();
$app.data.enableCustomEndpoint = configRepository.getBool(
'VRCX_enableCustomEndpoint'
);
$app.methods.toggleCustomEndpoint = function () {
this.enableCustomEndpoint = !this.enableCustomEndpoint;
configRepository.setBool(
'VRCX_enableCustomEndpoint',
this.enableCustomEndpoint
);
};
$app = new Vue($app); $app = new Vue($app);
window.$app = $app; window.$app = $app;
})(); })();
+4 -1
View File
@@ -26,14 +26,17 @@ html
.detail .detail
span.name(v-text="user.user.displayName") span.name(v-text="user.user.displayName")
span.extra(v-text="user.user.username") span.extra(v-text="user.user.username")
span.extra(v-text="user.loginParmas.endpoint")
el-button(type="default" @click="deleteSavedLogin(user.user.username)" size="mini" icon="el-icon-delete" circle) el-button(type="default" @click="deleteSavedLogin(user.user.username)" size="mini" icon="el-icon-delete" circle)
div(style="margin:15px") div(style="margin:15px")
h2(style="font-weight:bold;text-align:center;margin:0") Login h2(style="font-weight:bold;text-align:center;margin:0") Login
el-form(ref="loginForm" :model="loginForm" :rules="loginForm.rules" @submit.native.prevent="login()") el-form(ref="loginForm" :model="loginForm" :rules="loginForm.rules" @submit.native.prevent="login()")
el-form-item(label="Username or Email" prop="username" required) el-form-item(label="Username or Email" prop="username" required)
el-input(v-model="loginForm.username" name="username" placeholder="Username or Email" clearable) el-input(v-model="loginForm.username" name="username" placeholder="Username or Email" clearable)
el-form-item(label="Password" prop="password" required style="margin-top:5px") el-form-item(label="Password" prop="password" required style="margin-top:10px")
el-input(type="password" v-model="loginForm.password" name="password" placeholder="Password" clearable show-password) el-input(type="password" v-model="loginForm.password" name="password" placeholder="Password" clearable show-password)
el-form-item(v-if="enableCustomEndpoint" label="Endpont" prop="endpoint" style="margin-top:10px")
el-input(v-model="loginForm.endpoint" name="endpoint" placeholder="Endpoint URL" clearable)
el-checkbox(v-model="loginForm.saveCredentials" style="margin-top:15px") Save Credentials el-checkbox(v-model="loginForm.saveCredentials" style="margin-top:15px") Save Credentials
el-form-item(style="margin-top:15px") el-form-item(style="margin-top:15px")
el-button(native-type="submit" type="primary" :loading="loginForm.loading" style="width:100%") Login el-button(native-type="submit" type="primary" :loading="loginForm.loading" style="width:100%") Login