diff --git a/README.ja.md b/README.ja.md index 946bf94..e3c3062 100644 --- a/README.ja.md +++ b/README.ja.md @@ -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を起動する。 diff --git a/README.md b/README.md index bf333b1..dcdbfff 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lua/fafm.lua b/lua/fafm.lua index ddbe24a..de3c533 100644 --- a/lua/fafm.lua +++ b/lua/fafm.lua @@ -1,3 +1,5 @@ +-- Version 0.1.1 + -- read config local file = io.open('credentials.json') local text = file:read("*a") @@ -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) @@ -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 diff --git a/lua/fafm_boot.lua b/lua/fafm_boot.lua index d64e4e9..0bb596e 100644 --- a/lua/fafm_boot.lua +++ b/lua/fafm_boot.lua @@ -1,3 +1,5 @@ +-- Version 0.1.1 + local fafm = require("fafm") while(1) do diff --git a/lua/fafm_list.lua b/lua/fafm_list.lua index 27ab3fc..c5ad127 100644 --- a/lua/fafm_list.lua +++ b/lua/fafm_list.lua @@ -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 \ No newline at end of file diff --git a/lua/fafm_upload.lua b/lua/fafm_upload.lua index 67ed0aa..102d83f 100644 --- a/lua/fafm_upload.lua +++ b/lua/fafm_upload.lua @@ -1,3 +1,5 @@ +-- Version 0.1.1 + local current_path = arguments.current_path or "/" local file_name = arguments.file_name diff --git a/package.json b/package.json index 40e0a3d..884d464 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/common/const.js b/src/common/const.js index 9cff92a..3d83579 100644 --- a/src/common/const.js +++ b/src/common/const.js @@ -38,8 +38,8 @@ export const IoTHubApiConst = { export const Filer = { files: { mode: { - FILE: 'file', - DIRECTORY: 'directory' + FILE: 'f', + DIRECTORY: 'd' }, special: { PARENT_DIR: '..' diff --git a/src/common/resources.js b/src/common/resources.js index 2efebee..8fcc2df 100644 --- a/src/common/resources.js +++ b/src/common/resources.js @@ -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)', diff --git a/src/common/util.js b/src/common/util.js index 4b180ff..22bf427 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -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); diff --git a/src/main/main.js b/src/main/main.js index 7f39ad9..ceca5fb 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -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 diff --git a/src/renderer/view/filer.js b/src/renderer/view/filer.js index aa9b440..f0b5634 100644 --- a/src/renderer/view/filer.js +++ b/src/renderer/view/filer.js @@ -524,12 +524,6 @@ 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; @@ -537,36 +531,39 @@ export class FilerPage { 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([{