feat(files): persist uploaded files and associate them with conversations - #354
Open
Hustler490 wants to merge 1 commit into
Open
Hustler490 wants to merge 1 commit into
Hustler490 wants to merge 1 commit into
Conversation
…ions Add a files table plus upload/list/retrieve/download/attach/analyze routes so an uploaded file is stored once on disk and can be attached to a conversation and re-analyzed later without re-uploading. Uploads reuse the /tools/analyze extension allowlist and size cap, are written under UPLOAD_FOLDER with a random stored name, and every read/download/attach/analyze is scoped to the owner (another user gets 404). The migration also merges the three pre-existing Alembic heads, which previously made \lask db upgrade\ fail outright, and the head test now asserts a single head. Closes AyinkxLab#42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #42
What
Uploaded files are now persisted on disk and tracked in a
filestable, so the same file can be downloaded, attached to a conversation, and re-analyzed later without re-uploading.Changes
app/models/stored_file.py-StoredFile(filestable):id, workspace_id, user_id, original_name, stored_name, size, content_type, created_at(+conversation_idfor attachment). The stored name is random and never derived from user input.app/files/- new blueprint with:POST /filesupload (extension allowlist and size cap reused from/tools/analyze; optionalworkspace_idgated on active membership),GET /fileslist (own files only),GET /files/<id>metadata,GET /files/<id>/download,POST /files/<id>/attach(own conversations only;nulldetaches),POST /files/<id>/analyze(re-analyzes the stored bytes).Every read/download/attach/analyze is owner-scoped - another user gets a 404, never the file.
app/config.py-UPLOAD_FOLDER(configurable) andUPLOAD_MAX_BYTES.filestable. It also merges the three pre-existing Alembic heads, which previously madeflask db upgradefail with "Multiple head revisions";tests/test_migrations.py::test_head_is_latest_revisionnow asserts a single head.Acceptance criteria
filestable with the required columns.UPLOAD_FOLDERwith random stored names and validated extensions./tools/analyzevalidation.Validation
pytest tests/test_files.py-> 8 passed.ruff checkandblack --checkclean on the changed files.test_migrations.py::test_conversation_shares_table_upgradedfails, which is a pre-existing stale assertion (it expects the oldconversation_sharescolumns while the migration/model addexpires_at,token_hash,permission) and is unrelated to this change.