Skip to content

Commit

Permalink
Delete world persistent data button
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Oct 21, 2024
1 parent 6180777 commit 7a21376
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
104 changes: 100 additions & 4 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ speechSynthesis.getVoices();
this.$throw(0, err, endpoint);
})
.then((response) => {
if (!response.data) {
return response;
}
try {
response.data = JSON.parse(response.data);
if ($app.debugWebRequests) {
Expand Down Expand Up @@ -499,30 +502,42 @@ speechSynthesis.getVoices();
}
throw new Error('401: Unauthorized');
}
if (status === 403 && endpoint.substring(0, 6) === 'config') {
if (status === 403 && endpoint === 'config') {
$app.$alert(
'VRChat currently blocks most VPNs. Please disable any connected VPNs and try again.',
'Login Error 403'
);
this.logout();
throw new Error(`403: ${endpoint}`);
}
if (status === 404 && endpoint.substring(0, 8) === 'avatars/') {
if (
init.method === 'GET' &&
status === 404 &&
endpoint.startsWith('avatars/')
) {
$app.$message({
message: 'Avatar private or deleted',
type: 'error'
});
$app.avatarDialog.visible = false;
throw new Error(`404: ${data.error.message} ${endpoint}`);
}
if (status === 404 && endpoint.endsWith('/persist/exists')) {
return false;
}
if (
init.method === 'GET' &&
(status === 404 || status === 403) &&
!endpoint.startsWith('auth/user')
) {
this.failedGetRequests.set(endpoint, Date.now());
}
if (status === 404 && endpoint.startsWith('users/')) {
if (
init.method === 'GET' &&
status === 404 &&
endpoint.startsWith('users/') &&
endpoint.split('/').length - 1 === 1
) {
throw new Error(`404: ${data.error.message} ${endpoint}`);
}
if (
Expand Down Expand Up @@ -19168,7 +19183,8 @@ speechSynthesis.getVoices();
timeSpent: 0,
isPC: false,
isQuest: false,
isIos: false
isIos: false,
hasPersistData: false
};

$app.data.ignoreWorldMemoSave = false;
Expand Down Expand Up @@ -19342,6 +19358,7 @@ speechSynthesis.getVoices();
D.isPC = false;
D.isQuest = false;
D.isIos = false;
D.hasPersistData = false;
this.ignoreWorldMemoSave = true;
D.memo = '';
var LL = API.parseLocation(this.lastLocation.location);
Expand Down Expand Up @@ -19408,6 +19425,7 @@ speechSynthesis.getVoices();
D.isQuest = isQuest;
D.isIos = isIos;
this.updateVRChatWorldCache();
API.hasWorldPersistData({ worldId: D.id });
if (args.cache) {
API.getWorld(args.params)
.catch((err) => {
Expand Down Expand Up @@ -19882,6 +19900,18 @@ speechSynthesis.getVoices();
return args;
});
break;
case 'Delete Persistent Data':
API.deleteWorldPersistData({
worldId: D.id
}).then((args) => {
this.$message({
message:
'Persistent data has been deleted',
type: 'success'
});
return args;
});
break;
case 'Delete':
API.deleteWorld({
worldId: D.id
Expand Down Expand Up @@ -34051,6 +34081,72 @@ speechSynthesis.getVoices();

// #endregion

// #region persistent data

/**
* @param {{
worldId: string
}} params
* @returns {Promise<{json: any, params}>}
*/
API.deleteWorldPersistData = function (params) {
return this.call(
`users/${this.currentUser.id}/${params.worldId}/persist`,
{
method: 'DELETE'
}
).then((json) => {
var args = {
json,
params
};
this.$emit('WORLD:PERSIST:DELETE', args);
return args;
});
};

/**
* @param {{
worldId: string
}} params
* @returns {Promise<{json: any, params}>}
*/
API.hasWorldPersistData = function (params) {
return this.call(
`users/${this.currentUser.id}/${params.worldId}/persist/exists`,
{
method: 'GET'
}
).then((json) => {
var args = {
json,
params
};
this.$emit('WORLD:PERSIST:HAS', args);
return args;
});
};

API.$on('WORLD:PERSIST:HAS', function (args) {
if (
args.params.worldId === $app.worldDialog.id &&
$app.worldDialog.visible
) {
$app.worldDialog.hasPersistData = args.json !== false;
}
});

API.$on('WORLD:PERSIST:DELETE', function (args) {
if (
args.params.worldId === $app.worldDialog.id &&
$app.worldDialog.visible
) {
$app.worldDialog.hasPersistData = false;
}
});

// #endregion

$app = new Vue($app);
window.$app = $app;
})();
Expand Down
2 changes: 2 additions & 0 deletions html/src/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ html
el-dropdown-item(icon="el-icon-tickets" command="Previous Instances") {{ $t('dialog.world.actions.show_previous_instances') }}
template(v-if="API.currentUser.id !== worldDialog.ref.authorId")
el-dropdown-item(icon="el-icon-picture-outline" command="Previous Images") {{ $t('dialog.world.actions.show_previous_images') }}
el-dropdown-item(:disabled="!worldDialog.hasPersistData" icon="el-icon-upload" command="Delete Persistent Data") {{ $t('dialog.world.actions.delete_persistent_data') }}
template(v-else)
el-dropdown-item(icon="el-icon-edit" command="Rename") {{ $t('dialog.world.actions.rename') }}
el-dropdown-item(icon="el-icon-edit" command="Change Description") {{ $t('dialog.world.actions.change_description') }}
Expand All @@ -702,6 +703,7 @@ html
el-dropdown-item(v-if="worldDialog.ref.unityPackageUrl" icon="el-icon-download" command="Download Unity Package") {{ $t('dialog.world.actions.download_package') }}
el-dropdown-item(v-if="worldDialog.ref.tags.includes('system_approved') || worldDialog.ref.tags.includes('system_labs')" icon="el-icon-view" command="Unpublish" divided) {{ $t('dialog.world.actions.unpublish') }}
el-dropdown-item(v-else icon="el-icon-view" command="Publish" divided) {{ $t('dialog.world.actions.publish_to_labs') }}
el-dropdown-item(:disabled="!worldDialog.hasPersistData" icon="el-icon-upload" command="Delete Persistent Data") {{ $t('dialog.world.actions.delete_persistent_data') }}
el-dropdown-item(icon="el-icon-delete" command="Delete" style="color:#F56C6C") {{ $t('dialog.world.actions.delete') }}
el-tabs
el-tab-pane(:label="$t('dialog.world.instances.header')")
Expand Down
1 change: 1 addition & 0 deletions html/src/localization/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@
"download_package": "Download Unity Package",
"publish_to_labs": "Publish To Labs",
"unpublish": "Unpublish",
"delete_persistent_data": "Delete Persistent Data",
"delete": "Delete"
},
"instances": {
Expand Down

0 comments on commit 7a21376

Please sign in to comment.