feat(play): a framing page that saves files is handed the package by Download (#98)

Merged
AL
11h ago
+115-16

Closes #98. Part of missing-elements/h5p-toolkit#210.

Inside a chat's card the play page's Download did nothing: the chat lets the frame save no file. The card can ask the chat to save one. Now a framing page that saves files says so, and Download hands it the package.

For the page that frames this one

All optional. With no saves, the page saves as before.

MessageWayWhat it does
{ type: 'saves', max }to the pageThe framing page saves files itself. max is the most bytes it takes; none means any size.
{ type: 'save', id, file }from the pageDownload was pressed: save this package. id numbers the save. Sent where the page would have saved it: at once for a package with its files in it, and after the bytes are brought and the package built for one whose video plays from the chat.
{ type: 'saved', id, ok }to the pageHow the save with that id went, ok a boolean. Only word on the last package handed is taken. No word in a minute is taken as not saved; a yes that comes later is still said.
sizes, beside linksto the page{ 'clip.mp4': bytes }: what the file at each address weighs. A video that would make a package above max is then not fetched for it.

What a person sees

  • One Download that works. Pressed, the button says "Saving…", and a row under the stage "The chat is saving the .h5p…" with a bar, then "Saved. Look in your downloads.", which goes after a few seconds.
  • Not saved: "The chat did not save it. Open it in the build page, and download it there.", with the build page as the row's button.
  • Too big for the chat: "This .h5p is 235 MB, more than the chat can save from here. Open it in the build page, choose your video there, and download it." For a video still at its address, said before anything is brought: "With your video in it, this .h5p is over 230 MB…".
  • Outside a chat, and in one that says no saves: as before.

Testing

By hand, as this repository has no page tests: the built site served locally and framed by a page of another origin acting as a card that saves files, with a store on a third origin.

CaseResult
A quiz, max 64 MB, the card answers yes (light and dark at 720 px, light at 360 px)"The chat is saving…", then "Saved…", then the row goes; one save with the 882 kB package; the browser saves nothing
A quiz, the card first answers with another number, with no number, and with no okthe row stays on saving until the real answer, then the saved row
A quiz, the card answers nothe not-saved row, its button to /h5p/build/ with the source
A quiz above maxthe too-big row at once, no save
A quiz, no savesthe browser saves water.h5p, no row: as before
An Interactive Video from its address, its size given, above max (720 and 360 px)the too-big row at once, "over 2.1 MB"; no needs-bytes, nothing fetched
The same within maxneeds-bytes, the package built, one save with the 6.3 MB package, "Saved…"
The same above max, no size giventhe bytes brought and the package built, then the too-big row with its real size, no save
  • The six card behaviours of #93 and #95, with no saves: unchanged (one browser save for one press, one built, no restart).
  • No page error in any run. pnpm build and pnpm typecheck pass. Screenshots of the rows looked at.

Not verified

  • Not in ChatGPT: the card has to say saves and answer save with the chat's own save first, the next step of h5p-toolkit#210.
  • The minute with no answer: not waited out in a test.
  • Whether "Open in the build page" opens a tab from inside ChatGPT's card, as the row's button or the bar's.
  • What the largest file a chat's save takes is.
  • Chromium only.

Summary by cubic

The play page's Download now hands a package to a framing page that saves files, where before it could not save anything inside a chat's card.

  • A framing page sends { type: 'saves', max } to say it saves files itself; Download sends { type: 'save', file, id } and expects { type: 'saved', id, ok } back, where only the word on the last one handed counts, and a minute of silence is taken as not saved.
  • The row under the stage shows "Saving…", "The chat is saving the .h5p…", then "Saved. Look in your downloads.", or the not-saved row with a button to the build page.
  • A package above max is not handed over, and a video that would make one is not fetched when the frame gave its size (sizes beside links); the too-big row offers the build page instead.
  • A link the parent gives again, as with its size once known, no longer starts the build afresh.
  • With no saves message, behavior is unchanged.