~lastrosade/getcraft

f91ad96f7fa3fea8dd2b022bb41ffb39f99a2e51 — jeremy.shields 5 years ago 4ecb79f
err
1 files changed, 21 insertions(+), 12 deletions(-)

M src/index.lua
M src/index.lua => src/index.lua +21 -12
@@ 57,6 57,7 @@ function scandir(directory)
	pfile:close()
	if (i == 0) then
		print("Warning on directory '"..directory.. "', Could not iterate over")
		return false
	end
    return t
end


@@ 93,8 94,9 @@ http.createServer(function (req, res)
				local content = readAll(route.res)
				if (content == false) then 
					res:writeHead(404, {})
					res:setHeader("Content-Length", 0)
					res:finish()
					err = "404, File is missing"
					res:setHeader("Content-Length", #err)
					res:finish(err)
				else
					res:setHeader("Content-Type", "text/plain")
					res:setHeader("Content-Length", #content)


@@ 103,17 105,24 @@ http.createServer(function (req, res)

			elseif (route.type == "directory") then
				local files = scandir(route.res)
				local array = {}
				for i,f in pairs(files) do
					array[i] = {}
					array[i].filename = f
					array[i].content = readAll(f)
					array[i].size = #array[i].content
				if (files == false) then
					res:writeHead(404, {})
					err = "404, Directory is empty or missing"
					res:setHeader("Content-Length", #err)
					res:finish(err)
				else
					local array = {}
					for i,f in pairs(files) do
						array[i] = {}
						array[i].filename = f
						array[i].content = readAll(f)
						array[i].size = #array[i].content
					end
					content = json.encode(array)
					res:setHeader("Content-Type", "text/plain")
					res:setHeader("Content-Length", #content)
					res:finish(content)
				end
				content = json.encode(array)
				res:setHeader("Content-Type", "text/plain")
				res:setHeader("Content-Length", #content)
				res:finish(content)

			end