|
|
@@ -2,13 +2,31 @@ require("fwutils.webapi")
|
|
|
local M = {}
|
|
|
|
|
|
M.add = function(file_size,filepath,desc,conn)
|
|
|
- local ppst = conn:setsql("INSERT INTO fw_file (role_id,custom_id,file_size,filepath,`desc`) VALUES (?,?,?,?,?)")
|
|
|
- local user_data = cjson.decode(request.get("user_data"))
|
|
|
- ppst:set_i32(1,user_data.role_id)
|
|
|
- ppst:set_i32(2,user_data.id)
|
|
|
- ppst:set_i64(3,file_size)
|
|
|
- ppst:set_str(4,filepath)
|
|
|
- ppst:set_str(5,desc)
|
|
|
+ local sql = ""
|
|
|
+
|
|
|
+ local user_data = request.get("user_data")
|
|
|
+ if user_data ~= nil and user_data ~= "" then
|
|
|
+ sql = "INSERT INTO fw_file (role_id,custom_id,file_size,filepath,`desc`) VALUES (?,?,?,?,?)"
|
|
|
+ user_data = cjson.decode(user_data)
|
|
|
+ else
|
|
|
+ user_data = nil
|
|
|
+ sql = "INSERT INTO fw_file (file_size,filepath,`desc`) VALUES (?,?,?)"
|
|
|
+ end
|
|
|
+
|
|
|
+ local ppst = conn:setsql(sql)
|
|
|
+ if user_data ~= nil then
|
|
|
+ ppst:set_i32(1,user_data.role_id)
|
|
|
+ ppst:set_i32(2,user_data.id)
|
|
|
+ ppst:set_i64(3,file_size)
|
|
|
+ ppst:set_str(4,filepath)
|
|
|
+ ppst:set_str(5,desc)
|
|
|
+ else
|
|
|
+ ppst:set_i64(1,file_size)
|
|
|
+ ppst:set_str(2,filepath)
|
|
|
+ ppst:set_str(3,desc)
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
if ppst:update() == 1 then
|
|
|
return true
|
|
|
end
|