Implement multipart request for uploading emojis

This commit is contained in:
Angelina Filippova 2020-04-01 18:51:17 +03:00
parent 32432e1f6e
commit a2072165aa

View file

@ -3,15 +3,21 @@ import { getToken } from '@/utils/auth'
import { baseName } from './utils' import { baseName } from './utils'
export async function addNewEmojiFile(packName, file, shortcode, filename, host, token) { 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)
return await request({ return await request({
baseURL: baseName(host), baseURL: baseName(host),
url: `/api/pleroma/emoji/packs/${packName}/files`, url: `/api/pleroma/emoji/packs/${packName}/files`,
method: 'post', method: 'post',
headers: authHeaders(token), headers: authHeaders(token),
data: { data
file,
shortcode: shortcode.trim() !== '' ? shortcode : null,
filename: filename.trim() !== '' ? filename : null }
}) })
} }