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

Commit afdd963

Browse files
committed
Fixed issue that does not work with W-03.
1 parent 20af01f commit afdd963

10 files changed

Lines changed: 125 additions & 41 deletions

File tree

README.ja.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ FlashAir™の無線LAN機能を使い、FlashAir IoT Hubを経由する事で
7878

7979
## Changelog
8080

81+
- [0.3.2](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.2)
82+
- W-03で動作しない事がある問題を修正しました。
83+
- iothub.luaの先頭行のバージョン番号が1.5.0未満の場合、最新のLuaスクリプトを[FlashAir IoT Hub](https://iot-hub.flashair-developers.com)からダウンロードしてください。
8184
- [0.3.1](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.1)
8285
- OSの言語設定が英語と日本語以外の場合、起動に失敗する問題を修正しました。
8386
- [0.3.0](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.0)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Note: Since version 0.2.0, Lua scripts are using [FlashAir IoT Hub](https://iot-
7878

7979
## Changelog
8080

81+
- [0.3.2](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.2)
82+
- Fixed issue that does not work with W-03.
83+
- If the version number of the first line of `iothub.lua` is less than 1.5.0, download the latest Lua script from [FlashAir IoT Hub](https://iot-hub.flashair-developers.com).
8184
- [0.3.1](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.1)
8285
- Fixed issue that failed to start if OS locale is other than English and Japanese.
8386
- [0.3.0](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.0)

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.3.1",
3+
"version": "0.3.2",
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/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ export const IoTHubApi = {
4444
};
4545
export const FlashAIrScript = {
4646
LIST: '/list_file.lua',
47-
UPLOAD: '/upload_file.lua'
47+
LIST_FETCH_MAX: 10,
48+
UPLOAD: '/upload_file_slim.lua'
4849
};

src/common/resources.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const resources = {
3535
filer_label_local_file_date: '更新日付',
3636
filer_label_remote_file_name: '名前',
3737
filer_label_remote_file_date: '更新日付',
38+
filer_label_remote_show_more: '更に表示する',
3839
filer_msg_remote_download_progress: 'ダウンロード中...',
3940
filer_msg_remote_download_completed: 'ダウンロードが完了しました。',
4041
auth_msg_invalid_access_token: '認証処理が失敗しました。再度ログインし直してください。',
@@ -56,6 +57,7 @@ export const resources = {
5657
filer_label_local_file_date: 'Update date',
5758
filer_label_remote_file_name: 'Name',
5859
filer_label_remote_file_date: 'Update date',
60+
filer_label_remote_show_more: 'Show more',
5961
filer_msg_remote_download_progress: 'Downloading...',
6062
filer_msg_remote_download_completed: 'Download is completed.',
6163
auth_msg_invalid_access_token: 'Authentication processing failed. Please login again.',

src/main/store/app-store.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ export class AppStore extends EventEmitter {
4545
/*
4646
* [{
4747
* path:<parent full path>,
48+
* startIndex <Display start index>,
4849
* files:[{
4950
* name:<file name>
5051
* mode:<file type: file, directory>
5152
* size:<file size>
5253
* modification:<file modification timestamp>
54+
* } ...]
5355
* },
5456
* {...}
5557
* ]
5658
*/
5759
localFiles: [],
5860
remoteFiles: [],
61+
// boolean has more remote files
62+
isMoreRemoteFiles: false,
5963
// String current local directory path
6064
localCurDir: os.homedir(),
6165
// String currnent remote direcotry path
@@ -157,11 +161,12 @@ export class AppStore extends EventEmitter {
157161
this.state.isFetchingRemoteFileList = isFetchingRemoteFileList;
158162
this.emit(AppEvent.CHANGE_FLASHAIR, this.state);
159163
}
160-
_requestFlashAirFileListOnStart({isFetchingRemoteFileList, flashairId, remoteCurDir}) {
164+
_requestFlashAirFileListOnStart({isFetchingRemoteFileList, flashairId, remoteCurDir, isMoreRemoteFiles}) {
161165
this.state.isFetchingRemoteFileList = isFetchingRemoteFileList;
162166
this.state.flashairId = flashairId;
163167
this.state.remoteCurDir = remoteCurDir;
164168
this.state.curJobResponderId = null;
169+
this.state.isMoreRemoteFiles = isMoreRemoteFiles;
165170
this.emit(AppEvent.REQUEST_REMOTE_FILE_LIST, this.state);
166171
}
167172
_requestFlashAirFileListOnSuccess({isFetchingRemoteFileList, curJobResponderId}) {
@@ -198,9 +203,10 @@ export class AppStore extends EventEmitter {
198203
this.state.message = message;
199204
this.emit(AppEvent.DELETE_REMOTE_JOB_FAILURE);
200205
}
201-
_updateRemoteFileList({remoteFiles, isFetchingRemoteFileList}) {
206+
_updateRemoteFileList({remoteFiles, isFetchingRemoteFileList, isMoreRemoteFiles}) {
202207
this.state.isFetchingRemoteFileList = isFetchingRemoteFileList;
203208
this.state.remoteFiles = remoteFiles;
209+
this.state.isMoreRemoteFiles = isMoreRemoteFiles;
204210
this.emit(AppEvent.UPDATE_REMOTE_FILE_LIST, this.state);
205211
}
206212
_getLocalFileListOnStart({isGetingLocalFileList}) {

src/renderer/action/iothub-action.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,20 @@ export class IoTHubAction {
107107
isFetchingRemoteFileList: false
108108
});
109109
}
110-
requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir}, useCache = false) {
110+
requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir, isMoreRemoteFiles}, useCache = false, startIndex = 0) {
111111
if (state.isFetchingRemoteFileList || !state.flashairId) {
112112
return Promise.resolve();
113113
}
114-
return this._requestRemoteFileList(state, useCache);
114+
return this._requestRemoteFileList(state, useCache, startIndex);
115115
}
116-
_requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir}, useCache = false) {
116+
_requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir, isMoreRemoteFiles}, useCache, startIndex) {
117117
// Notify fetch start event
118118
this.dispatcher.emit(AppEvent.REQUEST_REMOTE_FILE_LIST, {
119119
isFetchingRemoteFileList: true,
120120
flashairId: state.flashairId,
121-
remoteCurDir: state.remoteCurDir
121+
remoteCurDir: state.remoteCurDir,
122+
remoteFileStartIndex: startIndex || 0,
123+
isMoreRemoteFiles: state.isMoreRemoteFiles
122124
});
123125
const requestBody = {
124126
request: {
@@ -127,6 +129,9 @@ export class IoTHubAction {
127129
arguments: {current_path: state.remoteCurDir || '/'}
128130
}
129131
};
132+
if (startIndex !== undefined) {
133+
requestBody.request.arguments.start_index = Number(startIndex);
134+
}
130135
return fetch(`${IoTHubApi.baseUrl}${IoTHubApi.jobs.replace('{flashair_id}', state.flashairId)}`, {
131136
method: 'POST',
132137
headers: {
@@ -251,10 +256,11 @@ export class IoTHubAction {
251256
});
252257
});
253258
}
254-
updateFiles(state = {remoteFiles}) {
259+
updateFiles(state = {remoteFiles, isMoreRemoteFiles}) {
255260
this.dispatcher.emit(AppEvent.UPDATE_REMOTE_FILE_LIST, {
256261
remoteFiles: state.remoteFiles,
257-
isFetchingRemoteFileList: false
262+
isFetchingRemoteFileList: false,
263+
isMoreRemoteFiles: state.isMoreRemoteFiles
258264
});
259265
}
260266
selectRemoteFile(fileName) {

src/renderer/view/filer.js

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ export class FilerPage {
250250
if (tmpRemoteFiles && tmpRemoteFiles.files) {
251251
templateVar.remoteFiles = tmpRemoteFiles.files;
252252
}
253+
// Set fetch more files start index
254+
templateVar.remoteStartIndex = tmpRemoteFiles.startIndex;
253255
}
254256
this._templateAddFileFlag(templateVar);
255257
const renderContent = filerTemplate(templateVar || this.baseTemplateVar);
@@ -350,6 +352,10 @@ export class FilerPage {
350352
$('#remote-reload').on('click', this.refreshRemoteDirectory);
351353
$('#local-reload').on('click', this.refreshLocalDirectory);
352354
$('#download-button').on('click', this.onClickDownload);
355+
$('#remote-file-row-more-item').on('click', (event) => {
356+
const startIndex = $(event.currentTarget).attr('data-start-index');
357+
this.onClickMoreRemoteFiles(startIndex);
358+
});
353359

354360
// Show FlashAir file loading
355361
if (templateVar.isFetchingFlashairs || templateVar.isFetchingRemoteFileList) {
@@ -411,7 +417,11 @@ export class FilerPage {
411417
}
412418
changeRemoteDirecory(remoteNextDir, useCache) {
413419
this.iotHubAction.requestRemoteFileList(Object.assign(
414-
appMain.store.getState(), {remoteCurDir: remoteNextDir, selectedRemoteFile: null}
420+
appMain.store.getState(), {
421+
remoteCurDir: remoteNextDir,
422+
selectedRemoteFile: null,
423+
isMoreRemoteFiles: false
424+
}
415425
,useCache)
416426
)
417427
.catch(response => {
@@ -480,6 +490,15 @@ export class FilerPage {
480490
}
481491
});
482492
}
493+
onClickMoreRemoteFiles(startIndex) {
494+
this.iotHubAction.requestRemoteFileList(appMain.store.getState(), true, startIndex)
495+
.catch(response => {
496+
log.error(response);
497+
if (response) {
498+
this.notifyMessage('danger', resources[this.locale].common_msg_process_failure);
499+
}
500+
});
501+
}
483502
watchRequestJob() {
484503
const curState = appMain.store.getState();
485504
this.iotHubAction.getJobs(curState)
@@ -533,6 +552,31 @@ export class FilerPage {
533552
}
534553
}
535554
}
555+
_comparetorFiles(a, b) {
556+
// sort by mode(directory or file)
557+
// directory than file
558+
if (a.m < b.m) {
559+
return -1;
560+
} else if (b.m < a.m) {
561+
return 1;
562+
}
563+
// sort by name
564+
if (a.n.hasOwnProperty('localeCompare')) {
565+
const nameCmp = a.n.localeCompare(b.n);
566+
if (nameCmp !== 0) {
567+
// ASC sort
568+
return nameCmp;
569+
}
570+
}
571+
// ASC sort
572+
if (a.n < b.n) {
573+
return -1;
574+
} else if (b.n < a.n) {
575+
return 1;
576+
}
577+
// sort by timestamp
578+
return a.u - b.u;
579+
}
536580
_fetchRemoteFileList(job) {
537581
const curState = appMain.store.getState();
538582
if ((job.response)
@@ -542,49 +586,59 @@ export class FilerPage {
542586
let fetchedDir = curRemoteFiles.filter(dir => {
543587
return dir.path !== job.request.arguments.current_path;
544588
});
545-
job.response.result.sort((a, b) => {
546-
// sort by mode(directory or file)
547-
// directory than file
548-
if (a.m < b.m) {
549-
return -1;
550-
} else if (b.m < a.m) {
551-
return 1;
552-
}
553-
// sort by name
554-
if (a.n.hasOwnProperty('localeCompare')) {
555-
const nameCmp = a.n.localeCompare(b.n);
556-
if (nameCmp !== 0) {
557-
// ASC sort
558-
return nameCmp;
559-
}
560-
}
561-
// ASC sort
562-
if (a.n < b.n) {
563-
return -1;
564-
} else if (b.n < a.n) {
565-
return 1;
566-
}
567-
// sort by timestamp
568-
return a.u - b.u;
589+
let prevDir = curRemoteFiles.filter(dir => {
590+
return dir.path === job.request.arguments.current_path;
569591
});
592+
if (prevDir.length > 0) {
593+
prevDir = prevDir[0];
594+
} else {
595+
prevDir = null;
596+
}
570597
job.response.result.forEach((file, index, array) => {
571598
// Mapping shot protperty to regureler property
572599
array[index].name = file.n;
573600
array[index].mode = file.m;
574601
// formatting modification timestamp
575602
array[index].modification = dateFormat.format(fatDateToDate(file.u), 'yyyy/MM/dd');
576603
});
604+
605+
let nextFiles = job.response.result;
606+
let isMoreFiles = false;
607+
// Cut fetch size
608+
if (nextFiles.length > FlashAIrScript.LIST_FETCH_MAX) {
609+
nextFiles = nextFiles.slice(0, FlashAIrScript.LIST_FETCH_MAX);
610+
isMoreFiles = true;
611+
}
612+
// Add previous directory items
613+
if (prevDir && prevDir.startIndex > 0) {
614+
nextFiles = prevDir.files.concat(nextFiles);
615+
// Remove parent directory item
616+
nextFiles.shift();
617+
// Merge and Uniq
618+
const newFileMap = new Map();
619+
nextFiles.forEach(file => newFileMap.set(file.name, file));
620+
nextFiles.length = 0;
621+
for (let file of newFileMap.values()) {
622+
nextFiles.push(file);
623+
}
624+
}
625+
let remoteFileStartIndex = nextFiles.length;
626+
nextFiles.sort(this._comparetorFiles);
577627
// Add move parent directory item
578-
job.response.result.unshift({
628+
nextFiles.unshift({
579629
name: Filer.files.special.PARENT_DIR,
580630
mode: Filer.files.mode.DIRECTORY,
581631
modification: ''
582632
});
583633
fetchedDir = fetchedDir.concat([{
584634
path: job.request.arguments.current_path,
585-
files: job.response.result
635+
startIndex: remoteFileStartIndex,
636+
files: nextFiles
586637
}]);
587-
this.iotHubAction.updateFiles({remoteFiles: fetchedDir});
638+
this.iotHubAction.updateFiles({
639+
remoteFiles: fetchedDir,
640+
isMoreRemoteFiles: isMoreFiles
641+
});
588642
this.iotHubAction.deleteJob(curState, job)
589643
.catch(message => {
590644
log.error(message);

src/renderer/view/filer_tmpl.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<td class="col-xs-3" id="remote-file-modification-{{name}}">{{modification}}</td>
3737
</tr>
3838
{{/each}}
39+
{{#if isMoreRemoteFiles}}
40+
<tr id="remote-file-row-more-item" data-start-index="{{remoteStartIndex}}">
41+
<td class="col-xs-12 more-item">{{filer_label_remote_show_more}}</td>
42+
</tr>
43+
{{/if}}
3944
</tbody>
4045
</table>
4146
</div>

static/css/file-manager.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
}
2121
.remote-files td:nth-child(2),
2222
.local-files td:nth-child(2) {
23-
text-overflow:ellipsis;
24-
overflow:hidden;
25-
white-space:nowrap;
23+
text-overflow: ellipsis;
24+
overflow: hidden;
25+
white-space: nowrap;
26+
}
27+
.remote-files .more-item {
28+
cursor: pointer;
29+
text-align: center;
2630
}
2731

2832
.fa-dir-button {

0 commit comments

Comments
 (0)