Skip to content

Commit e897c95

Browse files
committed
modify comments
1 parent 421c989 commit e897c95

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

wami/app.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ browseImagesButton.addEventListener('click', async e => {
285285

286286
for (const file of files) {
287287
imagesToStore.push({
288-
file, // <-- The original file object keeps its name
288+
file,
289289
fsHandlePromise: Promise.resolve(null)
290290
});
291291
resolve();
@@ -365,7 +365,7 @@ saveImagesButton.addEventListener('click', async e => {
365365
}
366366

367367
// If the input images were cloned, we can't save the new images
368-
// back to disk. They don't have a handle. Bail out for now.
368+
// back to disk. They don't have a handle. Just bail out for now.
369369
if (currentImages.length !== outputImages.length) {
370370
return;
371371
}
@@ -422,7 +422,7 @@ viewImagesButton.addEventListener('click', async e => {
422422
imageViewer.show();
423423

424424
// 2 modes: either we matching inputs and outputs in which case we can
425-
// go into the swipe mode. Or we don't, in which case we show the
425+
// go into the swipe mode. Or we don't, in which case we just show the
426426
// output images.
427427
if (input.length === output.length) {
428428
imageViewer.populateFromInputAndOutput(input, output);
@@ -478,9 +478,7 @@ async function processShareTargetData() {
478478
window.history.replaceState({}, document.title, window.location.pathname);
479479
}
480480

481-
/**
482-
* Determines the flow configuration (title and steps) based on shared data
483-
*/
481+
// Determines the flow configuration (title and steps) based on shared data
484482
function determineFlowConfiguration(shareData) {
485483
// Default flow title and steps
486484
let flowTitle = shareData.title || 'Shared Images Flow';
@@ -508,9 +506,7 @@ function determineFlowConfiguration(shareData) {
508506
return { flowTitle, flowSteps };
509507
}
510508

511-
/**
512-
* Parses a web+wami:// URL to extract flow configuration
513-
*/
509+
// Parses a web+wami:// URL to extract flow configuration
514510
function parseWebWamiUrl(url) {
515511
// Extract the part after web+wami://
516512
const urlPath = url.substring('web+wami://'.length);
@@ -560,9 +556,7 @@ function parseWebWamiUrl(url) {
560556
return { title, steps };
561557
}
562558

563-
/**
564-
* Creates a new flow or navigates to an existing flow with the same name
565-
*/
559+
// Creates a new flow or navigates to an existing flow with the same name
566560
async function createOrNavigateToFlow(flowTitle, flowSteps) {
567561
// Only auto-process if title contains ai-action
568562
const shouldAutoProcess = true;
@@ -603,9 +597,7 @@ async function createOrNavigateToFlow(flowTitle, flowSteps) {
603597
return targetFlow;
604598
}
605599

606-
/**
607-
* Loads shared images from the cache and processes them if needed
608-
*/
600+
// Loads shared images from the cache and processes them if needed
609601
async function loadAndProcessSharedImages(shareCache, shareData) {
610602
const imagesToStore = [];
611603

@@ -615,17 +607,23 @@ async function loadAndProcessSharedImages(shareCache, shareData) {
615607
if (fileResponse) {
616608
const blob = await fileResponse.blob();
617609

618-
// Get the original file name from the shareData.fileNames array
619-
// This is more reliable than trying to extract it from the blob
620-
const fileName = (shareData.fileNames && shareData.fileNames[i]) ||
621-
`shared-${i + 1}.${getFileExtension(blob.type)}`;
610+
// Use the exact original filename stored in the shareData
611+
let fileName;
612+
613+
if (shareData.fileNames && shareData.fileNames[i]) {
614+
fileName = shareData.fileNames[i];
615+
console.log(`Using original file name: ${fileName}`);
616+
} else {
617+
// Only fall back if absolutely necessary
618+
fileName = `shared-${i + 1}.${getFileExtension(blob.type)}`;
619+
console.log(`No filename found, using fallback: ${fileName}`);
620+
}
622621

623-
// Create a File object with the original name
624622
const file = new File([blob], fileName, { type: blob.type });
625623

626624
imagesToStore.push({
627625
file,
628-
name: file.name,
626+
name: fileName,
629627
fsHandlePromise: Promise.resolve(null)
630628
});
631629
}
@@ -650,9 +648,7 @@ async function loadAndProcessSharedImages(shareCache, shareData) {
650648
}
651649
}
652650

653-
/**
654-
* Cleans up the share cache after processing
655-
*/
651+
// Cleans up the share cache after processing
656652
async function cleanupShareCache(shareCache, shareData) {
657653
await shareCache.delete('shareData');
658654
for (let i = 0; i < shareData.fileCount; i++) {

wami/sw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ self.addEventListener('fetch', event => {
121121
// Store the files in a temporary cache for the client to access
122122
const shareCache = await caches.open('share-target-cache');
123123

124-
// Extract file names and store them in the shareData
124+
// Store original file names explicitly
125125
const fileNames = files.map(file => file.name);
126126

127-
// Create share data object with file names array
127+
// Create an object with the share data including file names
128128
const shareData = {
129129
title: data.title,
130130
text: data.text,
131131
url: data.url,
132132
timestamp: Date.now(),
133133
fileCount: files.length,
134-
fileNames: fileNames // Store file names in the share data
134+
fileNames: fileNames
135135
};
136136

137137
// Store the share data

0 commit comments

Comments
 (0)