Update API for downloading remote packs

This commit is contained in:
Angelina Filippova 2020-03-30 19:48:41 +03:00
parent 5805792211
commit 1f488a18be
4 changed files with 20 additions and 8 deletions

View file

@ -57,17 +57,17 @@ export async function listRemotePacks(host, token, instance) {
})
}
export async function downloadFrom(host, instance_address, pack_name, as, token) {
export async function downloadFrom(host, instance, pack_name, as, token) {
if (as.trim() === '') {
as = null
}
return await request({
baseURL: baseName(host),
url: '/api/pleroma/emoji/packs/download_from',
url: '/api/pleroma/emoji/packs/download',
method: 'post',
headers: authHeaders(token),
data: { instance_address: baseName(instance_address), pack_name, as },
data: { url: baseName(instance), name: pack_name, as },
timeout: 0
})
}

View file

@ -116,6 +116,9 @@ const packs = {
commit('SET_REMOTE_INSTANCE', remoteInstance)
commit('SET_REMOTE_PACKS', data)
},
SetRemoteInstance({ commit }, instance) {
commit('SET_REMOTE_INSTANCE', instance)
},
async UpdateAndSavePackFile({ commit, getters }, args) {
const result = await updatePackFile(getters.authHost, getters.token, args)

View file

@ -52,7 +52,7 @@
</p>
<div class="download-shared-pack">
<el-input v-model="downloadSharedAs" :placeholder=" $t('emoji.downloadAsOptional')"/>
<el-button type="primary" class="download-shared-pack-button" @click="downloadFromInstance(pack.pack['homepage'])">
<el-button type="primary" class="download-shared-pack-button" @click="downloadFromInstance">
{{ isDesktop ? $t('emoji.downloadSharedPack') : $t('emoji.downloadSharedPackMobile') }}
</el-button>
</div>
@ -113,6 +113,9 @@ export default {
loadRemotePack() {
return this.$store.state.emojiPacks.activeCollapseItems.includes(this.name)
},
remoteInstanceAddress() {
return this.$store.state.emojiPacks.remoteInstance
},
share: {
get() { return this.pack.pack['share-files'] },
set(value) {
@ -171,11 +174,10 @@ export default {
}
},
methods: {
downloadFromInstance(url) {
const instanceAddress = `${new URL(url).protocol}//${new URL(url).hostname}`
downloadFromInstance() {
this.$store.dispatch(
'DownloadFrom',
{ instanceAddress, packName: this.name, as: this.downloadSharedAs }
{ instanceAddress: this.remoteInstanceAddress, packName: this.name, as: this.downloadSharedAs }
).then(() => this.$store.dispatch('ReloadEmoji'))
.then(() => this.$store.dispatch('SetLocalEmojiPacks'))
}

View file

@ -63,7 +63,6 @@ export default {
components: { LocalEmojiPack, RemoteEmojiPack },
data() {
return {
remoteInstanceAddress: '',
newPackName: '',
activeLocalPack: [],
activeRemotePack: [],
@ -89,6 +88,14 @@ export default {
localPacks() {
return this.$store.state.emojiPacks.localPacks
},
remoteInstanceAddress: {
get() {
return this.$store.state.emojiPacks.remoteInstance
},
set(instance) {
this.$store.dispatch('SetRemoteInstance', instance)
}
},
remotePacks() {
return this.$store.state.emojiPacks.remotePacks
}