From e4c898cd1bbd4bf64abf2878afaca0f9ccd9846e Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 19 Jul 2026 22:21:26 -0400 Subject: [PATCH] M2 attachments: image upload + owner-scoped media serving - Migration 0007: note_attachments (path/mime/size). Upload POST /api/notes//attachments (multipart, png/jpeg/gif/webp, 12MB cap via MAX_CONTENT_LENGTH) stored under Config.media_root() (first use of DATA_DIR); owner/ACL-scoped GET serves the file (nosniff); DELETE removes row + file. Note responses include attachments[]. - Frontend: notes store uploadAttachment (FormData)/deleteAttachment; editor image button + paste-to-upload + thumbnail grid with remove; card shows the first image as a cover. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm --- alembic/versions/0007_attachments.py | 32 +++++++ frontend/src/components/Icon.vue | 1 + frontend/src/components/NoteCard.vue | 12 ++- frontend/src/components/NoteEditor.vue | 64 +++++++++++++ frontend/src/stores/notes.ts | 28 ++++++ src/thoughtsync/app.py | 1 + src/thoughtsync/models/all.py | 2 +- src/thoughtsync/models/note_attachment.py | 26 ++++++ src/thoughtsync/notes.py | 109 +++++++++++++++++++++- tests/test_notes.py | 6 ++ 10 files changed, 278 insertions(+), 3 deletions(-) create mode 100644 alembic/versions/0007_attachments.py create mode 100644 src/thoughtsync/models/note_attachment.py diff --git a/alembic/versions/0007_attachments.py b/alembic/versions/0007_attachments.py new file mode 100644 index 0000000..f4fa01e --- /dev/null +++ b/alembic/versions/0007_attachments.py @@ -0,0 +1,32 @@ +"""note_attachments + +Revision ID: 0007 +Revises: 0006 +Create Date: 2026-07-20 +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import UUID + +revision = "0007" +down_revision = "0006" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.create_table( + "note_attachments", + sa.Column("id", UUID(as_uuid=True), primary_key=True), + sa.Column("note_id", UUID(as_uuid=True), sa.ForeignKey("notes.id", ondelete="CASCADE"), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column("mime", sa.Text(), nullable=False), + sa.Column("size", sa.BigInteger(), nullable=False), + sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()), + ) + op.create_index("ix_note_attachments_note", "note_attachments", ["note_id"]) + + +def downgrade() -> None: + op.drop_index("ix_note_attachments_note", table_name="note_attachments") + op.drop_table("note_attachments") diff --git a/frontend/src/components/Icon.vue b/frontend/src/components/Icon.vue index d2fb296..70778fa 100644 --- a/frontend/src/components/Icon.vue +++ b/frontend/src/components/Icon.vue @@ -15,6 +15,7 @@ const paths: Record = { plus: '', check: '', checkbox: '', + image: '', }; diff --git a/frontend/src/components/NoteCard.vue b/frontend/src/components/NoteCard.vue index a2f9b9f..d0f1b5f 100644 --- a/frontend/src/components/NoteCard.vue +++ b/frontend/src/components/NoteCard.vue @@ -19,6 +19,14 @@ function cardClass(color: NoteColor): string { class="group relative mb-4 break-inside-avoid rounded-xl border p-3 shadow-sm transition hover:shadow-md" :class="cardClass(note.color)" > + +