Feature: Read and download project files - #148
Conversation
|
I will patch EDIT: #149 |
Add FileGet, FileList and FileDownload to the projects package. Files were
write-only in the SDK: FileCreate and FileDelete existed, but nothing could
read a file's attributes, list a project's files area or fetch the content.
FileGet and FileList use the v3 routes, GET /projects/api/v3/files/{id}.json
and GET /projects/api/v3/files.json (or the project-scoped
/projects/{id}/files.json), with typed sideloads, ordering, count mode and
generated sparse-field slots. FileDownload builds the address that
File.DownloadURL reports from the session's server, so the session's Bearer
token authenticates it, follows the redirect to storage and hands the caller
an open body. Its response type deliberately does not implement
twapi.HTTPResponser, since twapi.Execute closes the body before returning.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Drop FileID and ProjectID from FileVersion, and VersionID, ProjectID, CategoryID and TagIDs from File: each repeats a relation the neighbouring twapi.Relationship already carries, and the generated FileField constants followed them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Rebased onto main and dropped the six duplicated identifiers ( |
82669dc to
a336437
Compare
The v3 responses carry them on every row as file relationships: tasks and message replies under "attachments", comments under "files". The models dropped the key, so a typed read could not say which files an item carried, and the ID is what FileGet and FileDownload take. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Added the file relationships the v3 responses already carry, so the attached files of an item can be read back and handed to |
Description
Files were write-only in the SDK:
FileCreateandFileDeleteexisted, but nothing could read a file's attributes, list a project's files area or fetch the content. This adds the read side on the v3 routes and a download step.FileGet—GET /projects/api/v3/files/{id}.json, withVersion,IncludeVersions, typedIncludesideloads (users, projects, tags, tasks) and a generatedFileGetFieldsslot.FileList—GET /projects/api/v3/files.json, orGET /projects/api/v3/projects/{id}/files.jsonwhenPath.ProjectIDis set. Filters: IDs, task, category, tags, uploaders, search term (optionally across all fields), upload date window, updated-after, deleted files, external files, versions, sideloads, ordering, paging, count mode and sparse fields. Date boundary rules are stated on each field.FileDownload— builds the addressFile.DownloadURLreports from the session's server, so the session's Bearer token authenticates it the same way it does the v3 endpoints. The route answers 302 to a signed storage URL, which the HTTP client follows; the caller gets the suggested name, content type, size and an open body.FileDownloadResponsedeliberately does not implementtwapi.HTTPResponser, becausetwapi.Executecloses the body before returning.File,FileVersionandFileRelatedItemsmodels, plusFileStatus,FileRequestSideloadandFileOrderByenums.Task.Attachments,MessageReply.AttachmentsandComment.Files, the file relationships the v3 responses already carry on every row (attachments,attachmentsandfiles), so a typed read says which files an item carries and handsFileGet/FileDownloadtheir ID. A message's own attachments arrive on the reply that holds its body.Type of Change
Testing
go test -v ./...)Examples for get, list and download run against a mock that redirects to a storage path as the real route does. Integration tests (
TestFileGet,TestFileList,TestFileDownload) were run against a live site with a Bearer token and pass, including the downloaded bytes matching the uploaded fixture. Rows were added to the ordering and sparse-field get tables;go generateoutput is committed.Checklist
🤖 Generated with Claude Code