chat: send a file to a room, and bound what an agent may attach #81
Loading…
Reference in a new issue
No description provided.
Delete branch "send-file"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The room's end of an agent's
attach(spec-bb1.39), against the seam of roomcity-b8's #77 (server.Files:SendFile(ctx, session, File) (event, err)), which the serve adapter fills in once #77 is on main.chat.Driver.SendFile(ctx, room, speaker, File{Name, MediaType, Caption, Data}). Matrix: the file is uploaded to the media repository as the agent's user and sent as anm.imagewhen it is a PNG, JPEG or GIF whose size can be read (infohas the type, size, width and height), else as anm.file; an SVG is a file until a client is seen to draw one. The caption is the body and the name thefilename; with no caption the name is the body. A 413 on the upload ischat.ErrFileTooLarge; another answer of 4xx is a refusal (#68'schat.Refused); anything else is the homeserver out of reach.(*chat.Service).Attach(ctx, session, File) (MessageID, error)applies the bounds, which are keys of[chat]:max_file(a size,"10MiB"by default) andfile_kinds(media types ortype/*; defaultimage/*,text/*,application/pdf,application/json). Errors wrapchat.ErrFileTooLarge,ErrFileKind,ErrNoRoom(a session with no room yet) orErrChatDownwith a text that says what the room takes, for the agent to read.m.imagewith its width and height and the same bytes from the media repository, a text file as anm.file, an SVG as anm.file; the upload's 413 and the picture that cannot be read.It is on #68's branch (it uses
chat.Refused): merge it after. Not here: the serve adapter (after #77), the transcript's File event and the renderer's default case for it (b8's type), the incoming direction.1915c1b0a9b38512952fb38512952fa81f407b80Read at
a81f407(its own commit, on #68's old branch). The driver's part holds: the upload as the agent's user, anm.imageonly for a picture whose size can be read, the caption and the name where clients look for them, a 413 told from the other refusals. One change before it merges, and two things for the wiring.The kind that
Attachchecks is the one the caller names. That name is the session's word: the host makes it from the file's extension, and a session can also make the call itself, with its own token, and say what it likes. Sofile_kindsholds for the names of files and not for what they are: a zip callednotes.txtis atext/plainthat the room takes, and anything at all calledx.pngis animage/png(sent as a file, since it does not read as a picture, but sent). The bound is the owner's, on what an agent may put in the room. Check it against what the bytes show (http.DetectContentTypeknows the kinds the default list names, and what it callsapplication/octet-streamis nothing it can vouch for), refuse a file whose bytes belong to another kind than the one named, and upload it under the kind that was checked. A test with a zip named as text and an HTML page named as a picture.For the adapter in serve, with roomcity-b8: the server's handler maps its own
server.ErrFileTooLarge,ErrFileKind,ErrNoRoomandErrChatDown, andAttachwrapschat's four of the same names, which are other values. The adapter has to turn one into the other, or every refusal reaches the agent as Internal.Also for the adapter: there are two bounds on size and they do not know of each other. The server reads no further than
server.DefaultMaxFile, a constant of 10 MiB, before the call reachesAttach;[chat] max_fileis checked after. A city that raisesmax_filegets the server's refusal at 10 MiB all the same. One number, from[chat] max_file, has to reachLimitSendandHost.MaxFile.It is behind main by the release and #76; rebase onto main with the change.
a81f407b80257f2695d2257f2695d2e5c74d3c28