Skip to content

Commit 0fd52d7

Browse files
committed
error handling if invalid url
1 parent e897c95 commit 0fd52d7

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

wami/app.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,21 @@ async function processShareTargetData() {
462462
// Determine flow configuration from share data
463463
const { flowTitle, flowSteps } = determineFlowConfiguration(shareData);
464464

465-
// Create or navigate to the flow
466-
const targetFlow = await createOrNavigateToFlow(flowTitle, flowSteps);
467-
468-
// Load and process the shared images
469-
await loadAndProcessSharedImages(shareCache, shareData);
465+
// If no valid command was found, create an empty flow
466+
if (flowTitle === null || flowSteps === null) {
467+
console.log('Creating empty flow due to invalid URL command');
468+
// Create a new untitled flow with no steps
469+
const newFlow = await createNewFlow('Untitled flow', []);
470+
471+
// Load the images without auto-processing
472+
await loadAndProcessSharedImages(shareCache, shareData, false);
473+
} else {
474+
// Create or navigate to the flow with the specified steps
475+
const targetFlow = await createOrNavigateToFlow(flowTitle, flowSteps);
476+
477+
// Load and process the shared images
478+
await loadAndProcessSharedImages(shareCache, shareData, true);
479+
}
470480

471481
// Clean up cache after processing
472482
await cleanupShareCache(shareCache, shareData);
@@ -480,14 +490,9 @@ async function processShareTargetData() {
480490

481491
// Determines the flow configuration (title and steps) based on shared data
482492
function determineFlowConfiguration(shareData) {
483-
// Default flow title and steps
493+
// Default flow title and steps - only used if no URL is provided
484494
let flowTitle = shareData.title || 'Shared Images Flow';
485-
let flowSteps = [
486-
{
487-
type: 'resize-width-if-larger',
488-
params: [1000]
489-
}
490-
];
495+
let flowSteps = null;
491496

492497
// If URL field exists and starts with web+wami://, use it for configuration
493498
if (shareData.url && shareData.url.trim() !== '') {
@@ -499,10 +504,24 @@ function determineFlowConfiguration(shareData) {
499504
if (result) {
500505
flowTitle = result.title;
501506
flowSteps = result.steps;
507+
} else {
508+
// If URL parsing failed, return null to indicate we should stay on launch page
509+
console.log('Invalid command URL, will not process images');
510+
return { flowTitle: null, flowSteps: null };
502511
}
503512
}
504513
}
505514

515+
// If no web+wami URL was provided, use these default steps
516+
if (flowSteps === null) {
517+
flowSteps = [
518+
{
519+
type: 'resize-width-if-larger',
520+
params: [1000]
521+
}
522+
];
523+
}
524+
506525
return { flowTitle, flowSteps };
507526
}
508527

@@ -549,8 +568,9 @@ function parseWebWamiUrl(url) {
549568
console.log(`Creating resize flow with width ${width}`);
550569
steps = [{ type: 'resize-width-if-larger', params: [width] }];
551570
} else {
552-
// Default to resize-width-if-larger
553-
steps = [{ type: 'resize-width-if-larger', params: [1000] }];
571+
// If no recognized command is found, return null instead of using default steps
572+
console.log(`No recognized command found in URL: ${mainCommand}`);
573+
return null;
554574
}
555575

556576
return { title, steps };
@@ -598,7 +618,7 @@ async function createOrNavigateToFlow(flowTitle, flowSteps) {
598618
}
599619

600620
// Loads shared images from the cache and processes them if needed
601-
async function loadAndProcessSharedImages(shareCache, shareData) {
621+
async function loadAndProcessSharedImages(shareCache, shareData, shouldAutoProcess = true) {
602622
const imagesToStore = [];
603623

604624
// Load the shared files from cache
@@ -637,13 +657,14 @@ async function loadAndProcessSharedImages(shareCache, shareData) {
637657
return { src: URL.createObjectURL(image.file), name: image.file.name };
638658
}));
639659

640-
// Automatically run the flow
641-
const shouldAutoProcess = true;
660+
// Automatically run the flow only if requested
642661
if (shouldAutoProcess) {
643662
console.log('Auto-processing images...');
644663
setTimeout(() => {
645664
runFlowButton.click();
646665
}, 500);
666+
} else {
667+
console.log('Images loaded but not auto-processing due to invalid command');
647668
}
648669
}
649670
}

0 commit comments

Comments
 (0)