Update emoji api functions

This commit is contained in:
Angelina Filippova 2020-04-01 16:37:08 +03:00
parent ee20731a4e
commit 32432e1f6e

View file

@ -2,20 +2,71 @@ import request from '@/utils/request'
import { getToken } from '@/utils/auth'
import { baseName } from './utils'
export async function deletePack(host, token, name) {
export async function addNewEmojiFile(packName, file, shortcode, filename, host, token) {
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: {
file,
shortcode: shortcode.trim() !== '' ? shortcode : null,
filename: filename.trim() !== '' ? filename : null }
})
}
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)
})
}
@ -29,15 +80,6 @@ export async function importFromFS(host, token) {
})
}
export async function createPack(host, token, name) {
return await request({
baseURL: baseName(host),
url: `/api/pleroma/emoji/packs/${name}`,
method: 'post',
headers: authHeaders(token)
})
}
export async function listPacks(host) {
return await request({
baseURL: baseName(host),
@ -55,25 +97,19 @@ export async function listRemotePacks(host, token, instance) {
})
}
export async function downloadFrom(host, instance, 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',
url: '/api/pleroma/admin/reload_emoji',
method: 'post',
headers: authHeaders(token),
data: { url: baseName(instance), name: pack_name, as },
timeout: 0
headers: authHeaders(token)
})
}
export async function savePackMetadata(host, token, name, metadata) {
export async function savePackMetadata(host, token, packName, metadata) {
return await request({
baseURL: baseName(host),
url: `/api/pleroma/emoji/packs/${name}`,
url: `/api/pleroma/emoji/packs/${packName}`,
method: 'patch',
headers: authHeaders(token),
data: { metadata },
@ -81,19 +117,6 @@ export async function savePackMetadata(host, token, name, metadata) {
})
}
export async function addNewEmojiFile(packName, file, shortcode, filename, host, token) {
return await request({
baseURL: baseName(host),
url: `/api/pleroma/emoji/packs/${packName}/files`,
method: 'post',
headers: authHeaders(token),
data: {
file,
shortcode: shortcode.trim() !== '' ? shortcode : null,
filename: filename.trim() !== '' ? filename : null }
})
}
export async function updateEmojiFile(packName, shortcode, newShortcode, newFilename, force, host, token) {
return await request({
baseURL: baseName(host),
@ -104,18 +127,4 @@ export async function updateEmojiFile(packName, shortcode, newShortcode, newFile
})
}
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 function addressOfEmojiInPack(host, packName, name) {
return `${baseName(host)}/emoji/${packName}/${name}`
}
const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {}