LibraryForm.vue 3.03 KB
Newer Older
1
2
<template>
  <form class="ui form" @submit.prevent="fetchInstanceInfo">
Bat's avatar
Bat committed
3
4
    <h3 class="ui header"><i18next path="Federate with a new instance"/></h3>
    <p><i18next path="Use this form to scan an instance and setup federation."/></p>
5
    <div v-if="errors.length > 0 || scanErrors.length > 0" class="ui negative message">
Bat's avatar
Bat committed
6
      <div class="header"><i18next path="Error while scanning library"/></div>
7
8
9
10
11
12
13
      <ul class="list">
        <li v-for="error in errors">{{ error }}</li>
        <li v-for="error in scanErrors">{{ error }}</li>
      </ul>
    </div>
    <div class="ui two fields">
      <div class="ui field">
Bat's avatar
Bat committed
14
        <label><i18next path="Library name"/></label>
15
16
17
18
19
20
21
22
23
        <input v-model="libraryUsername" type="text" placeholder="library@demo.funkwhale.audio" />
      </div>
      <div class="ui field">
        <label>&nbsp;</label>
        <button
          type="submit"
          :disabled="isLoading"
          :class="['ui', 'icon', {loading: isLoading}, 'button']">
          <i class="search icon"></i>
Bat's avatar
Bat committed
24
          <i18next path="Launch scan"/>
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
        </button>
      </div>
    </div>
  </form>
</template>

<script>
import axios from 'axios'
import TrackTable from '@/components/audio/track/Table'
import RadioButton from '@/components/radios/Button'
import Pagination from '@/components/Pagination'

export default {
  components: {
    TrackTable,
    RadioButton,
    Pagination
  },
  data () {
    return {
      isLoading: false,
46
      libraryUsername: '',
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
      result: null,
      errors: []
    }
  },
  methods: {
    follow () {
      let params = {
        'actor': this.result['actor']['id'],
        'autoimport': false,
        'download_files': false,
        'federation_enabled': true
      }
      let self = this
      self.isFollowing = false
      axios.post('/federation/libraries/', params).then((response) => {
        self.$emit('follow', {data: self.result, library: response.data})
        self.result = response.data
        self.isFollowing = false
      }, error => {
        self.isFollowing = false
        self.errors = error.backendErrors
      })
    },
    fetchInstanceInfo () {
      let self = this
      this.isLoading = true
      self.errors = []
      self.result = null
75
      axios.get('/federation/libraries/fetch/', {params: {account: this.libraryUsername}}).then((response) => {
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
        self.result = response.data
        self.result.display_name = self.libraryUsername
        self.isLoading = false
      }, error => {
        self.isLoading = false
        self.errors = error.backendErrors
      })
    }
  },
  computed: {
    scanErrors () {
      let errors = []
      if (!this.result) {
        return errors
      }
      let keys = ['webfinger', 'actor', 'library']
      keys.forEach(k => {
        if (this.result[k]) {
          if (this.result[k].errors) {
            this.result[k].errors.forEach(e => {
              errors.push(e)
            })
          }
        }
      })
      return errors
    }
  },
  watch: {
    result (newValue, oldValue) {
      this.$emit('scanned', newValue)
    }
  }
}
</script>