-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.lua
49 lines (42 loc) · 1.41 KB
/
push.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
serverUrl = "http://192.168.0.11/"
watchFolder = "/DCIM/101CANON"
watchExt = "JPG"
local function httpSuccess(code)
local firstNum = string.sub(code, 1, 1)
return (firstNum == '2' or firstNum == '1')
end
local function sendFileName(filePath)
local message = cjson.encode({ file = filePath })
print(filePath .. "->" .. serverUrl)
body, code, header = fa.request { url = serverUrl
, method = "POST"
, headers = { ["Content-Length"] = string.len(message)
, ["Content-Type"] = "application/json"
}
, body = message
}
if httpSuccess(code) then
print("SENT " .. filePath)
else
print("FAILED " .. filePath)
end
collectgarbage()
end
local function checkDir()
local newestFileDate = 0
for file in lfs.dir(watchFolder) do
local filePath = watchFolder..'/'..file
local fileDate = lfs.attributes(filePath, 'modification')
local fileExt = string.sub(filePath, -3)
if ((fileDate) and (fileDate > newestFileDate) and (watchExt == fileExt)) then
newestFileDate = fileDate
newestFilePath = filePath
end
end
collectgarbage()
return newestFilePath
end
local res = fa.ReadStatusReg()
if (string.sub(res, 13, 13) == "b") then
sendFileName(checkDir())
end