Skip to content

Adds support for downloading attachments as a .tar #1495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 7, 2025

Conversation

Spoffy
Copy link
Contributor

@Spoffy Spoffy commented Mar 3, 2025

Context

Currently only Zip is supported for downloading attachments. In the future, we want to be able to support re-uploading attachments. Zip will make this difficult, as the structure of the zip file is stored at the end of file, requiring the entire file to be uploaded before it can be parsed.

Proposed solution

This PR adds downloading attachments as a .tar, which uses inline headers for each file it contains. This means it can be easily parsed and processed through node's streams, minimizing server disk and memory usage.

Related issues

#1021

Has this been tested?

  • 👍 yes, I added tests to the test suite
  • 💭 no, because this PR is a draft and still needs work
  • 🙅 no, because this is not relevant here
  • 🙋 no, because I need help

Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good!

I think endpoint forwarders are needed, and the tests may need a tweak.

dataStream: stream.Readable;
completed: Promise<void>;
}

export const CreatableArchiveFormats = StringUnion('zip', 'tar');
export type CreatableArchiveFormats = typeof CreatableArchiveFormats.type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: our codebase normally puts semicolon at end of type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, wonder why this one wasn't caught by the linting rules?

@@ -2530,6 +2530,27 @@ function testDocApi(settings: {
]);
});

it("GET /docs/{did}/attachments/download downloads all attachments as a .tar", async function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed on previous work that @berhalak later needed to add forwarders for new attachment endpoints:
https://github.com/gristlabs/grist-core/pull/1348/files#diff-531fd1025fc38b2b06fc3bafb8972112a3480fa807426e12e7b047374576c807

This is normal, in multi-server Grist all doc workers interact with the outside world via forwarding from home servers for ... reasons.

I was wondering why the tests you're adding are passing, despite being run for multiple configurations, including separate home server and doc worker.

I think it may be that by using serverUrl versus homeUrl, the tests are talking directly to the doc worker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this - but not quite sure how to test it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the trick will be to use homeUrl rather than serverUrl to better mimic real conditions. But I could be misremembering.

@Spoffy Spoffy force-pushed the spoffy/attachment-downloads-tar branch from 07013e6 to b088df1 Compare March 4, 2025 14:40
@@ -59,6 +59,7 @@ export class DocApiForwarder {
app.use('/api/docs/:docId/create-fork', withDoc);
app.use('/api/docs/:docId/apply', withDoc);
app.use('/api/docs/:docId/attachments', withDoc);
app.use('/api/docs/:docId/attachments/download', withDoc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the /attachments forwarders at the end of this list could all be herded together. Btw, do tests now fail if you remove this forwarder?

Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Spoffy

@Spoffy Spoffy merged commit e5d5d5a into main Mar 7, 2025
12 checks passed
@Spoffy Spoffy deleted the spoffy/attachment-downloads-tar branch March 7, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants