logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

data_import_export_tab.js (2854B)


  1. import Importer from 'src/components/importer/importer.vue'
  2. import Exporter from 'src/components/exporter/exporter.vue'
  3. import Checkbox from 'src/components/checkbox/checkbox.vue'
  4. import { mapState } from 'vuex'
  5. const DataImportExportTab = {
  6. data () {
  7. return {
  8. activeTab: 'profile',
  9. newDomainToMute: '',
  10. listBackupsError: false,
  11. addBackupError: false,
  12. addedBackup: false,
  13. backups: []
  14. }
  15. },
  16. created () {
  17. this.$store.dispatch('fetchTokens')
  18. this.fetchBackups()
  19. },
  20. components: {
  21. Importer,
  22. Exporter,
  23. Checkbox
  24. },
  25. computed: {
  26. ...mapState({
  27. backendInteractor: (state) => state.api.backendInteractor,
  28. user: (state) => state.users.currentUser
  29. })
  30. },
  31. methods: {
  32. getFollowsContent () {
  33. return this.backendInteractor.exportFriends({ id: this.user.id })
  34. .then(this.generateExportableUsersContent)
  35. },
  36. getBlocksContent () {
  37. return this.backendInteractor.fetchBlocks()
  38. .then(this.generateExportableUsersContent)
  39. },
  40. getMutesContent () {
  41. return this.backendInteractor.fetchMutes()
  42. .then(this.generateExportableUsersContent)
  43. },
  44. importFollows (file) {
  45. return this.backendInteractor.importFollows({ file })
  46. .then((status) => {
  47. if (!status) {
  48. throw new Error('failed')
  49. }
  50. })
  51. },
  52. importBlocks (file) {
  53. return this.backendInteractor.importBlocks({ file })
  54. .then((status) => {
  55. if (!status) {
  56. throw new Error('failed')
  57. }
  58. })
  59. },
  60. importMutes (file) {
  61. return this.backendInteractor.importMutes({ file })
  62. .then((status) => {
  63. if (!status) {
  64. throw new Error('failed')
  65. }
  66. })
  67. },
  68. generateExportableUsersContent (users) {
  69. // Get addresses
  70. return users.map((user) => {
  71. // check is it's a local user
  72. if (user && user.is_local) {
  73. // append the instance address
  74. // eslint-disable-next-line no-undef
  75. return user.screen_name + '@' + location.hostname
  76. }
  77. return user.screen_name
  78. }).join('\n')
  79. },
  80. addBackup () {
  81. this.$store.state.api.backendInteractor.addBackup()
  82. .then((res) => {
  83. this.addedBackup = true
  84. this.addBackupError = false
  85. })
  86. .catch((error) => {
  87. this.addedBackup = false
  88. this.addBackupError = error
  89. })
  90. .then(() => this.fetchBackups())
  91. },
  92. fetchBackups () {
  93. this.$store.state.api.backendInteractor.listBackups()
  94. .then((res) => {
  95. this.backups = res
  96. this.listBackupsError = false
  97. })
  98. .catch((error) => {
  99. this.listBackupsError = error.error
  100. })
  101. }
  102. }
  103. }
  104. export default DataImportExportTab