mirror of
https://github.com/xlmnxp/extractify.zip.git
synced 2024-11-23 17:13:12 +03:00
support docx and remove unnecessary sorting
This commit is contained in:
parent
93a42b6458
commit
f3e4f4923a
@ -59,10 +59,10 @@ export class FilesManager {
|
|||||||
|
|
||||||
// sort unorganized files by depth
|
// sort unorganized files by depth
|
||||||
unorganizedFiles = unorganizedFiles.sort((a, b) => {
|
unorganizedFiles = unorganizedFiles.sort((a, b) => {
|
||||||
const aPathArray = a.path.split("/");
|
const aPathArrayLength = (a.path.match(/\//g) || []).length;
|
||||||
const bPathArray = b.path.split("/");
|
const bPathArrayLength = (b.path.match(/\//g) || []).length;
|
||||||
if (aPathArray.length > bPathArray.length) return -1;
|
if (aPathArrayLength > bPathArrayLength) return -1;
|
||||||
if (aPathArray.length < bPathArray.length) return 1;
|
if (aPathArrayLength < bPathArrayLength) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -71,8 +71,17 @@ export class FilesManager {
|
|||||||
for (let file of unorganizedFiles) {
|
for (let file of unorganizedFiles) {
|
||||||
// get parent folder file
|
// get parent folder file
|
||||||
const parentPath = file.path.substring(0, file.path.lastIndexOf("/"));
|
const parentPath = file.path.substring(0, file.path.lastIndexOf("/"));
|
||||||
const parentFolderFile = pathArrays[parentPath] || unorganizedFiles.find(_file => _file.path === parentPath);
|
let parentFolderFile = pathArrays[parentPath] || unorganizedFiles.find(_file => _file.path === parentPath);
|
||||||
if (!parentFolderFile) continue;
|
if (!parentFolderFile) {
|
||||||
|
unorganizedFiles.push({
|
||||||
|
name: parentPath.substring(parentPath.lastIndexOf('/') + 1),
|
||||||
|
path: parentPath,
|
||||||
|
isFolder: true,
|
||||||
|
content: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
parentFolderFile = unorganizedFiles.find(_file => _file.path === parentPath);
|
||||||
|
};
|
||||||
|
|
||||||
// add file to parent folder content
|
// add file to parent folder content
|
||||||
if (!parentFolderFile.content) parentFolderFile.content = [];
|
if (!parentFolderFile.content) parentFolderFile.content = [];
|
||||||
@ -81,20 +90,18 @@ export class FilesManager {
|
|||||||
// cache split path array to avoid calling split() multiple times
|
// cache split path array to avoid calling split() multiple times
|
||||||
const pathArray = pathArrays[file.path] || file.path.split("/");
|
const pathArray = pathArrays[file.path] || file.path.split("/");
|
||||||
pathArrays[file.path] = pathArray;
|
pathArrays[file.path] = pathArray;
|
||||||
|
|
||||||
parentFolderFile.content = parentFolderFile.content.sort((a:any, b:any) => {
|
|
||||||
// sort by folder and from a to z
|
|
||||||
if (a.isFolder && !b.isFolder) return -1;
|
|
||||||
if (!a.isFolder && b.isFolder) return 1;
|
|
||||||
if (a.name < b.name) return -1;
|
|
||||||
if (a.name > b.name) return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove folders from root
|
// remove folders from root
|
||||||
const files = unorganizedFiles.filter(file => (file.path.match(/\//g) || []).length == 1);
|
const files = unorganizedFiles.filter(file => (file.path.match(/\//g) || []).length == 1).sort((a:any, b:any) => {
|
||||||
console.log({files});
|
// sort by folder and from a to z
|
||||||
|
if (a.isFolder && !b.isFolder) return -1;
|
||||||
|
if (!a.isFolder && b.isFolder) return 1;
|
||||||
|
if (a.name < b.name) return -1;
|
||||||
|
if (a.name > b.name) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
this.filesList.value = files;
|
this.filesList.value = files;
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
@ -123,13 +130,29 @@ export class FilesManager {
|
|||||||
getFile(path: string, innerList = undefined): any {
|
getFile(path: string, innerList = undefined): any {
|
||||||
if (path == "/") {
|
if (path == "/") {
|
||||||
return {
|
return {
|
||||||
content: this.filesList.value,
|
content: this.filesList.value.sort((a:any, b:any) => {
|
||||||
|
// sort by folder and from a to z
|
||||||
|
if (a.isFolder && !b.isFolder) return -1;
|
||||||
|
if (!a.isFolder && b.isFolder) return 1;
|
||||||
|
if (a.name < b.name) return -1;
|
||||||
|
if (a.name > b.name) return 1;
|
||||||
|
return 0;
|
||||||
|
}),
|
||||||
isFolder: true,
|
isFolder: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of (innerList || this.filesList.value)) {
|
for (const file of (innerList || this.filesList.value)) {
|
||||||
if (file.path == path) {
|
if (file.path == path) {
|
||||||
|
file.content = file.content.sort((a:any, b:any) => {
|
||||||
|
// sort by folder and from a to z
|
||||||
|
if (a.isFolder && !b.isFolder) return -1;
|
||||||
|
if (!a.isFolder && b.isFolder) return 1;
|
||||||
|
if (a.name < b.name) return -1;
|
||||||
|
if (a.name > b.name) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user