diff --git a/src/api/emojiPacks.js b/src/api/emojiPacks.js
index cc07b1b6..61319cec 100644
--- a/src/api/emojiPacks.js
+++ b/src/api/emojiPacks.js
@@ -2,22 +2,77 @@ import request from '@/utils/request'
import { getToken } from '@/utils/auth'
import { baseName } from './utils'
-import _ from 'lodash'
+export async function addNewEmojiFile(packName, file, shortcode, filename, host, token) {
+ const data = new FormData()
+ if (filename.trim() !== '') {
+ data.set('filename', filename)
+ }
+ if (shortcode.trim() !== '') {
+ data.set('shortcode', shortcode)
+ }
+ data.set('file', file)
-export async function deletePack(host, token, name) {
return await request({
baseURL: baseName(host),
- url: `/api/pleroma/emoji/packs/${name}`,
+ url: `/api/pleroma/emoji/packs/${packName}/files`,
+ method: 'post',
+ headers: authHeaders(token),
+ data
+ })
+}
+
+export function addressOfEmojiInPack(host, packName, name) {
+ return `${baseName(host)}/emoji/${packName}/${name}`
+}
+
+export async function createPack(host, token, packName) {
+ return await request({
+ baseURL: baseName(host),
+ url: `/api/pleroma/emoji/packs/${packName}`,
+ method: 'post',
+ headers: authHeaders(token)
+ })
+}
+
+export async function deleteEmojiFile(packName, shortcode, host, token) {
+ return await request({
+ baseURL: baseName(host),
+ url: `/api/pleroma/emoji/packs/${packName}/files`,
+ method: 'delete',
+ headers: authHeaders(token),
+ data: { shortcode }
+ })
+}
+
+export async function deletePack(host, token, packName) {
+ return await request({
+ baseURL: baseName(host),
+ url: `/api/pleroma/emoji/packs/${packName}`,
method: 'delete',
headers: authHeaders(token)
})
}
-export async function reloadEmoji(host, token) {
+export async function downloadFrom(host, instance, packName, as, token) {
+ if (as.trim() === '') {
+ as = null
+ }
+
return await request({
baseURL: baseName(host),
- url: '/api/pleroma/admin/reload_emoji',
+ url: '/api/pleroma/emoji/packs/download',
method: 'post',
+ headers: authHeaders(token),
+ data: { url: baseName(instance), name: packName, as },
+ timeout: 0
+ })
+}
+
+export async function fetchPack(packName, host, token) {
+ return await request({
+ baseURL: baseName(host),
+ url: `/api/pleroma/emoji/packs/${packName}`,
+ method: 'get',
headers: authHeaders(token)
})
}
@@ -25,17 +80,8 @@ export async function reloadEmoji(host, token) {
export async function importFromFS(host, token) {
return await request({
baseURL: baseName(host),
- url: '/api/pleroma/emoji/packs/import_from_fs',
- method: 'post',
- headers: authHeaders(token)
- })
-}
-
-export async function createPack(host, token, name) {
- return await request({
- baseURL: baseName(host),
- url: `/api/pleroma/emoji/packs/${name}`,
- method: 'put',
+ url: '/api/pleroma/emoji/packs/import',
+ method: 'get',
headers: authHeaders(token)
})
}
@@ -51,106 +97,40 @@ export async function listPacks(host) {
export async function listRemotePacks(host, token, instance) {
return await request({
baseURL: baseName(host),
- url: `/api/pleroma/emoji/packs/list_from`,
- method: 'post',
- headers: authHeaders(token),
- data: { instance_address: baseName(instance) }
+ url: `/api/pleroma/emoji/packs/remote?url=${baseName(instance)}`,
+ method: 'get',
+ headers: authHeaders(token)
})
}
-export async function downloadFrom(host, instance_address, pack_name, as, token) {
- if (as.trim() === '') {
- as = null
- }
-
+export async function reloadEmoji(host, token) {
return await request({
baseURL: baseName(host),
- url: '/api/pleroma/emoji/packs/download_from',
+ url: '/api/pleroma/admin/reload_emoji',
method: 'post',
- headers: authHeaders(token),
- data: { instance_address: baseName(instance_address), pack_name, as },
- timeout: 0
+ headers: authHeaders(token)
})
}
-export async function savePackMetadata(host, token, name, new_data) {
+export async function savePackMetadata(host, token, packName, metadata) {
return await request({
baseURL: baseName(host),
- url: `/api/pleroma/emoji/packs/${name}/update_metadata`,
- method: 'post',
+ url: `/api/pleroma/emoji/packs/${packName}`,
+ method: 'patch',
headers: authHeaders(token),
- data: { name, new_data },
+ data: { metadata },
timeout: 0 // This might take a long time
})
}
-function fileUpdateFormData(d) {
- const data = new FormData()
-
- _.each(d, (v, k) => {
- data.set(k, v)
- })
-
- return data
-}
-
-export async function updatePackFile(host, token, args) {
- let data = null
-
- switch (args.action) {
- case 'add': {
- const { shortcode, file, fileName } = args
-
- data = fileUpdateFormData({
- action: 'add',
- shortcode: shortcode,
- file: file
- })
- if (fileName.trim() !== '') {
- data.set('filename', fileName)
- }
-
- break
- }
-
- case 'update': {
- const { oldName, newName, newFilename } = args
-
- data = fileUpdateFormData({
- action: 'update',
- shortcode: oldName,
- new_shortcode: newName,
- new_filename: newFilename
- })
-
- break
- }
-
- case 'remove': {
- const { name } = args
- data = fileUpdateFormData({
- action: 'remove',
- shortcode: name
- })
-
- break
- }
- }
-
- const { packName } = args
-
+export async function updateEmojiFile(packName, shortcode, newShortcode, newFilename, force, host, token) {
return await request({
baseURL: baseName(host),
- url: `/api/pleroma/emoji/packs/${packName}/update_file`,
- method: 'post',
+ url: `/api/pleroma/emoji/packs/${packName}/files`,
+ method: 'patch',
headers: authHeaders(token),
- data: data,
- timeout: 0
+ data: { shortcode, new_shortcode: newShortcode, new_filename: newFilename, force }
})
}
-export function addressOfEmojiInPack(host, packName, name) {
- return `${baseName(host)}/emoji/${packName}/${name}`
-}
-
const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {}
diff --git a/src/store/modules/emojiPacks.js b/src/store/modules/emojiPacks.js
index f92e0fa5..e4748c26 100644
--- a/src/store/modules/emojiPacks.js
+++ b/src/store/modules/emojiPacks.js
@@ -1,13 +1,16 @@
import {
+ addNewEmojiFile,
+ createPack,
+ deleteEmojiFile,
+ deletePack,
+ downloadFrom,
+ importFromFS,
listPacks,
listRemotePacks,
- downloadFrom,
reloadEmoji,
- createPack,
- deletePack,
savePackMetadata,
- importFromFS,
- updatePackFile } from '@/api/emojiPacks'
+ updateEmojiFile
+} from '@/api/emojiPacks'
import i18n from '@/lang'
import { Message } from 'element-ui'
@@ -49,6 +52,36 @@ const packs = {
}
},
actions: {
+ async AddNewEmojiFile({ commit, getters }, { packName, file, shortcode, filename }) {
+ let result
+ try {
+ result = await addNewEmojiFile(packName, file, shortcode, filename, getters.authHost, getters.token)
+ } catch (_e) {
+ return
+ }
+ Message({
+ message: `${i18n.t('settings.successfullyUpdated')} ${packName} ${i18n.t('settings.metadatLowerCase')}`,
+ type: 'success',
+ duration: 5 * 1000
+ })
+
+ commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
+ },
+ async DeleteEmojiFile({ commit, getters }, { packName, shortcode }) {
+ let result
+ try {
+ result = await deleteEmojiFile(packName, shortcode, getters.authHost, getters.token)
+ } catch (_e) {
+ return
+ }
+ Message({
+ message: `${i18n.t('settings.successfullyUpdated')} ${packName} ${i18n.t('settings.metadatLowerCase')}`,
+ type: 'success',
+ duration: 5 * 1000
+ })
+
+ commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
+ },
async CreatePack({ getters }, { name }) {
await createPack(getters.authHost, getters.token, name)
},
@@ -116,20 +149,23 @@ const packs = {
commit('SET_REMOTE_INSTANCE', remoteInstance)
commit('SET_REMOTE_PACKS', data)
},
- async UpdateAndSavePackFile({ commit, getters }, args) {
- const result = await updatePackFile(getters.authHost, getters.token, args)
-
- if (result.status === 200) {
- const { packName } = args
-
- Message({
- message: `${i18n.t('settings.successfullyUpdated')} ${packName} ${i18n.t('settings.metadatLowerCase')}`,
- type: 'success',
- duration: 5 * 1000
- })
-
- commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
+ SetRemoteInstance({ commit }, instance) {
+ commit('SET_REMOTE_INSTANCE', instance)
+ },
+ async UpdateEmojiFile({ commit, getters }, { packName, shortcode, newShortcode, newFilename, force }) {
+ let result
+ try {
+ result = await updateEmojiFile(packName, shortcode, newShortcode, newFilename, force, getters.authHost, getters.token)
+ } catch (_e) {
+ return
}
+ Message({
+ message: `${i18n.t('settings.successfullyUpdated')} ${packName} ${i18n.t('settings.metadatLowerCase')}`,
+ type: 'success',
+ duration: 5 * 1000
+ })
+
+ commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
},
async UpdateLocalPackVal({ commit }, args) {
commit('UPDATE_LOCAL_PACK_VAL', args)
diff --git a/src/views/emojiPacks/components/LocalEmojiPack.vue b/src/views/emojiPacks/components/LocalEmojiPack.vue
index 917ff4dd..c03ba580 100644
--- a/src/views/emojiPacks/components/LocalEmojiPack.vue
+++ b/src/views/emojiPacks/components/LocalEmojiPack.vue
@@ -44,11 +44,11 @@
or