From f0ddcb8d6d24eb345e57a8f799aa255a6bda9447 Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Sun, 14 Apr 2024 20:25:39 +1000 Subject: [PATCH] Images now actually send filenames to the server. Server may still disregard them, but pleromer will actually detect mime type properly and generate a sane URL. --- app/js/platform/end.js | 2 +- app/js/platform/preload.js | 4 ++-- app/js/post/img.js | 14 +++++++++----- app/main/img.js | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/js/platform/end.js b/app/js/platform/end.js index ce65c908..f54c0a3d 100644 --- a/app/js/platform/end.js +++ b/app/js/platform/end.js @@ -145,7 +145,7 @@ onmessage = function (e) { } else if (e.data[0] == 'udg') { udg(e.data[1][0], e.data[1][1]) } else if (e.data[0] == 'media') { - media(e.data[1][0], e.data[1][1], e.data[1][2], e.data[1][3]) + media(e.data[1][0], e.data[1][1], e.data[1][2], e.data[1][3], e.data[1][4]) } else if (e.data[0] == 'post') { post('pass') } else if (e.data[0] == 'toastSaved') { diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index 27ab5292..a3cd9cbf 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -156,12 +156,12 @@ ipc.on('resizeJudgement', function (event, b64) { if (width > resize || height > resize) { ipc.send('resize-image', [b64[0], resize]) } else { - postMessage(['media', [b64[0], 'image/png', b64[1]]], '*') + postMessage(['media', [b64[0], 'image/png', b64[1], null, b64[2]]], '*') } } element.src = 'data:image/png;base64,' + b64[0] } else { - postMessage(['media', [b64[0], 'image/png', b64[1]]], '*') + postMessage(['media', [b64[0], 'image/png', b64[1], null, b64[2]]], '*') } }) //ui,img.js diff --git a/app/js/post/img.js b/app/js/post/img.js index 973064e4..a0073658 100644 --- a/app/js/post/img.js +++ b/app/js/post/img.js @@ -57,6 +57,7 @@ function fileselect() { //ファイル読み込み function handleFileUpload(files, obj, no) { + console.log('nignog\n'+files+'\n'+obj+'\n'+no) var fr = new FileReader() fr.onload = function(evt) { var b64 = evt.target.result @@ -72,21 +73,24 @@ function handleFileUpload(files, obj, no) { return false } else { $('#b64-box').val(b64) - var ret = media(b64, files['type'], no) + var ret = media(b64, files['type'], no, null, files['name']) } } element.src = b64 return false } $('#b64-box').val(b64) - var ret = media(b64, files['type'], no) + var ret = media(b64, files['type'], no, null, files['name']) } fr.readAsDataURL(files) $('#mec').append(files['name'] + '/') } //ファイルアップロード -async function media(b64, type, no, stamped) { +async function media(b64, type, no, stamped, filename) { + if (filename) filename=filename.split('/').slice(-1) + else filename='image.png' // probably from clipboard + console.log('nognig\n'+type+'\n'+no+'\n'+stamped) var acct_id = $('#post-acct-sel').val() var domain = localStorage.getItem('domain_' + acct_id) var user = localStorage.getItem('user_' + acct_id) @@ -112,7 +116,7 @@ async function media(b64, type, no, stamped) { todo('Image Upload...') var media = toBlob(b64, type) var fd = new FormData() - fd.append('file', media) + fd.append('file', media, filename) var at = localStorage.getItem('acct_' + acct_id + '_at') var httpreq = new XMLHttpRequest() if (localStorage.getItem('mode_' + domain) == 'misskey') { @@ -265,7 +269,7 @@ element.addEventListener('paste', function(e) { var i = mediav.split(',').length } // DataTransferItem の type に mime tipes があるのでそれを使う - media(base64, imageType, i) + media(base64, imageType, i, null, 'image.png') } fr.readAsDataURL(imageFile) diff --git a/app/main/img.js b/app/main/img.js index 7a11d672..667f3df2 100644 --- a/app/main/img.js +++ b/app/main/img.js @@ -26,7 +26,7 @@ function img(mainWindow, dir) { for (var i = 0; i < fileNames.length; i++) { var path = fileNames[i] var bin = fs.readFileSync(path, 'base64') - e.sender.send('resizeJudgement', [bin, 'new']) + e.sender.send('resizeJudgement', [bin, 'new', fileNames[i]]) } }) ipc.on('bmp-image', (e, args) => {