Behaviour SwRS-MDOKFSTUDIO-PALETTE-196
The host saves a pasted image next to the document under a name it chooses
When previewPasteImage is accepted, the extension SHALL check the request and the image bytes, save the image in the folder of the document as image.png, image.jpg, image.gif or image.webp, or with the suffix -1, -2 and so on up to -1000 when the name is taken, comparing names without case, never showing the name before all its bytes are written, remove first the hidden partial files of its own naming that are older than 10 minutes, and answer the file name, or write nothing and answer a refusal with its reason when a check or the write fails.
Step 2 of path 1 in StRS-MDOKFSTUDIO-PALETTE-018: from “The host receives the image” to “The image is saved next to the document”.
Scenarios 7
The situations the tests check; open one to read it.
nominalThe host chooses the name
The name never comes from the page. The handler answers ok true and the file name (previewPasteImageResult). The envelope, the render gate and the answer correlation are those of SwRS-MDOKFSTUDIO-TRUST-052, SwRS-MDOKFSTUDIO-TRUST-065, SwRS-MDOKFSTUDIO-TRUST-005 and SwRS-MDOKFSTUDIO-TRUST-090.
| GIVEN the folder of the document | WHEN the bytes are | THEN the file and the answer are |
|---|---|---|
| empty | a png | image.png |
| empty | a jpeg | image.jpg |
| empty | a gif | image.gif |
| empty | a webp | image.webp |
| holds image.png | a png | image-1.png |
| holds image.png and image-1.png | a png | image-2.png |
| holds a name that differs from image.png only by case | a png | image-1.png (the name counts as taken) |
nominalThe name appears complete
a file created under the chosen name during the write
the rename runs
that file is kept and not overwritten, and the image is saved under the next free name (image-1.png when image.png was taken), chosen again from a fresh listing of the folder, up to 5 attempts in all; the answer is then ok true with that name, or ok false with the error message when the rename keeps failing for another reason than a taken name
nominalA leftover of an interrupted save is removed
boundaryThe numbering stops after 1000 suffixes
| Folder | Outcome |
|---|---|
| image-1000.png free, all smaller names taken | the file is written under image-1000.png |
| image.png and image-1.png to image-1000.png taken (1001 taken names) | ok false with the reason Too many pasted images next to this document. and nothing is written |
refusalA check fails
Each refusal answers ok false with the reason below and writes nothing; the folder is unchanged. The checks run in this order.
| Case | Reason |
|---|---|
| document with no file path, or whose id differs from the previewed document | Save the document before pasting an image. |
| saved document whose file is not a .md file (any case of the extension) | Pasting an image needs a Markdown file. |
| document folder outside every workspace folder, both paths compared with symbolic links resolved; for a document that lies in no workspace folder at all, its own folder is the root, so the image is saved there | The image must be saved inside a workspace folder. |
| announced type outside png, jpeg, gif and webp, or data that is not plain base64 | That clipboard image type is not supported. |
| more than 10 MiB (10 times 1024 times 1024 bytes) of bytes | The image is larger than 10 MB. |
| first bytes that are not those of the announced type (text announced as image/png) | The clipboard data is not a png, jpeg, gif or webp image. |
| no free name up to the suffix 1000 | Too many pasted images next to this document. |
A saved .md document in a folder inside the workspace, reached through a symbolic link or not, is accepted and the image is saved. This handler does not check the render revision.
refusalThe write fails
a write that succeeds
the save ends
only the chosen name remains
boundaryThe message shape
| previewPasteImage field | Accepted | Otherwise |
|---|---|---|
| mime | image/png, image/jpeg, image/gif or image/webp (SVG is not accepted because it can carry script) | the protocol rejects the message and the handler does not run |
| dataBase64 | a non-empty string of at most 14,000,000 characters in the base64 alphabet with optional padding and no whitespace | the protocol rejects the message and the handler does not run |
| edit id | as for every host request (SwRS-MDOKFSTUDIO-TRUST-052) | the protocol rejects the message |