@samitouri / QOSami-HFS / commits / 14df6e1c

upload: use PUT instead of POST, as it's simpler

Massimo Melina committed Dec 23, 2023 at 19:55 UTC 14df6e1c81d5d6e77bbe8594b2570b366f2bd4b6
2 files changed +5 -7
frontend/src/upload.ts
+4 -6
@@ -190,8 +190,8 @@ export function showUpload() {
190
191 }
192
193 -function path(f: File, pre='') {
194 - return (prefix('', pre, '/') + (f.webkitRelativePath || f.name)).replaceAll('//','/')
193 +function path(f: File) {
194 + return (f.webkitRelativePath || f.name).replaceAll('//','/')
195 }
196
197 function FilesList({ entries, actions }: { entries: Readonly<ToUpload[]>, actions: { [icon:string]: null | ((rec :ToUpload) => any) } }) {
@@ -299,15 +299,13 @@ async function startUpload(toUpload: ToUpload, to: string, resume=0) {
299 bytesSent += e.loaded - lastProgress
300 lastProgress = e.loaded
301 }
302 - req.open('POST', to + '?' + new URLSearchParams({
302 + req.open('PUT', to + encodeURIComponent(path(toUpload.file)) + '?' + new URLSearchParams({
303 notificationChannel,
304 ...resume && { resume: String(resume) },
305 ...toUpload.comment && { comment: toUpload.comment },
306 ...uploadState.skipExisting && { skipExisting: '1' },
307 }), true)
308 - const form = new FormData()
309 - form.append('file', toUpload.file.slice(resume), path(toUpload.file))
310 - req.send(form)
308 + req.send(toUpload.file.slice(resume))
309
310 async function subscribeNotifications() {
311 if (notificationChannel) return
src/middlewares.ts
+1 -1
@@ -94,7 +94,7 @@ export const serveGuiAndSharedFiles: Koa.Middleware = async (ctx, next) => {
94 return allowAdmin(ctx) ? serveAdminPrefixed(ctx,next)
95 : sendErrorPage(ctx, HTTP_FORBIDDEN)
96 if (ctx.method === 'PUT') { // curl -T file url/
97 - const decPath = decodeURI(path)
97 + const decPath = decodeURIComponent(path)
98 let rest = basename(decPath)
99 const folder = await urlToNode(dirname(decPath), ctx, vfs, v => rest = v+'/'+rest)
100 if (!folder)