Skip to content

Commit ac32868

Browse files
committed
fix(play): the saving tab is opened only where every file is at an address, by the package's weight and not the video's (#102)
1 parent f71698b commit ac32868

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The site of the [missing-elements](https://github.com/missing-elements) web comp
99
| `/` | The project list, the tools (the build page first, with its how-to), and a footer of links | [src/index.njk](src/index.njk); the lists are in [src/_data/site.js](src/_data/site.js) |
1010
| `/pdfjs-viewer/` | The docs of `<pdfjs-viewer-element>`, with a live preview | [src/pdfjs-viewer/](src/pdfjs-viewer/) |
1111
| `/h5p/build/` | The build page, for people: what it makes, a sample that plays, and the build of a chat's source into a `.h5p`, in the visitor's browser | [src/h5p/build/](src/h5p/build/) |
12-
| `/h5p/play/` | The play page, for a chat app to show in its reply (h5p-toolkit#210); no page links to it. It builds the activity in a link's `#source=` in the visitor's browser, as the build page does, and plays it with nothing beside it but its download and a link to the build page. A file of the visitor's own that the source names is chosen there or given by the page that frames it. A video or a recording can be given as its address: it plays from there at once and is fetched whole only for the download. A framing page that saves files itself is handed the download. A package bigger than that page saves stays behind the Download link, and the page says how to save it from such a frame. A framing page that opens links itself is handed the link to the build page. A link to the page may also carry the files' addresses and a wish to save (`&links=`, `&save=1`): the page then fetches them itself and saves the package with no press, which is how a framing page that opens links gets a package saved that it cannot save itself. | [src/h5p/play/](src/h5p/play/) |
12+
| `/h5p/play/` | The play page, for a chat app to show in its reply (h5p-toolkit#210); no page links to it. It builds the activity in a link's `#source=` in the visitor's browser, as the build page does, and plays it with nothing beside it but its download and a link to the build page. A file of the visitor's own that the source names is chosen there or given by the page that frames it. A video or a recording can be given as its address: it plays from there at once and is fetched whole only for the download. A framing page that saves files itself is handed the download. A package bigger than that page saves stays behind the Download link, and the page says how to save it from such a frame. A framing page that opens links itself is handed the link to the build page. A link to the page may also carry the files' addresses and a wish to save (`&links=`, `&save=1`): the page then fetches them itself and tries to save the package with no press, saying to press Download where the browser saved nothing. That is how a framing page that opens links gets a package saved that it cannot save itself. | [src/h5p/play/](src/h5p/play/) |
1313
| `/h5p/create-with-ai/` | The how-to, for people: installing the skill, asking a chat, the prompts to start from, the types, and what to do when something goes wrong | [src/h5p/create-with-ai/](src/h5p/create-with-ai/) |
1414
| `/h5p/skill/` | The skill as zips to install: `h5p-author.zip`, installed once in a chat's place for skills, or attached to the message in each new chat where it has none, and `h5p-author-chatgpt.zip`, the same skill laid out as a plugin; and a page that lists them and the bundles' addresses, each in full, which no page links to | [src/h5p/skill/](src/h5p/skill/); the zips written by [vite.config.ts](vite.config.ts) |
1515
| `/h5p/bundles/` | The skill's build tool and a library bundle per content type, for a chat that runs Node but cannot reach npm; and `h5p-author-build.tar.gz`, the tool and every library in one archive, for a person to attach to a chat whose code can download nothing | written by [vite.config.ts](vite.config.ts) |

‎src/h5p/play/play-page.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ let hostOpens = false
122122
/** The address each file of the preview plays from, by its path in the source, and the sizes the parent gave, by address. */
123123
let shownFrom: Record<string, string> = {}
124124
const sizeAt = new Map<string, number>()
125+
/** What the preview's package weighs without those files: its libraries and its content. */
126+
let previewWeighs = 0
125127
/** What the link carried beside its source: addresses, and the wish to save with no press. Read once, and taken out of the address bar. */
126128
const carried = linksFromFragment(location.hash)
127129
if (carried.rest !== location.hash) history.replaceState(null, '', `${location.pathname}${location.search}${carried.rest}`)
@@ -326,9 +328,14 @@ function saying(text: string, { busy = false } = {}): void {
326328
announce(text)
327329
}
328330

329-
/** What the files of a preview weigh, where the parent said for each: the package is that and a little. */
331+
/**
332+
* What the package to keep will weigh, about: the preview's own package and the files it plays
333+
* from addresses, where the parent said what each weighs. `null` where it did not, and where a
334+
* file of the activity is here and not at an address: a tab could not fetch that one.
335+
*/
330336
function previewSize(): number | null {
331-
let total = 0
337+
if (previewed.length !== wanted.length) return null
338+
let total = previewWeighs
332339
for (const path of previewed) {
333340
const size = sizeAt.get(shownFrom[path] ?? '')
334341
if (size === undefined) return null
@@ -514,6 +521,7 @@ async function play(): Promise<void> {
514521
const file = new File([result.blob], name, { type: 'application/zip' })
515522
previewed = result.linked
516523
shownFrom = linked
524+
previewWeighs = result.blob.size
517525
download.hidden = false
518526
if (previewed.length) {
519527
// A preview is not a file to hand out: its address expires. Download fetches the bytes first.
@@ -591,12 +599,13 @@ keepInstead.addEventListener('click', () => filesInput.click())
591599
download.addEventListener('click', (event) => {
592600
if (previewed.length) {
593601
event.preventDefault()
594-
// A video the parent says weighs more than it saves is not fetched here, where it could not be
602+
// A package that will weigh more than the parent saves is not made here, where it could not be
595603
// saved with a press: a tab of this page is opened by the parent, at once, and saves it there.
604+
// Only where every file of the activity is at an address, which is all a tab can reach.
596605
const size = hostSaves !== null && hostOpens && !keeping ? previewSize() : null
597606
if (size !== null && size > hostSaves!) {
598607
toParent({ type: 'open', href: savingLink() })
599-
return saying(`This .h5p is over ${sized(size)}, more than the chat saves. A new tab gets your ${previewedAs()} and saves it there.`)
608+
return saying(`This .h5p is about ${sized(size)}, more than the chat saves. A new tab gets your ${previewedAs()} and saves it there.`)
600609
}
601610
return fetchToKeep()
602611
}

0 commit comments

Comments
 (0)