Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

[BREAKING] Refactor getfilecontent and upload methods #239

Merged
merged 10 commits into from
Dec 18, 2020

Conversation

mrcnski
Copy link
Contributor

@mrcnski mrcnski commented Dec 15, 2020

  • [BREAKING] Upload methods return object
  • [BREAKING] Remove upload request
  • [BREAKING] Make getMetadata return object containing metadata and skylink
  • Return object containing contentType, metadata, skylink from getFileContent
  • getFileContent returns a skylink prefixed with sia:
  • Add getFileContentHns

src/download.ts Outdated
Comment on lines 48 to 64
export type GetFileContentResponse<T = unknown> = {
data: T;
contentType: string;
metadata: Record<string, unknown>;
skylink: string;
};

/**
* The response for a get metadata request.
*
* @property metadata - The metadata in JSON format.
* @property skylink - 46-character skylink.
*/
export type GetMetadataResponse = {
metadata: Record<string, unknown>;
skylink: string;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we combine these return types with data?: T ? contentType is returned on HEAD calls and could serve a purpose.

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 want to keep the response types separate, but I added contentType to the metadata response. I'm can see potential use cases for it

@mrcnski mrcnski requested a review from dghelm December 16, 2020 14:47
Copy link
Contributor

@ro-tex ro-tex left a comment

Choose a reason for hiding this comment

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

LGTM!

);
}

// TODO: Return null instead if header not found?
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO an empty content type is acceptable, especially if we're doing it for the metadata call. It's better than null because the client can treat it as a string in a safe way without needing a nullish check.

expect(data).toEqual(data);
});

it("Should get JSON file contents", async () => {
const json = { key: "testdownload" };

// Upload the data to acquire its skylink
const file = new File([JSON.stringify(json)], dataKey, { type: "application/json" });
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if we don't specify the content type? Would it be detected?
No need to cover this now but it might be interesting to verify the behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up: #241

@mrcnski mrcnski merged commit 21cda61 into master Dec 18, 2020
@mrcnski mrcnski deleted the refactor-getfilecontent-and-upload branch December 18, 2020 15:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants