Skip to content

Commit

Permalink
style: further improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorosty committed Feb 17, 2024
1 parent fd0efc9 commit 8cd353a
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
.catch(error => dialog('error', error, __('MSG_UPLOAD_ERROR')));
};

const getUploadData = async (items) => {
const getUploadList = async (items) => {
/*
type: [{dirPath: string, file?: any}]
Directories do not have the `file` property.
Expand All @@ -322,20 +322,6 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
*/
const uploadList = [];

let totalSize = 0;
let title;

const checkFile = (file, dirPath) => {
uploadList.push({dirPath, file});
totalSize += file.size;
if (title === undefined) {
title = file.name;
} else if (title) {
// we've got multiple titles; reset the value
title = '';
}
};

const getDirectoryEntries = (directory) => {
const reader = directory.createReader();
return new Promise(resolve => {
Expand All @@ -361,7 +347,7 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
for (let entry of entries) {
if (entry.isFile) {
const file = await getFileFromEntry(entry);
checkFile(file, dirPath);
uploadList.push({dirPath, file});
} else if (entry.isDirectory) {
const subDirPath = dirPath + '/' + entry.name;
await checkDirectory(entry, subDirPath);
Expand All @@ -375,7 +361,7 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
if (entry.isFile) {
const file = item.getAsFile();
const dirPath = '';
checkFile(file, dirPath);
uploadList.push({dirPath, file});
} else if (entry.isDirectory) {
await checkDirectory(entry, entry.name);
}
Expand All @@ -384,20 +370,16 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
console.warn(error);
}

return { uploadList, totalSize, title };
return uploadList;
}

Check failure on line 374 in index.js

View workflow job for this annotation

GitHub Actions / Lint tests (node latest)

Missing semicolon

const uploadBrowserFiles = async (items) => {
if (!supportsUploadingFolders) {
return legacyUploadBrowserFiles(items);
}

const { uploadList, totalSize, title } = await getUploadData(items);

const d = dialog('progress', title || 'multiple files');
const uploadFileAndFolderList = async (list) => {
const files = list.map(({file}) => file).filter((file) => file);
const totalSize = files.reduce((sum, {size}) => sum + size, 0);
const d = dialog('progress', files.length === 1 ? files[0].name : 'multiple files');
try {
let uploaded = 0;
for (let {dirPath, file} of uploadList) {
for (let {dirPath, file} of list) {
if (file) {
// upload file
await vfs.writefile({
Expand All @@ -414,11 +396,20 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
await vfs.mkdir({path: pathJoin(state.currentPath.path, dirPath)}, {pid: proc.pid});
}
}
refresh(items[0].name); // FIXME: Select all ?
} catch (error) {
dialog('error', error, __('MSG_UPLOAD_ERROR'));
}
d.destroy();
}

Check failure on line 403 in index.js

View workflow job for this annotation

GitHub Actions / Lint tests (node latest)

Missing semicolon

const uploadBrowserFiles = async (items) => {

Check warning on line 405 in index.js

View workflow job for this annotation

GitHub Actions / Lint tests (node latest)

Expected to return a value at the end of async arrow function
if (!supportsUploadingFolders) {
return legacyUploadBrowserFiles(items);
}

const uploadList = await getUploadList(items);
await uploadFileAndFolderList(uploadList);
refresh(items[0].name); // FIXME: Select all ?
};

const uploadVirtualFile = (data) => {
Expand Down

0 comments on commit 8cd353a

Please sign in to comment.