Skip to content
This repository was archived by the owner on Jul 31, 2019. It is now read-only.

Commit 88ec183

Browse files
committed
Shulink the data size of JSON for file list.
1 parent d68a53d commit 88ec183

File tree

12 files changed

+63
-43
lines changed

12 files changed

+63
-43
lines changed

README.ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ FlashAir™の無線LAN機能を使い、FlashAir IoT Hubを経由する事で
3535
## Usage
3636

3737
1. 事前にFlashAir IoT Hubでアカウント登録し、FlashAirを登録する。詳細は[FlashAir IoT Hubのご利用の流れ](https://www.flashair-developers.com/ja/documents/tutorials/iot-hub/1/)を参照。
38-
2. [Luaスクリプト](https://github.com/FlashAirDevelopers/FlashAirFileManager/archive/FlashAirFileManagerScript-0.1.0.zip)をダウンロード・解凍してFlashAirのルート上に置く。
38+
2. [Luaスクリプト](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/download/v0.1.1/FlashAirFileManagerScript-0.1.1.zip)をダウンロード・解凍してFlashAirのルート上に置く。
3939
3. FlashAirのCONFIGに`LUA_RUN_SCRIPT=/fafm_boot.lua`を追記する。
4040
4. FlashAirを抜き挿しするなどして、再起動する。
4141
5. FlashAirFileMangerを起動する。

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ It is in [FlashAir Developers - FlashairFileManager](https://www.flashair-develo
3535
## Usage
3636

3737
1. Register your account in advance with FlashAir IoT Hub and register FlashAir. For details, please refer to [Flow of using FlashAir IoT Hub](https://www.flashair-developers.com/en/documents/tutorials/iot-hub/1/).
38-
2. Download [Lua script](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/download/v0.1.0/FlashAirFileManagerScript-0.1.0.zip), unzip it and place it on the root of FlashAir.
38+
2. Download [Lua script](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/download/v0.1.1/FlashAirFileManagerScript-0.1.1.zip), unzip it and place it on the root of FlashAir.
3939
3. Add `LUA_RUN_SCRIPT=/fafm_boot.lua` to FlashAir CONFIG.
4040
4. Disconnect and reconnect the FlashAir and restart.
4141
5. Start FlashAirFileManger.

lua/fafm.lua

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- Version 0.1.1
2+
13
-- read config
24
local file = io.open('credentials.json')
35
local text = file:read("*a")
@@ -33,6 +35,21 @@ local function getJob(job)
3335
return nil
3436
end
3537

38+
local function updateJob(job, response)
39+
local body = cjson.encode({response=response, status='executed'})
40+
b, c, h = fa.request {
41+
url=config.api_base .. '/v1/flashairs/self/jobs/' .. job.id,
42+
method='PATCH',
43+
headers={
44+
['Authorization']='Basic ' .. config.credential,
45+
['Content-Length']=tostring(string.len(body)),
46+
['Content-Type']='application/json',
47+
['If-Match']=job.etag,
48+
},
49+
body=body,
50+
}
51+
end
52+
3653
local function execJob(job)
3754
if job.request.type == "script" then
3855
local script = loadfile(job.request.path)
@@ -50,21 +67,6 @@ local function execJob(job)
5067
end
5168
end
5269

53-
local function updateJob(job, response)
54-
local body = cjson.encode({response=response, status='executed'})
55-
b, c, h = fa.request {
56-
url=config.api_base .. '/v1/flashairs/self/jobs/' .. job.id,
57-
method='PATCH',
58-
headers={
59-
['Authorization']='Basic ' .. config.credential,
60-
['Content-Length']=tostring(string.len(body)),
61-
['Content-Type']='application/json',
62-
['If-Match']=job.etag,
63-
},
64-
body=body,
65-
}
66-
end
67-
6870
local function runJob()
6971
local jobs = getJobs()
7072
for i, job in ipairs(jobs) do

lua/fafm_boot.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- Version 0.1.1
2+
13
local fafm = require("fafm")
24

35
while(1) do

lua/fafm_list.lua

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1+
-- Version 0.1.1
2+
13
local current_path = arguments.current_path or "/"
24

35
-- Get file list under current_path
46
local result = {}
7+
local full_path = ""
8+
local file_attr = nil
9+
local file_mode = ""
510
for file_name in lfs.dir(current_path) do
6-
local full_path = current_path .. "/" .. file_name
7-
local file_attr = lfs.attributes(full_path)
8-
table.insert(result, {
9-
name=file_name,
10-
mode=file_attr.mode,
11-
size=file_attr.size,
12-
modification=file_attr.modification
13-
})
11+
-- Skip dot files
12+
if file_name:sub(0, 1) ~= "." then
13+
full_path = current_path .. "/" .. file_name
14+
file_attr = lfs.attributes(full_path)
15+
-- Filter file or directory only
16+
if (file_attr.mode == "file") or (file_attr.mode == "directory") then
17+
-- Set mode initials. file:"f", directory:"d"
18+
file_mode = string.sub(file_attr.mode, 0, 1)
19+
table.insert(result, {
20+
n=file_name,
21+
m=file_mode,
22+
u=file_attr.modification
23+
})
24+
end
25+
end
1426
end
1527

1628
return result

lua/fafm_upload.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- Version 0.1.1
2+
13
local current_path = arguments.current_path or "/"
24
local file_name = arguments.file_name
35

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flashair-file-manager",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "The application to browse and download files on FlashAir™ via the network.",
55
"homepage": "https://github.com/FlashAirDevelopers/FlashAirFileManager",
66
"main": "./src/main/main.js",

src/common/const.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const IoTHubApiConst = {
3838
export const Filer = {
3939
files: {
4040
mode: {
41-
FILE: 'file',
42-
DIRECTORY: 'directory'
41+
FILE: 'f',
42+
DIRECTORY: 'd'
4343
},
4444
special: {
4545
PARENT_DIR: '..'

src/common/resources.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
export const resources = {
23+
common_window_title: 'FlashAir File Manager',
2324
menu_label_file: 'ファイル (F)',
2425
menu_label_file_close: '終了 (X)',
2526
menu_label_remote: 'リモート (L)',

src/common/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121

2222
export const fatDateToDate = (fatDate) => {
23+
if (fatDate === 0) {
24+
return new Date(1980, 0, 1, 0, 0, 0);
25+
}
2326
const year = ((fatDate >> 25) & 0x7F) + 1980;
2427
const month = ((fatDate >> 21) & 0x0F);
2528
const date = ((fatDate >> 16) & 0x1F);

0 commit comments

Comments
 (0)