From b2564cfabb5996d606d6f8abf554a015f0c1fea7 Mon Sep 17 00:00:00 2001 From: cutls Date: Sat, 11 Apr 2020 10:41:04 +0900 Subject: [PATCH] Fix: Pleroma image upload --- app/js/post/img.js | 47 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/app/js/post/img.js b/app/js/post/img.js index 202aa37f..0a186035 100644 --- a/app/js/post/img.js +++ b/app/js/post/img.js @@ -133,25 +133,34 @@ async function media(b64, type, no, stamped) { //v2/media try { var id = await v2MediaUpload(domain, at, fd) - var mediav = $('#media').val() - var regExp = new RegExp('tmp_' + r, 'g') - mediav = mediav.replace(regExp, id) - $('#media').val(mediav) - var html = `` - $('#preview').append(html) - todc() - if (localStorage.getItem('nsfw_' + acct_id)) { - $('#nsfw').addClass('yellow-text') - $('#nsfw').html('visibility') - $('#nsfw').addClass('nsfw-avail') - } - $('.toot-btn-group').prop('disabled', false) - $('select').formSelect() - $('#mec').text(lang.lang_there) - M.toast({ html: '' + lang.lang_postimg_sync + '', displayLength: 3000 }) - $('#imgup').text('') - $('#imgsel').show() - localStorage.removeItem('image') + if(!id) { + var start = 'https://' + domain + '/api/v1/media' + httpreq.open('POST', start, true) + httpreq.upload.addEventListener('progress', progshow, false) + httpreq.responseType = 'json' + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.send(fd) + } else { + var mediav = $('#media').val() + var regExp = new RegExp('tmp_' + r, 'g') + mediav = mediav.replace(regExp, id) + $('#media').val(mediav) + var html = `` + $('#preview').append(html) + todc() + if (localStorage.getItem('nsfw_' + acct_id)) { + $('#nsfw').addClass('yellow-text') + $('#nsfw').html('visibility') + $('#nsfw').addClass('nsfw-avail') + } + $('.toot-btn-group').prop('disabled', false) + $('select').formSelect() + $('#mec').text(lang.lang_there) + M.toast({ html: '' + lang.lang_postimg_sync + '', displayLength: 3000 }) + $('#imgup').text('') + $('#imgsel').show() + localStorage.removeItem('image') + } } catch { var start = 'https://' + domain + '/api/v1/media' httpreq.open('POST', start, true)