Skip to content

fix: improve onLaunchedWithItems to prevent information loss #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/gui/src/helpers/launch_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,14 @@ const launch_app = async (options)=>{
}

if(file_signature){
// Only pass the file UUID to the app, and let onLaunchedWithItems
// fetch the complete file information via puter.js
iframe_url.searchParams.append('puter.item.uid', file_signature.uid);
iframe_url.searchParams.append('puter.item.path', privacy_aware_path(options.file_path) || file_signature.path);
iframe_url.searchParams.append('puter.item.name', file_signature.fsentry_name);
iframe_url.searchParams.append('puter.item.read_url', file_signature.read_url);
iframe_url.searchParams.append('puter.item.write_url', file_signature.write_url);
iframe_url.searchParams.append('puter.item.metadata_url', file_signature.metadata_url);
iframe_url.searchParams.append('puter.item.size', file_signature.fsentry_size);
iframe_url.searchParams.append('puter.item.accessed', file_signature.fsentry_accessed);
iframe_url.searchParams.append('puter.item.modified', file_signature.fsentry_modified);
iframe_url.searchParams.append('puter.item.created', file_signature.fsentry_created);
}
else if(options.readURL){
iframe_url.searchParams.append('puter.item.name', options.filename);
iframe_url.searchParams.append('puter.item.path', privacy_aware_path(options.file_path));
iframe_url.searchParams.append('puter.item.read_url', options.readURL);
else if(options.readURL && options.file_uid){
// Only pass the file UUID to the app, and let onLaunchedWithItems
// fetch the complete file information via puter.js
iframe_url.searchParams.append('puter.item.uid', options.file_uid);
}

// In godmode, we add the super token to the iframe URL
Expand Down
34 changes: 16 additions & 18 deletions src/puter-js/src/modules/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,24 +605,22 @@ class UI extends EventListener {
// the URL parameters will be checked every time the callback is set which can cause problems if the callback is set multiple times.
if(!this.#onLaunchedWithItems){
let URLParams = new URLSearchParams(window.location.search);
if(URLParams.has('puter.item.name') && URLParams.has('puter.item.uid') && URLParams.has('puter.item.read_url')){
let fpath = URLParams.get('puter.item.path');

if(!fpath.startsWith('~/') && !fpath.startsWith('/'))
fpath = '~/' + fpath;

callback([new FSItem({
name: URLParams.get('puter.item.name'),
path: fpath,
uid: URLParams.get('puter.item.uid'),
readURL: URLParams.get('puter.item.read_url'),
writeURL: URLParams.get('puter.item.write_url'),
metadataURL: URLParams.get('puter.item.metadata_url'),
size: URLParams.get('puter.item.size'),
accessed: URLParams.get('puter.item.accessed'),
modified: URLParams.get('puter.item.modified'),
created: URLParams.get('puter.item.created'),
})]);
if(URLParams.has('puter.item.uid')){
const fileUID = URLParams.get('puter.item.uid');

// Fetch the complete file information using the UID
puter.fs.stat({ uid: fileUID })
.then(fileInfo => {
// Create an FSItem with the complete information
callback([new FSItem(fileInfo)]);
})
.catch(error => {
console.error('Error fetching file information:', error);
// If there's an error, still call the callback with the minimal information
callback([new FSItem({
uid: fileUID
})]);
});
}
}

Expand Down