From f3ce76ddbfb49b574b37019ed0c1062d509de916 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Mon, 9 May 2022 00:38:25 -0400 Subject: [PATCH 1/3] Add backup UI --- .../tabs/data_import_export_tab.js | 29 ++++++++- .../tabs/data_import_export_tab.vue | 61 +++++++++++++++++++ src/services/api/api.service.js | 22 +++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/components/settings_modal/tabs/data_import_export_tab.js b/src/components/settings_modal/tabs/data_import_export_tab.js index f4b736d2dc..4895733c90 100644 --- a/src/components/settings_modal/tabs/data_import_export_tab.js +++ b/src/components/settings_modal/tabs/data_import_export_tab.js @@ -7,11 +7,16 @@ const DataImportExportTab = { data () { return { activeTab: 'profile', - newDomainToMute: '' + newDomainToMute: '', + listBackupsError: false, + addBackupError: false, + addedBackup: false, + backups: [] } }, created () { this.$store.dispatch('fetchTokens') + this.fetchBackups() }, components: { Importer, @@ -72,6 +77,28 @@ const DataImportExportTab = { } return user.screen_name }).join('\n') + }, + addBackup () { + this.$store.state.api.backendInteractor.addBackup() + .then((res) => { + this.addedBackup = true + this.addBackupError = false + }) + .catch((error) => { + this.addedBackup = false + this.addBackupError = error + }) + .then(() => this.fetchBackups()) + }, + fetchBackups () { + this.$store.state.api.backendInteractor.listBackups() + .then((res) => { + this.backups = res + this.listBackupsError = false + }) + .catch((error) => { + this.listBackupsError = error.error + }) } } } diff --git a/src/components/settings_modal/tabs/data_import_export_tab.vue b/src/components/settings_modal/tabs/data_import_export_tab.vue index a406077d03..0654839041 100644 --- a/src/components/settings_modal/tabs/data_import_export_tab.vue +++ b/src/components/settings_modal/tabs/data_import_export_tab.vue @@ -53,6 +53,67 @@ :export-button-label="$t('settings.mute_export_button')" /> +
+

{{ $t('settings.account_backup') }}

+

{{ $t('settings.account_backup_description') }}

+ + + + + + + + + + + + + +
{{ $t('settings.account_backup_table_head') }}
{{ backup.inserted_at }} + + {{ $t('settings.download_backup') }} + + + {{ $t('settings.backup_not_ready') }} + +
+
+ {{ $t('settings.list_backups_error', { error }) }} + +
+ +

+ {{ $t('settings.added_backup') }} +

+ +
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 436b8b0a0e..d2df353abe 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -87,6 +87,7 @@ const PLEROMA_CHAT_URL = id => `/api/v1/pleroma/chats/by-account-id/${id}` const PLEROMA_CHAT_MESSAGES_URL = id => `/api/v1/pleroma/chats/${id}/messages` const PLEROMA_CHAT_READ_URL = id => `/api/v1/pleroma/chats/${id}/read` const PLEROMA_DELETE_CHAT_MESSAGE_URL = (chatId, messageId) => `/api/v1/pleroma/chats/${chatId}/messages/${messageId}` +const PLEROMA_BACKUP_URL = '/api/v1/pleroma/backups' const oldfetch = window.fetch @@ -868,6 +869,25 @@ const fetchBlocks = ({ credentials }) => { .then((users) => users.map(parseUser)) } +const addBackup = ({ credentials }) => { + return promisedRequest({ + url: PLEROMA_BACKUP_URL, + method: 'POST', + credentials + }) +} + +const listBackups = ({ credentials }) => { + return promisedRequest({ + url: PLEROMA_BACKUP_URL, + method: 'GET', + credentials, + params: { + _cacheBooster: (new Date()).getTime() + } + }) +} + const fetchOAuthTokens = ({ credentials }) => { const url = '/api/oauth_tokens.json' @@ -1325,6 +1345,8 @@ const apiService = { generateMfaBackupCodes, mfaSetupOTP, mfaConfirmOTP, + addBackup, + listBackups, fetchFollowRequests, approveUser, denyUser, From 22af78c7f421a1b62e5149a7ea95d789493e382d Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Mon, 9 May 2022 00:38:46 -0400 Subject: [PATCH 2/3] Add English translations for backup UI --- src/i18n/en.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/i18n/en.json b/src/i18n/en.json index f8336e5cea..06c2a5e47b 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -314,6 +314,16 @@ "mute_import_error": "Error importing mutes", "mutes_imported": "Mutes imported! Processing them will take a while.", "import_mutes_from_a_csv_file": "Import mutes from a csv file", + "account_backup": "Account backup", + "account_backup_description": "This allows you to download an archive of your account information and your posts, but they cannot yet be imported into a Pleroma account.", + "account_backup_table_head": "Backup", + "download_backup": "Download", + "backup_not_ready": "This backup is not ready yet.", + "remove_backup": "Remove", + "list_backups_error": "Error fetching backup list: {error}", + "add_backup": "Create a new backup", + "added_backup": "Added a new backup.", + "add_backup_error": "Error adding a new backup: {error}", "blocks_tab": "Blocks", "bot": "This is a bot account", "btnRadius": "Buttons", From 653a762c21270bc74fd4da8bf49ec1c7d8f69df2 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Mon, 9 May 2022 00:40:39 -0400 Subject: [PATCH 3/3] Make lint happy --- src/components/settings_modal/tabs/data_import_export_tab.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/settings_modal/tabs/data_import_export_tab.vue b/src/components/settings_modal/tabs/data_import_export_tab.vue index 0654839041..e3b7f407c9 100644 --- a/src/components/settings_modal/tabs/data_import_export_tab.vue +++ b/src/components/settings_modal/tabs/data_import_export_tab.vue @@ -60,7 +60,7 @@ {{ $t('settings.account_backup_table_head') }} - +