aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/admin_tabs/emoji_tab.js
diff options
context:
space:
mode:
authorEkaterina Vaartis <vaartis@kotobank.ch>2024-01-07 14:28:34 +0300
committerEkaterina Vaartis <vaartis@kotobank.ch>2024-01-07 14:28:34 +0300
commitf8e1d5e3e0600a0a113ee40787b7589b61c2654f (patch)
tree49f30873382f3760c98db46880343663dcfecde7 /src/components/settings_modal/admin_tabs/emoji_tab.js
parent4451cccb3c1244a179b9f5017e6a4536eb5456f1 (diff)
Remote pack download, localization
Diffstat (limited to 'src/components/settings_modal/admin_tabs/emoji_tab.js')
-rw-r--r--src/components/settings_modal/admin_tabs/emoji_tab.js80
1 files changed, 74 insertions, 6 deletions
diff --git a/src/components/settings_modal/admin_tabs/emoji_tab.js b/src/components/settings_modal/admin_tabs/emoji_tab.js
index f3adc3d5..d88c9e55 100644
--- a/src/components/settings_modal/admin_tabs/emoji_tab.js
+++ b/src/components/settings_modal/admin_tabs/emoji_tab.js
@@ -24,13 +24,16 @@ const EmojiTab = {
data () {
return {
- knownPacks: { },
+ knownLocalPacks: { },
+ knownRemotePacks: { },
editedParts: { },
editedMetadata: { },
packName: '',
newPackName: '',
deleteModalVisible: false,
- newEmojiUpload: clone(newEmojiUploadBase)
+ newEmojiUpload: clone(newEmojiUploadBase),
+ remotePackInstance: '',
+ remotePackDownloadAs: ''
}
},
@@ -44,6 +47,17 @@ const EmojiTab = {
}
return this.editedMetadata[this.packName]
+ },
+ knownPacks () {
+ // Copy the object itself but not the children, so they are still passed by reference and modified
+ const result = clone(this.knownLocalPacks)
+ for (const instName in this.knownRemotePacks) {
+ for (const instPack in this.knownRemotePacks[instName]) {
+ result[`${instPack}@${instName}`] = this.knownRemotePacks[instName][instPack]
+ }
+ }
+
+ return result
}
},
@@ -55,7 +69,12 @@ const EmojiTab = {
this.$store.state.api.backendInteractor.importEmojiFromFS()
},
emojiAddr (name) {
- return `${this.$store.state.instance.server}/emoji/${encodeURIComponent(this.packName)}/${name}`
+ if (this.pack.remote !== undefined) {
+ // Remote pack
+ return `${this.pack.remote.instance}/emoji/${encodeURIComponent(this.pack.remote.baseName)}/${name}`
+ } else {
+ return `${this.$store.state.instance.server}/emoji/${encodeURIComponent(this.packName)}/${name}`
+ }
},
uploadEmoji () {
@@ -193,15 +212,64 @@ const EmojiTab = {
return
}
- this.knownPacks = packData.packs
- for (const name of Object.keys(this.knownPacks)) {
+ this.knownLocalPacks = packData.packs
+ for (const name of Object.keys(this.knownLocalPacks)) {
this.sortPackFiles(name)
}
})
},
+ listRemotePacks () {
+ this.$store.state.api.backendInteractor.listRemoteEmojiPacks({ instance: this.remotePackInstance })
+ .then(data => data.json())
+ .then(packData => {
+ if (packData.error !== undefined) {
+ this.displayError(packData.error)
+ return
+ }
+
+ let inst = this.remotePackInstance
+ if (!inst.startsWith('http')) { inst = 'https://' + inst }
+ const instUrl = new URL(inst)
+ inst = instUrl.host
+
+ for (const packName in packData.packs) {
+ packData.packs[packName].remote = {
+ baseName: packName,
+ instance: instUrl.origin
+ }
+ }
+
+ this.knownRemotePacks[inst] = packData.packs
+
+ this.$refs.remotePackPopover.hidePopover()
+ })
+ },
+ downloadRemotePack () {
+ if (this.remotePackDownloadAs.trim() === '') {
+ this.remotePackDownloadAs = this.pack.remote.baseName
+ }
+
+ this.$store.state.api.backendInteractor.downloadRemoteEmojiPack({
+ instance: this.pack.remote.instance, packName: this.pack.remote.baseName, as: this.remotePackDownloadAs
+ })
+ .then(data => data.json())
+ .then(resp => {
+ if (resp === 'ok') {
+ this.$refs.dlPackPopover.hidePopover()
+
+ return this.refreshPackList()
+ } else {
+ this.displayError(resp.error)
+ return Promise.reject(resp)
+ }
+ }).then(done => {
+ this.packName = this.remotePackDownloadAs
+ this.remotePackDownloadAs = ''
+ })
+ },
displayError (msg) {
this.$store.dispatch('pushGlobalNotice', {
- messageKey: 'upload.error.message',
+ messageKey: 'admin_dash.emoji.error',
messageArgs: [msg],
level: 'error'
})