Browse Source

Upload for all files fix 119 (#120)

* allow uploading files not only to http + replace symbol images by unicode symbols

allow uploading files to root dir and http.
+ replace symbol images by unicode symbols

* backend for uploading arbitrary files

* fix uploading to http
Gregor Hartmann 3 years ago
parent
commit
7c8fe9c164
2 changed files with 79 additions and 37 deletions
  1. 59 10
      http/upload.html
  2. 20 27
      http/upload.lua

File diff suppressed because it is too large
+ 59 - 10
http/upload.html


+ 20 - 27
http/upload.lua

@@ -48,18 +48,16 @@ return function (connection, req, args)
 	
 	if (mbCmd == 'upload') then
 		if (fieldsCount > 5) then
-			if (mbFilename ~= 'upload.lua') then
+			if (mbFilename ~= 'http/upload.lua') then
 				connection:send('"offset":"' .. mbOffset .. '",')
 				connection:send('"len":"' .. mbLen .. '",')
 				connection:send('"filename":"' .. mbFilename .. '"')
-				
-				mbFilename = 'http/' .. mbFilename
-				
+
 				for i=1,string.len(mbData),2 do
 					currentByte = tonumber(string.sub(mbData, i, i + 1), 16)
 					binaryData = binaryData .. string.char(currentByte)
 				end
-				
+
             local mbTmpFilename = string.sub(mbFilename, 0, 27) .. '.dnl' 
 				if (mbOffset > 0) then
 					file.open(mbTmpFilename,'a+')
@@ -77,7 +75,7 @@ return function (connection, req, args)
 					file.remove(mbFilename)					
 					file.rename(mbTmpFilename, mbFilename)
 					file.remove(mbTmpFilename)						
-				
+
 					if (string.sub(mbFilename, -4) == '.lua') then
 						file.remove(string.sub(mbFilename, 0, -3) .. "lc")
 						node.compile(mbFilename)
@@ -90,39 +88,34 @@ return function (connection, req, args)
 		local remaining, used, total=file.fsinfo()
 
 		local headerExist = 0
-		
+
 		connection:send('"files":{')
-		
+
 		for name, size in pairs(file.list()) do
-			local isHttpFile = string.match(name, "(http/)") ~= nil
-			
-			if isHttpFile then
-				if (headerExist > 0) then 
-					connection:send(',')
-				end
-				
-				local url = string.match(name, ".*/(.*)")
-				
-				connection:send('"' .. url .. '":"' .. size .. '"')
-				
-				headerExist = 1
-			end
+         if (headerExist > 0) then 
+            connection:send(',')
+         end
+
+         local url = string.match(name, ".*/(.*)")
+         url = name
+         connection:send('"' .. url .. '":"' .. size .. '"')
+
+         headerExist = 1
 		end
-		
+
 		connection:send('},')
-		
+
 		connection:send('"total":"' .. total .. '",')
 		connection:send('"used":"' .. used .. '",')
 		connection:send('"free":"' .. remaining .. '"')
 	elseif (mbCmd == 'remove') then
 		if (fieldsCount > 1) then
-			if (mbFilename ~= 'upload.lua') and (mbFilename ~= 'upload.lc') and (mbFilename ~= 'upload.html.gz') then
-				file.remove('http/' .. mbFilename)
+			if (mbFilename ~= 'http/upload.lua') and (mbFilename ~= 'http/upload.lc') and (mbFilename ~= 'http/upload.html.gz') then
+				file.remove(mbFilename)
 			end
 		end
 	end
-	
+
 	connection:send('}')	
 	collectgarbage()
 end
-