6f37120dc4
A paper needs its experiment figures, and a figure is not text: the bytes go to
MinIO and the sentence keeps a Markdown address. That is what keeps a sentence
one editable string — a picture moves between paragraphs by being cut and
pasted, and survives a template switch with the sentence it belongs to.
Three decisions carry the safety, and each is a way to serve something other
than what was uploaded:
* the key is the digest of the bytes, so uploading the same screenshot twice is
one object and the address can never come to mean a different picture — which
is what makes the year-long `immutable` cache header safe;
* the format is sniffed from the magic bytes, not read from the client's
`Content-Type` or filename, and SVG is refused because an uploaded SVG served
from this origin is stored XSS;
* serving is restricted to the key space this application writes, so
`GET /api/images/{key}` cannot become a browser for the rest of the bucket.
Images are served through the API rather than from a public bucket URL so a
sentence never embeds a host name — the LAN in development and the public
address later would otherwise disagree — and the bucket can stay private. The
object is streamed rather than read into memory, and the connection is released
when the reader stops.
Storage unconfigured is a 503 that names the missing variables, not a crash:
the writing path does not depend on the bucket.
`scripts/smoke_images.py` walks the whole thing: each accepted format, the
refusals (text, SVG, a mislabelled file, an empty file, a key we did not
write), and a sentence that carries a figure through the paper endpoints.
104 lines
2.2 KiB
Python
104 lines
2.2 KiB
Python
"""Pydantic schemas for request and response payloads."""
|
|
|
|
from app.schemas.common import (
|
|
BatchDeleteRequest,
|
|
BatchDeleteResult,
|
|
PageResult,
|
|
normalize_hex_color,
|
|
)
|
|
from app.schemas.image import ImageRead
|
|
from app.schemas.paper import (
|
|
CitationInput,
|
|
CitationRead,
|
|
PaperCitationRead,
|
|
PaperCreate,
|
|
PaperDocumentRead,
|
|
PaperListItem,
|
|
PaperRead,
|
|
PaperReferenceRead,
|
|
PaperStatus,
|
|
PaperUpdate,
|
|
ParagraphListRead,
|
|
ParagraphRead,
|
|
ParagraphUpdate,
|
|
SentenceCreate,
|
|
SentenceRead,
|
|
SentenceUpdate,
|
|
)
|
|
from app.schemas.reference import (
|
|
ReferenceAuthorInput,
|
|
ReferenceAuthorRead,
|
|
ReferenceCitationRead,
|
|
ReferenceCreate,
|
|
ReferenceListItem,
|
|
ReferenceRead,
|
|
ReferenceUpdate,
|
|
normalize_doi,
|
|
)
|
|
from app.schemas.reference_tag import (
|
|
ReferenceTagCreate,
|
|
ReferenceTagRead,
|
|
ReferenceTagRef,
|
|
ReferenceTagUpdate,
|
|
)
|
|
from app.schemas.template import (
|
|
TemplateCreate,
|
|
TemplateListItem,
|
|
TemplateRead,
|
|
TemplateUpdate,
|
|
TemplateTitlePlacementInput,
|
|
TemplateTitlePlacementRead,
|
|
)
|
|
from app.schemas.template_title import (
|
|
TemplateTitleCreate,
|
|
TemplateTitleRead,
|
|
TemplateTitleRef,
|
|
TemplateTitleUpdate,
|
|
)
|
|
|
|
__all__ = [
|
|
"BatchDeleteRequest",
|
|
"ImageRead",
|
|
"ReferenceAuthorInput",
|
|
"ReferenceAuthorRead",
|
|
"ReferenceCitationRead",
|
|
"ReferenceCreate",
|
|
"ReferenceListItem",
|
|
"ReferenceRead",
|
|
"ReferenceTagCreate",
|
|
"ReferenceTagRead",
|
|
"ReferenceTagRef",
|
|
"ReferenceTagUpdate",
|
|
"ReferenceUpdate",
|
|
"normalize_doi",
|
|
"CitationInput",
|
|
"CitationRead",
|
|
"PaperCitationRead",
|
|
"PaperCreate",
|
|
"PaperDocumentRead",
|
|
"PaperListItem",
|
|
"PaperRead",
|
|
"PaperReferenceRead",
|
|
"PaperStatus",
|
|
"PaperUpdate",
|
|
"ParagraphListRead",
|
|
"ParagraphRead",
|
|
"ParagraphUpdate",
|
|
"SentenceCreate",
|
|
"SentenceRead",
|
|
"SentenceUpdate",
|
|
"BatchDeleteResult",
|
|
"PageResult",
|
|
"TemplateCreate",
|
|
"TemplateListItem",
|
|
"TemplateRead",
|
|
"TemplateUpdate",
|
|
"TemplateTitleCreate",
|
|
"TemplateTitleRead",
|
|
"TemplateTitleRef",
|
|
"TemplateTitleUpdate",
|
|
"TemplateTitlePlacementInput",
|
|
"TemplateTitlePlacementRead",
|
|
"normalize_hex_color",
|
|
]
|