2020-05-10 03:46:06 +00:00
|
|
|
import Importer from 'src/components/importer/importer.vue'
|
|
|
|
import Exporter from 'src/components/exporter/exporter.vue'
|
|
|
|
import Checkbox from 'src/components/checkbox/checkbox.vue'
|
2020-09-07 11:27:37 +00:00
|
|
|
import { mapState } from 'vuex'
|
2020-05-03 14:36:12 +00:00
|
|
|
|
2020-05-10 03:46:06 +00:00
|
|
|
const DataImportExportTab = {
|
2020-05-03 14:36:12 +00:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
activeTab: 'profile',
|
2022-07-18 13:08:50 +00:00
|
|
|
newDomainToMute: '',
|
|
|
|
listBackupsError: false,
|
|
|
|
addBackupError: false,
|
|
|
|
addedBackup: false,
|
|
|
|
backups: []
|
2020-05-03 14:36:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.$store.dispatch('fetchTokens')
|
2022-07-18 13:08:50 +00:00
|
|
|
this.fetchBackups()
|
2020-05-03 14:36:12 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Importer,
|
|
|
|
Exporter,
|
|
|
|
Checkbox
|
|
|
|
},
|
|
|
|
computed: {
|
2020-09-07 11:27:37 +00:00
|
|
|
...mapState({
|
|
|
|
backendInteractor: (state) => state.api.backendInteractor,
|
|
|
|
user: (state) => state.users.currentUser
|
|
|
|
})
|
2020-05-03 14:36:12 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getFollowsContent () {
|
2020-09-07 11:27:37 +00:00
|
|
|
return this.backendInteractor.exportFriends({ id: this.user.id })
|
2020-05-03 14:36:12 +00:00
|
|
|
.then(this.generateExportableUsersContent)
|
|
|
|
},
|
|
|
|
getBlocksContent () {
|
2020-09-07 11:27:37 +00:00
|
|
|
return this.backendInteractor.fetchBlocks()
|
|
|
|
.then(this.generateExportableUsersContent)
|
|
|
|
},
|
|
|
|
getMutesContent () {
|
|
|
|
return this.backendInteractor.fetchMutes()
|
2020-05-03 14:36:12 +00:00
|
|
|
.then(this.generateExportableUsersContent)
|
|
|
|
},
|
|
|
|
importFollows (file) {
|
2020-09-07 11:27:37 +00:00
|
|
|
return this.backendInteractor.importFollows({ file })
|
2020-05-03 14:36:12 +00:00
|
|
|
.then((status) => {
|
|
|
|
if (!status) {
|
|
|
|
throw new Error('failed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
importBlocks (file) {
|
2020-09-07 11:27:37 +00:00
|
|
|
return this.backendInteractor.importBlocks({ file })
|
|
|
|
.then((status) => {
|
|
|
|
if (!status) {
|
|
|
|
throw new Error('failed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
importMutes (file) {
|
|
|
|
return this.backendInteractor.importMutes({ file })
|
2020-05-03 14:36:12 +00:00
|
|
|
.then((status) => {
|
|
|
|
if (!status) {
|
|
|
|
throw new Error('failed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
generateExportableUsersContent (users) {
|
|
|
|
// Get addresses
|
|
|
|
return users.map((user) => {
|
|
|
|
// check is it's a local user
|
|
|
|
if (user && user.is_local) {
|
|
|
|
// append the instance address
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
return user.screen_name + '@' + location.hostname
|
|
|
|
}
|
|
|
|
return user.screen_name
|
|
|
|
}).join('\n')
|
2022-07-18 13:08:50 +00:00
|
|
|
},
|
|
|
|
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
|
|
|
|
})
|
2020-05-03 14:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 03:46:06 +00:00
|
|
|
export default DataImportExportTab
|