Skip to content

Commit

Permalink
portal experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
kevodwyer committed Jul 19, 2023
1 parent 690f150 commit a941df3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
5 changes: 3 additions & 2 deletions assets/apps/sandbox/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function load(appName, appPath, allowBrowsing, theme, chatId, username, props) {
let iframe = document.getElementById("appSandboxId");
iframe.style.width = '100%';
iframe.style.height = window.innerHeight + 'px';
var appNameInSW = props.appDevMode != null && props.appDevMode == true ? appName + '@APP_DEV_MODE' : appName;
var appNameInSW = props.portal.length > 0 ? props.portal + '@PORTAL_MODE' : appName;
appNameInSW = props.allowUnsafeEvalInCSP != null && props.allowUnsafeEvalInCSP == true ? appNameInSW + '@CSP_UNSAFE_EVAL' : appNameInSW;

let fileStream = streamSaver.createWriteStream(appNameInSW, "text/html", url => {
Expand All @@ -76,7 +76,8 @@ function load(appName, appPath, allowBrowsing, theme, chatId, username, props) {
path = path + '&isPathWritable=' + props.isPathWritable;
}
let src = allowBrowsing ? appPath.substring(1) : "index.html" + path;
iframe.src= src;
let srcPrefix = props.portal.length > 0 ? props.portal + "/" : "";
iframe.src = srcPrefix + src;
iframe.contentWindow.focus();
}, function(seekHi, seekLo, seekLength, streamFilePath){
that.streamFile(seekHi, seekLo, seekLength, streamFilePath);
Expand Down
2 changes: 1 addition & 1 deletion assets/apps/sandbox/sw-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ function appFetch(event) {
if (method == 'PATCH' && "append" != event.request.headers.get('X-Update-Range').toLowerCase()) {
return new Response('X-Update-Range:append header expected', {status: 400})
}
if (method == 'GET' && uniqueId == '' && appName.includes('@APP_DEV_MODE')) {
if (method == 'GET' && uniqueId == '' && appName.includes('@PORTAL_MODE')) {
return event.respondWith(
(async function() {
const responseFromNetwork = await fetch(filePath, { method: 'GET' });
Expand Down
19 changes: 14 additions & 5 deletions src/components/sandbox/AppSandbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ module.exports = {
showFolderPicker: false,
folderPickerBaseFolder: "",
selectedFolders: [],
selectedFolderStems: []
selectedFolderStems: [],
portalName: ''
}
},
computed: {
Expand Down Expand Up @@ -178,8 +179,14 @@ module.exports = {
} else {
let props = this.targetFile.getFileProperties();
let filename = props.name.toLowerCase();
if (filename.endsWith('jpg') || filename.endsWith('png')) {
this.recreateFileThumbnailOnClose = this.targetFile.isWritable();
let portalToken = '.portal';
if (filename.endsWith(portalToken)) {
this.browserMode = false;
this.portalName = filename.substring(0, filename.length - portalToken.length);
} else {
if (filename.endsWith('jpg') || filename.endsWith('png')) {
this.recreateFileThumbnailOnClose = this.targetFile.isWritable();
}
}
}
}
Expand All @@ -201,6 +208,9 @@ module.exports = {
that.fatalError('Application configuration error. See console for further details');
} else {
that.appProperties = props;
if (that.portalName.length == 0) {
that.portalName = props.portal;
}
that.appRegisteredWithFileAssociation = that.appHasFileAssociation(props);
that.appRegisteredWithWildcardFileAssociation = that.appHasWildcardFileRegistration(props);
that.currentChatId = that.sandboxAppChatId != null ? that.sandboxAppChatId : '';
Expand Down Expand Up @@ -404,9 +414,8 @@ module.exports = {
that.resizeHandler();
let theme = that.$store.getters.currentTheme;
let href = window.location.href;
let appDevMode = href.includes("?local-app-dev=true");
let allowUnsafeEvalInCSP = that.permissionsMap.get(that.PERMISSION_CSP_UNSAFE_EVAL) != null;
let props = { appDevMode: appDevMode, allowUnsafeEvalInCSP: allowUnsafeEvalInCSP, isPathWritable: that.isPathWritable()};
let props = { portal: that.portalName, allowUnsafeEvalInCSP: allowUnsafeEvalInCSP, isPathWritable: that.isPathWritable()};
let func = function() {
that.postMessage({type: 'init', appName: that.currentAppName, appPath: that.appPath,
allowBrowsing: that.browserMode, theme: theme, chatId: that.currentChatId,
Expand Down
16 changes: 9 additions & 7 deletions src/mixins/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ module.exports = {
matchingInbuiltApps.push(markdown);
}
if (mimeType.startsWith("text/html") ||
( mimeType.startsWith("text/") && filename.endsWith('.html'))) {
( mimeType.startsWith("text/") && filename.endsWith('.html'))
|| filename.endsWith('.portal')) {
let htmlviewer = {name:"htmlviewer", contextMenuText:'Open in HTML Viewer'};
matchingInbuiltApps.push(htmlviewer);
}
Expand Down Expand Up @@ -164,11 +165,7 @@ module.exports = {
}
var filename = file.getName();
var mimeType = file.getFileProperties().mimeType;
if (mimeType.startsWith("audio") ||
mimeType.startsWith("video") ||
mimeType.startsWith("image")) {
return 'Gallery';
} else if (mimeType === "application/vnd.peergos-todo") {
if (mimeType === "application/vnd.peergos-todo") {
return "Tasks";
} else if (mimeType === "application/pdf") {
return "pdf";
Expand All @@ -180,10 +177,15 @@ module.exports = {
( mimeType.startsWith("text/") && filename.endsWith('.md'))) {
return writable ? "editor" : "markdown";
} else if (mimeType.startsWith("text/html") ||
( mimeType.startsWith("text/") && filename.endsWith('.html'))) {
( mimeType.startsWith("text/") && filename.endsWith('.html'))
|| filename.endsWith('.portal')) {
return writable ? "editor" : "htmlviewer";
} else if (mimeType.startsWith("text/")) {
return "editor";
} else if (mimeType.startsWith("audio") ||
mimeType.startsWith("video") ||
mimeType.startsWith("image")) {
return 'Gallery';
} else {
return "hex";
}
Expand Down
32 changes: 16 additions & 16 deletions src/mixins/sandbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module.exports = {
} else {
let errors = [];
let mandatoryFields = ["displayName", "description", "launchable"];
let existingCreateMenuItems = ["upload files","upload folder","new folder","new file", "new app"];
let validPermissions = ["STORE_APP_DATA", "EDIT_CHOSEN_FILE", "READ_CHOSEN_FOLDER", "EXCHANGE_MESSAGES_WITH_FRIENDS", "CSP_UNSAFE_EVAL"];
mandatoryFields.forEach(field => {
if (props[field] == null) {
Expand All @@ -78,7 +77,7 @@ module.exports = {
if (props.displayName.length > 25) {
errors.push("Invalid displayName property. Length must not exceed 25 characters");
}
if (!that.validateDisplayName(props.displayName)) {
if (!that.validateTextCharacters(props.displayName)) {
errors.push("Invalid displayName property. Use only alphanumeric characters plus dash and underscore");
}
const versionStr = props.version;
Expand All @@ -99,16 +98,6 @@ module.exports = {
if (props.author.length > 32) {
errors.push("Invalid Author property. Length must not exceed 32 characters");
}
if (props.createMenuText != null) {
if (props.createMenuText.length > 25) {
errors.push("Invalid createMenuText property. Length must not exceed 25 characters");
}
let lowercaseText = props.createMenuText.toLowerCase().trim();
let itemIndex = existingCreateMenuItems.findIndex(v => v.name === lowercaseText);
if (itemIndex > -1) {
errors.push("Invalid createMenuText property. Menu text already exists!");
}
}
if (!(props.fileExtensions.constructor === Array)) {
errors.push("Invalid fileExtensions property. Must be an array. Can be empty []");
}
Expand All @@ -118,6 +107,14 @@ module.exports = {
if (!(props.fileTypes.constructor === Array)) {
errors.push("Invalid fileTypes property. Must be an array. Can be empty []");
}
if (props.portal.length > 0) {
if (props.portal.length > 32) {
errors.push("Invalid Portal property. Length must not exceed 32 characters");
}
if (!that.validateTextCharacters(props.portal)) {
errors.push("Invalid portal property. Use only alphanumeric characters plus dash and underscore");
}
}
}
if (errors.length == 0 && appPath != null) {
that.validateAppIconImage(props.appIcon, appPath, errors).thenApply(isIconOK => {
Expand Down Expand Up @@ -160,12 +157,12 @@ module.exports = {
}
return future;
},
validateDisplayName: function(displayName) {
if (displayName === '')
validateTextCharacters: function(text) {
if (text === '')
return false;
if (displayName.includes('.') || displayName.includes('..'))
if (text.includes('.') || text.includes('..'))
return false;
if (!displayName.match(/^[a-z\d\-_\s]+$/i)) {
if (!text.match(/^[a-z\d\-_\s]+$/i)) {
return false;
}
return true;
Expand Down Expand Up @@ -214,6 +211,9 @@ module.exports = {
if (props.permissions == null) {
props.permissions = [];
}
if (props.portal == null) {
props.portal = "";
}
props.name = props.displayName.replaceAll(' ', '').toLowerCase().trim();
future.complete(props);
} catch (ex) {
Expand Down
3 changes: 2 additions & 1 deletion src/views/Drive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ module.exports = {
let file = this.selectedFiles[0];
let mimeType = file.getFileProperties().mimeType;
return mimeType.startsWith("text/html") ||
(mimeType.startsWith("text/") && file.getName().endsWith('.html'));
(mimeType.startsWith("text/") && file.getName().endsWith('.html'))
|| file.getName().endsWith('.portal');
} catch (err) {
return false;
}
Expand Down

0 comments on commit a941df3

Please sign in to comment.