fix: file upload
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good

This commit is contained in:
DanyLE 2023-01-28 04:01:13 +01:00
parent 0974679023
commit beec8b9350
2 changed files with 9 additions and 6 deletions

View File

@ -186,8 +186,9 @@ end
function VFSController:upload(...)
auth_or_die("User unauthorized. Please login")
local vfs = require("vfs")
if REQUEST and REQUEST.path then
local r, m = require("vfs").upload(REQUEST.path)
--LOG_DEBUG("UPLOAD COMMAND: %s", JSON.encode(REQUEST))
if REQUEST and REQUEST.multipart and REQUEST.multipart.path then
local r, m = require("vfs").upload(REQUEST.multipart.path)
if r then
result(r)
else

View File

@ -149,11 +149,13 @@ vfs.upload = function(path)
if (r) then
local uid = ulib.uid(SESSION.user)
local index = 0
while (REQUEST["upload-" .. index .. ".tmp"] ~= nil) do
local file = m .. "/" .. REQUEST["upload-" .. index .. ".file"]
local ret = ulib.move(REQUEST["upload-" .. index .. ".tmp"], file)
while (REQUEST.multipart["upload-" .. index] ~= nil) do
local file_data = JSON.decodeString(REQUEST.multipart["upload-" .. index])
local file = m .. "/" .. file_data.file
local ret = ulib.move(file_data.tmp, file)
if not ret then
ret = ulib.send_file(REQUEST["upload-" .. index .. ".tmp"], file)
ret = ulib.send_file(file_data.tmp, file)
end
if not ret then
return false, "Unable to copy file"