Skip to content
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

Public methods to create files and folders and generate share links for files and folders #8

Closed
wants to merge 34 commits into from

Conversation

andrewatwood
Copy link
Contributor

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Feature

  • What is the new behavior (if this is a feature change)?
    Creates a few new resources on the client, exposing a few new methods: record.uploadFromUrl(), folder.create(), share.createRecordShareLink, share.createFolderShareLink, as well as creating the required init() method that sets up the session to be called after a client is created.

Client config parameters have also changed, exposing baseUrl as an optional param to help easily test against local, and using archiveNbr instead of archiveId, which is more practically useful internally it turns out. And now the client will throw an exception if required params are missing!

This PR got a little larger change-wise than intended due to:

  1. Updating types and interfaces for API requests and responses to make use of generics when appropriate to actually return the appropriate type signature with the expected VO field, instead of a bunch of optional params that all return as, like FolderVO | undefined instead of just FolderVO. This added a lot of line changes in otherwise untouched files. But a worthy change! Just makes the diff a little larger.
  2. A check-in call with TheirStory with a realization that they'll need to share multiple items in a single batch instead of single files from the jump, which required adding the folder.create and createFolderShareLink methods in this PR instead of for another later issue.

My demo code (minus client config) that creates a folder, uploads files to the folder, and generates a share link is as follows for reference:

  await permanent.init();

  const newFolder = await permanent.folder.create('Folder To Share');

  await permanent.record.uploadFromUrl(
    {
      uploadUri: 'https://static.wikia.nocookie.net/non-aliencreatures/images/9/90/Mogwai.jpg/revision/latest/scale-to-width-down/300?cb=20110102071311',
      displayName: 'My Little Friend!',
      uploadFileName: 'gremlin.jpg'
    },
    newFolder
  );

  await permanent.record.uploadFromUrl(
    {
      uploadUri: 'https://upload.wikimedia.org/wikipedia/commons/c/ce/E.T._figure_at_Madame_Tussauds_London.jpg',
      displayName: 'My Other Little Friend!',
      uploadFileName: 'et.jpg'
    },
    newFolder
  );

  const shareLink = await permanent.share.createFolderShareLink(newFolder);

  console.log(`SHARE LINK: ${shareLink}`);

Andrew Atwood and others added 30 commits October 15, 2020 22:57
…ource

- Clean up files and packages leftover from starter
- Install axios for HTTP requests
- Install axios-mock-adapter and ts-sinon for mocking during testing
- Set up params for creating Permanent SDK client
- Set up ApiService and BaseRepo, create AuthRepo with `/auth/loggedIn` endpoint
- Set up BaseResource for exposing public methods, create AuthResource with `isLoggedIn` method
- 100% test coverage!
Rather than using the static `axios`, using instances of `axios` from `axios.create` allows us to set defaults scoped to a particular instance of a Permanent client, and allows the API service to manage the cookies and baseURL rather than delgating this to each individual Repo.
# Conflicts:
#	README.md
#	src/lib/api/api.service.ts
#	src/lib/api/auth.repo.spec.ts
#	src/lib/api/base.repo.spec.ts
#	src/lib/api/base.repo.ts
#	src/lib/client.spec.ts
#	src/lib/client.ts
#	src/lib/model/index.ts
#	src/lib/model/request-vo.ts
#	src/lib/resources/auth.resource.spec.ts
#	src/lib/resources/auth.resource.ts
#	src/lib/resources/base.resource.ts
Add API errorto PermError, Add RecordVO

Set up record post API endpoint
@andrewatwood andrewatwood linked an issue Oct 28, 2020 that may be closed by this pull request
@andrewatwood andrewatwood added the enhancement New feature or request label Oct 28, 2020
Copy link
Contributor

@jasonaowen jasonaowen left a comment

Choose a reason for hiding this comment

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

Hey @andrewatwood, it looks like due to a bad merge this branch contains the alternate history that was originally in PR #3, including the WIP commits and the commits without the author email address set. Would you please rebase onto main to clean that up?

I believe rebasing would bring the number of lines changed down by a few hundred, but this is still an extremely large PR, and I haven't been able to meaningfully review it yet. Do you think it would be feasible for you to split it up into multiple smaller PRs for the sake of reviewability?

@jasonaowen
Copy link
Contributor

For the record, @andrewatwood and @slifty are working together to split this into several smaller PRs, starting with #10. Thanks, both of you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Method to upload a file from a public URL
2 participants