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.

This commit is contained in:
Zergling_man 2024-04-14 20:25:39 +10:00
parent 9e43a19084
commit f0ddcb8d6d
4 changed files with 13 additions and 9 deletions

View File

@ -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') {

View File

@ -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

View File

@ -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)

View File

@ -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) => {