0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 02:53:49 +01:00

add check for control and clear gcode on print fetch start

This commit is contained in:
Simon Voordouw 2017-06-12 12:06:27 +02:00
parent 82d4179bc3
commit 2f91065ff7

View File

@ -189,10 +189,37 @@ function M.fetch_POST(request, response)
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
if not printer or not printer:hasSocket() then return end
local controllerIP = accessManager.getController()
local hasControl = false
if controllerIP == "" then
accessManager.setController(request.remoteAddress)
hasControl = true
elseif controllerIP == request.remoteAddress then
hasControl = true
end
if not hasControl then
response:setFail("No control access")
return
end
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
response:addData('gcode_clear',true)
local rv,msg = printer:clearGcode()
if rv == false then
response:addData('status', msg)
response:setFail("could not clear gcode (" .. msg .. ")")
elseif rv == nil then
response:setError(msg)
return
end
local socket = printer:getId()
local remote = settings.get('gcode_server')
local id = request:get("id")
io.popen("print-fetch.lua " .. socket .. " " .. remote .. " " .. id)
io.popen("print-fetch " .. socket .. " " .. remote .. " " .. id)
response:setSuccess()
end