Skip to content

Commit

Permalink
Merge pull request #586 from Peergos/fix/misc-app-improvements
Browse files Browse the repository at this point in the history
App improvements
  • Loading branch information
ianopolous authored May 23, 2024
2 parents a1d5be7 + 1b9d251 commit f6788b5
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 139 deletions.
6 changes: 3 additions & 3 deletions src/components/picker/FilePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
fileThumbnail : ''
}
},
props: ['baseFolder', 'selectedFile_func', 'pickerFileExtension', 'pickerFilterMedia', 'pickerShowThumbnail'],
props: ['baseFolder', 'selectedFile_func', 'pickerFileExtension', 'pickerFilterMedia', 'pickerShowThumbnail', 'pickerFilters'],
mixins:[folderTreeMixin],
computed: {
...Vuex.mapState([
Expand All @@ -74,7 +74,7 @@ module.exports = {
that.showSpinner = false;
that.spinnerMessage = '';
};
this.loadSubFoldersAndFiles(this.baseFolder + "/", this.pickerFileExtension, this.pickerFilterMedia, callback);
this.loadSubFoldersAndFiles(this.baseFolder + "/", this.pickerFileExtension, this.pickerFilterMedia, this.pickerFilters, callback);
},
methods: {
close: function () {
Expand All @@ -99,7 +99,7 @@ module.exports = {
this.showSpinner = false;
},
loadFolderLazily: function(path, callback) {
this.loadSubFoldersAndFiles(path, this.pickerFileExtension, this.pickerFilterMedia, callback);
this.loadSubFoldersAndFiles(path, this.pickerFileExtension, this.pickerFilterMedia, this.pickerFilters, callback);
},
fileSelected: function() {
this.selectedFile_func(this.selectedFile);
Expand Down
4 changes: 3 additions & 1 deletion src/components/sandbox/AppSandbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
:baseFolder="filePickerBaseFolder"
:pickerFileExtension="pickerFileExtension"
:pickerFilterMedia="pickerFilterMedia"
:pickerFilters="pickerFilters"
:pickerShowThumbnail="pickerShowThumbnail"
:selectedFile_func="selectedFileFromPicker"
/>
Expand Down Expand Up @@ -182,6 +183,7 @@ module.exports = {
selectedFileFromPicker: null,
pickerFileExtension: "",
pickerFilterMedia: false,
pickerFilters: null,
pickerShowThumbnail: false,
commandQueue: [],
executingCommands: false,
Expand Down Expand Up @@ -534,7 +536,7 @@ module.exports = {
that.showError('Path not accessible: ' + streamFilePath);
} else {
var prefix = '';
if (!this.browserMode && streamFilePath != this.appPath) {
if (!this.browserMode && !streamFilePath.startsWith(this.appPath)) {
if(streamFilePath.startsWith(that.apiRequest + '/data')) {
streamFilePath = streamFilePath.substring(that.apiRequest.length);
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/mixins/sandbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,13 @@ module.exports = {
&& props.fileExtensions[0].trim().length > 0
&& props.fileExtensions[0] != '*';
let createFile = editPermission && hasFileExtensions;
let openFile = props.launchable && !props.folderAction && !createFile
&& (props.fileExtensions.length > 0 || props.mimeTypes.length > 0 || props.fileTypes.length > 0);
let openFileFilters = {fileExtensions: props.fileExtensions, mimeTypes: props.mimeTypes, fileTypes: props.fileTypes};
let primaryFileExtension = hasFileExtensions ? props.fileExtensions[0] : '';

let item = {name: props.name, displayName: props.displayName,
createFile: createFile, launchable: props.launchable,
createFile: createFile, openFile: openFile, openFileFilters: openFileFilters, launchable: props.launchable,
folderAction: props.folderAction, appIcon: props.appIcon, contextMenuText: contextMenuText,
source: props.source, version: props.version, createFile: createFile, primaryFileExtension: primaryFileExtension};

Expand Down
142 changes: 33 additions & 109 deletions src/mixins/tree-walker/index.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,20 @@
module.exports = {
methods: {
loadFoldersAndFiles: function(path, fileExtension, filterMedia, callback) {
this.loadAllFolders(path, callback, true, fileExtension, filterMedia);
},
loadSubFoldersAndFiles: function(path, fileExtension, filterMedia, callback) {
this.loadSubFoldersNotRecursive(path, callback, true, fileExtension, filterMedia);
},
loadFolders: function(path, callback) {
this.loadAllFolders(path, callback, false, '', false);
loadSubFoldersAndFiles: function(path, fileExtension, filterMedia, fileFilters, callback) {
this.loadSubFoldersNotRecursive(path, callback, true, fileExtension, filterMedia, fileFilters);
},
loadSubFolders: function(path, callback) {
this.loadSubFoldersNotRecursive(path, callback, false, '', false);
},
loadAllFolders: function(path, callback, includeFiles, fileExtension, filterMedia) {
var that = this;
let folderTree = {};
this.context.getByPath(path).thenApply(function(dirOpt){
let dir = dirOpt.get();
let folderProperties = dir.getFileProperties();
if (folderProperties.isDirectory && !folderProperties.isHidden) {
that.walk(dir, path, folderTree, includeFiles, fileExtension, filterMedia).thenApply( () => {
callback(folderTree);
});
} else {
callback(folderTree);
}
}).exceptionally(function(throwable) {
this.spinnerMessage = 'Unable to load folders...';
throwable.printStackTrace();
});
this.loadSubFoldersNotRecursive(path, callback, false, '', false, null);
},

walk: function(file, path, currentTreeData, includeFiles, fileExtension, filterMedia) {
currentTreeData.path = path.substring(0, path.length -1);
currentTreeData.children = [];
currentTreeData.isOpen = false;
let that = this;
let future = peergos.shared.util.Futures.incomplete();
file.getChildren(that.context.crypto.hasher, that.context.network).thenApply(function(children) {
let arr = children.toArray();
let funcArray = [];
arr.forEach(function(child, index){
let childProps = child.getFileProperties();
let newPath = childProps.isDirectory ? path + child.getFileProperties().name + '/' : path;
if (childProps.isDirectory && !childProps.isHidden) {
let node = {};
currentTreeData.children.push(node);
funcArray.push(() => {
return that.walk(child, newPath, node, includeFiles, fileExtension, filterMedia);
});
}
if (includeFiles === true && !childProps.isDirectory && !childProps.isHidden) {
let testAcceptAll = (fileExtension == null || fileExtension.length == 0 ) && !filterMedia;
var matchExtension = false;
if (!testAcceptAll ) {
if (filterMedia) {
let mimeType = childProps.mimeType;
matchExtension = mimeType.startsWith("image") || mimeType.startsWith("video");
}
if (!matchExtension) {
let extensions = fileExtension.split(',').filter(e => e.length > 0).map(i => i.toLowerCase().trim());
let matches = extensions.filter(ext => child.getFileProperties().name.toLowerCase().endsWith(ext));
matchExtension = matches.length > 0;
}
}
if (testAcceptAll || matchExtension) {
let node = {};
currentTreeData.children.push(node);
funcArray.push(() => {
return that.addFile(child, newPath, node);
});
}
}
});
if (funcArray.length > 0) {
let completed = {count: 0};
funcArray.forEach((func, idx) => {
func().thenApply(() => {
completed.count ++;
if (completed.count == funcArray.length) {
future.complete(true);
}
});
});
} else {
future.complete(true);
}
});
return future;
},
addFile(file, path, currentTreeData) {
let future = peergos.shared.util.Futures.incomplete();
currentTreeData.path = path + file.getName();
currentTreeData.children = [];
currentTreeData.isLeaf = true;
currentTreeData.isOpen = false;
future.complete(true);
return future;
},
loadSubFoldersNotRecursive: function(path, callback, includeFiles, fileExtension, filterMedia) {
loadSubFoldersNotRecursive: function(path, callback, includeFiles, fileExtension, filterMedia, fileFilters) {
var that = this;
let folderTree = {};
this.context.getByPath(path).thenApply(function(dirOpt){
let dir = dirOpt.get();
let folderProperties = dir.getFileProperties();
if (folderProperties.isDirectory && !folderProperties.isHidden) {
that.walkNotRecursive(dir, path, folderTree, includeFiles, fileExtension, filterMedia).thenApply( () => {
that.walkNotRecursive(dir, path, folderTree, includeFiles, fileExtension, filterMedia, fileFilters).thenApply( () => {
callback(folderTree);
});
} else {
Expand All @@ -117,7 +26,7 @@ module.exports = {
});
},

walkNotRecursive: function(file, path, currentTreeData, includeFiles, fileExtension, filterMedia) {
walkNotRecursive: function(file, path, currentTreeData, includeFiles, fileExtension, filterMedia, fileFilters) {
currentTreeData.path = path.substring(0, path.length -1);
currentTreeData.children = [];
currentTreeData.isOpen = false;
Expand All @@ -137,20 +46,35 @@ module.exports = {
currentTreeData.children.push(node);
}
if (includeFiles === true && !childProps.isDirectory && !childProps.isHidden) {
let testAcceptAll = (fileExtension == null || fileExtension.length == 0 ) && !filterMedia;
var matchExtension = false;
if (!testAcceptAll ) {
if (filterMedia) {
let mimeType = childProps.mimeType;
matchExtension = mimeType.startsWith("image") || mimeType.startsWith("video");
}
if (!matchExtension) {
let extensions = fileExtension.split(',').filter(e => e.length > 0).map(i => i.toLowerCase().trim());
let matches = extensions.filter(ext => child.getFileProperties().name.toLowerCase().endsWith(ext));
matchExtension = matches.length > 0;
var fileMatch = false;
if (fileFilters != null) { //{fileExtensions: app.fileExtensions, mimeTypes: app.mimeTypes, fileTypes: app.fileTypes}
let wildcardInclude = fileFilters.fileExtensions.length == 1 && fileFilters.fileExtensions[0] == '*'
|| fileFilters.mimeTypes.length == 1 && fileFilters.mimeTypes[0] == '*'
|| fileFilters.fileTypes.length == 1 && fileFilters.fileTypes[0] == '*'
let props = child.getFileProperties();
let filename = props.name.toLowerCase().trim();
let extensionMatches = fileFilters.fileExtensions.filter(ext => filename.endsWith(ext.toLowerCase().trim())).length > 0;
let mimeTypesMatches = fileFilters.mimeTypes.filter(mimeType => props.mimeType == mimeType).length > 0;
let fileType = props.getType();
let fileTypesMatches = fileFilters.fileTypes.filter(ft => fileType == ft).length > 0;
fileMatch = wildcardInclude || extensionMatches || mimeTypesMatches || fileTypesMatches;
} else {
let testAcceptAll = (fileExtension == null || fileExtension.length == 0 ) && !filterMedia;
var matchExtension = false;
if (!testAcceptAll ) {
if (filterMedia) {
let mimeType = childProps.mimeType;
matchExtension = mimeType.startsWith("image") || mimeType.startsWith("video");
}
if (!matchExtension) {
let extensions = fileExtension.split(',').filter(e => e.length > 0).map(i => i.toLowerCase().trim());
let matches = extensions.filter(ext => child.getFileProperties().name.toLowerCase().endsWith(ext));
matchExtension = matches.length > 0;
}
}
fileMatch = testAcceptAll || matchExtension;
}
if (testAcceptAll || matchExtension) {
if (fileMatch) {
let node = {};
node.path = newPath + child.getName();
node.children = [];
Expand Down
61 changes: 38 additions & 23 deletions src/views/Drive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -943,29 +943,44 @@ module.exports = {
this.context.getEntryPath().thenApply(function (linkPath) {
var path = that.initPath == null ? null : decodeURIComponent(that.initPath);
if (path != null && (path.startsWith(linkPath) || linkPath.startsWith(path))) {
that.$store.commit('SET_PATH', path.split('/').filter(n => n.length > 0))
if (that.download || that.open) {
that.context.getByPath(path)
.thenApply(function (file) {
if (! file.get().isDirectory()) {
if (that.download) {
that.downloadFile(file.get());
} else if (that.open) {
var open = () => {
const filename = file.get().getName();
that.selectedFiles = that.files.filter(f => f.getName() == filename);
var app = that.getApp(file.get(), path, false);
that.openInApp({filename:filename}, app);
that.openFileOrDir(app, that.getPath, {filename:filename}, false);
};
that.onUpdateCompletion.push(open);
}
} else {
let app = that.getApp(file.get(), linkPath);
that.openFileOrDir(app, linkPath, {path:path});
}
});
}
that.$store.commit('SET_PATH', path.split('/').filter(n => n.length > 0))
if (that.download || that.open) {
that.context.getByPath(path)
.thenApply(function (file) {
if (! file.get().isDirectory()) {
if (that.download) {
that.downloadFile(file.get());
} else if (that.open) {
var open = () => {
const filename = file.get().getName();
that.selectedFiles = that.files.filter(f => f.getName() == filename);
var app = that.getApp(file.get(), path, false);
that.openInApp({filename:filename}, app);
that.openFileOrDir(app, that.getPath, {filename:filename}, false);
};
that.onUpdateCompletion.push(open);
}
} else {
let app = that.getApp(file.get(), linkPath);
that.openFileOrDir(app, linkPath, {path:path});
}
});
} else if(path.startsWith("/peergos/recommended-apps")) {
let appPath = "/peergos/recommended-apps/";
that.context.getByPath(appPath + "index.html").thenApply(file => {
if (file.ref != null) {
var openRecApps = () => {
const filename = "index.html";
that.selectedFiles = that.files.filter(f => f.getName() == filename);
that.showAppSandbox = true;
that.sandboxAppName = '$$app-gallery$$';
that.currentFile = file.ref;
that.currentPath = appPath;
};
that.onUpdateCompletion.push(openRecApps);
}
});
}
} else {
that.$store.commit('SET_PATH', linkPath.split('/').filter(n => n.length > 0))
if (that.download) {
Expand Down
Loading

0 comments on commit f6788b5

Please sign in to comment.