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

Commit

Permalink
Shulink the data size of JSON for file list.
Browse files Browse the repository at this point in the history
  • Loading branch information
tks-abe committed Oct 17, 2017
1 parent d68a53d commit 88ec183
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FlashAir™の無線LAN機能を使い、FlashAir IoT Hubを経由する事で
## Usage

1. 事前にFlashAir IoT Hubでアカウント登録し、FlashAirを登録する。詳細は[FlashAir IoT Hubのご利用の流れ](https://www.flashair-developers.com/ja/documents/tutorials/iot-hub/1/)を参照。
2. [Luaスクリプト](https://github.com/FlashAirDevelopers/FlashAirFileManager/archive/FlashAirFileManagerScript-0.1.0.zip)をダウンロード・解凍してFlashAirのルート上に置く。
2. [Luaスクリプト](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/download/v0.1.1/FlashAirFileManagerScript-0.1.1.zip)をダウンロード・解凍してFlashAirのルート上に置く。
3. FlashAirのCONFIGに`LUA_RUN_SCRIPT=/fafm_boot.lua`を追記する。
4. FlashAirを抜き挿しするなどして、再起動する。
5. FlashAirFileMangerを起動する。
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It is in [FlashAir Developers - FlashairFileManager](https://www.flashair-develo
## Usage

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/).
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.
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.
3. Add `LUA_RUN_SCRIPT=/fafm_boot.lua` to FlashAir CONFIG.
4. Disconnect and reconnect the FlashAir and restart.
5. Start FlashAirFileManger.
Expand Down
32 changes: 17 additions & 15 deletions lua/fafm.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- Version 0.1.1

-- read config
local file = io.open('credentials.json')
local text = file:read("*a")
Expand Down Expand Up @@ -33,6 +35,21 @@ local function getJob(job)
return nil
end

local function updateJob(job, response)
local body = cjson.encode({response=response, status='executed'})
b, c, h = fa.request {
url=config.api_base .. '/v1/flashairs/self/jobs/' .. job.id,
method='PATCH',
headers={
['Authorization']='Basic ' .. config.credential,
['Content-Length']=tostring(string.len(body)),
['Content-Type']='application/json',
['If-Match']=job.etag,
},
body=body,
}
end

local function execJob(job)
if job.request.type == "script" then
local script = loadfile(job.request.path)
Expand All @@ -50,21 +67,6 @@ local function execJob(job)
end
end

local function updateJob(job, response)
local body = cjson.encode({response=response, status='executed'})
b, c, h = fa.request {
url=config.api_base .. '/v1/flashairs/self/jobs/' .. job.id,
method='PATCH',
headers={
['Authorization']='Basic ' .. config.credential,
['Content-Length']=tostring(string.len(body)),
['Content-Type']='application/json',
['If-Match']=job.etag,
},
body=body,
}
end

local function runJob()
local jobs = getJobs()
for i, job in ipairs(jobs) do
Expand Down
2 changes: 2 additions & 0 deletions lua/fafm_boot.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- Version 0.1.1

local fafm = require("fafm")

while(1) do
Expand Down
28 changes: 20 additions & 8 deletions lua/fafm_list.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
-- Version 0.1.1

local current_path = arguments.current_path or "/"

-- Get file list under current_path
local result = {}
local full_path = ""
local file_attr = nil
local file_mode = ""
for file_name in lfs.dir(current_path) do
local full_path = current_path .. "/" .. file_name
local file_attr = lfs.attributes(full_path)
table.insert(result, {
name=file_name,
mode=file_attr.mode,
size=file_attr.size,
modification=file_attr.modification
})
-- Skip dot files
if file_name:sub(0, 1) ~= "." then
full_path = current_path .. "/" .. file_name
file_attr = lfs.attributes(full_path)
-- Filter file or directory only
if (file_attr.mode == "file") or (file_attr.mode == "directory") then
-- Set mode initials. file:"f", directory:"d"
file_mode = string.sub(file_attr.mode, 0, 1)
table.insert(result, {
n=file_name,
m=file_mode,
u=file_attr.modification
})
end
end
end

return result
2 changes: 2 additions & 0 deletions lua/fafm_upload.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- Version 0.1.1

local current_path = arguments.current_path or "/"
local file_name = arguments.file_name

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flashair-file-manager",
"version": "0.1.0",
"version": "0.1.1",
"description": "The application to browse and download files on FlashAir™ via the network.",
"homepage": "https://github.com/FlashAirDevelopers/FlashAirFileManager",
"main": "./src/main/main.js",
Expand Down
4 changes: 2 additions & 2 deletions src/common/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const IoTHubApiConst = {
export const Filer = {
files: {
mode: {
FILE: 'file',
DIRECTORY: 'directory'
FILE: 'f',
DIRECTORY: 'd'
},
special: {
PARENT_DIR: '..'
Expand Down
1 change: 1 addition & 0 deletions src/common/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

export const resources = {
common_window_title: 'FlashAir File Manager',
menu_label_file: 'ファイル (F)',
menu_label_file_close: '終了 (X)',
menu_label_remote: 'リモート (L)',
Expand Down
3 changes: 3 additions & 0 deletions src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/

export const fatDateToDate = (fatDate) => {
if (fatDate === 0) {
return new Date(1980, 0, 1, 0, 0, 0);
}
const year = ((fatDate >> 25) & 0x7F) + 1980;
const month = ((fatDate >> 21) & 0x0F);
const date = ((fatDate >> 16) & 0x1F);
Expand Down
1 change: 1 addition & 0 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
title: resources.common_window_title,
useContentSize: true,
webPreferences: {
// comment out for load jQuery and Bootstrap
Expand Down
27 changes: 12 additions & 15 deletions src/renderer/view/filer.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,49 +524,46 @@ export class FilerPage {
if ((job.response)
&& (job.response.result)
&& (job.response.result.length > 0)) {
// formatting modification timestamp
if (job.response.result.files) {
job.response.result.files.forEach(file => {
file.modification = new Date(file.modification);
});
}
const curRemoteFiles = curState.remoteFiles || [];
let fetchedDir = curRemoteFiles.filter(dir => {
return dir.path !== job.request.arguments.current_path;
});
job.response.result.sort((a, b) => {
// sort by mode(directory or file)
// directory than file
if (a.mode < b.mode) {
if (a.m < b.m) {
return -1;
} else if (b.mode < a.mode) {
} else if (b.m < a.m) {
return 1;
}
// sort by name
if (a.name.hasOwnProperty('localeCompare')) {
const nameCmp = a.name.localeCompare(b.name);
if (a.n.hasOwnProperty('localeCompare')) {
const nameCmp = a.n.localeCompare(b.n);
if (nameCmp !== 0) {
// ASC sort
return nameCmp;
}
}
// ASC sort
if (a.name < b.name) {
if (a.n < b.n) {
return -1;
} else if (b.name < a.name) {
} else if (b.n < a.n) {
return 1;
}
// sort by timestamp
return a.modification - b.modification;
return a.u - b.u;
});
job.response.result.forEach((file, index, array) => {
array[index].modification = dateFormat.format(fatDateToDate(file.modification), 'yyyy/MM/dd');
// Mapping shot protperty to regureler property
array[index].name = file.n;
array[index].mode = file.m;
// formatting modification timestamp
array[index].modification = dateFormat.format(fatDateToDate(file.u), 'yyyy/MM/dd');
});
// Add move parent directory item
job.response.result.unshift({
name: Filer.files.special.PARENT_DIR,
mode: Filer.files.mode.DIRECTORY,
size: 0,
modification: ''
});
fetchedDir = fetchedDir.concat([{
Expand Down

0 comments on commit 88ec183

Please sign in to comment.