Skip to content

Commit

Permalink
Merge pull request #54 from internxt/feature/add-photo-shares
Browse files Browse the repository at this point in the history
[_]: feature/add-photo-shares
  • Loading branch information
AlexMenor authored Apr 4, 2022
2 parents 14d0c30 + 51b2a76 commit bbaf5b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/sdk",
"version": "0.6.1",
"version": "0.7.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
14 changes: 4 additions & 10 deletions src/photos/shares/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from 'axios';
import { extractAxiosErrorMessage } from '../../utils';

import { CreatePhotoShareBody, PhotosSdkModel, Share } from '..';
import { CreatePhotoShareBody, PhotosSdkModel } from '..';
import { GetPhotoShareResponse } from '../types';

export default class SharesSubmodule {
private model: PhotosSdkModel;
Expand All @@ -10,13 +11,9 @@ export default class SharesSubmodule {
this.model = model;
}

public getShareByToken(token: string) {
public getShare(id: string, code: string) {
return axios
.get<Share>(`${this.model.baseUrl}/shares/${token}`, {
headers: {
Authorization: `Bearer ${this.model.accessToken}`,
},
})
.get<GetPhotoShareResponse>(`${this.model.baseUrl}/shares/${id}?code=${code}`)
.then((response) => response.data)
.catch((err) => {
throw new Error(extractAxiosErrorMessage(err));
Expand All @@ -30,11 +27,8 @@ export default class SharesSubmodule {
Authorization: `Bearer ${this.model.accessToken}`,
},
})
.then(() => undefined)
.catch((err) => {
throw new Error(extractAxiosErrorMessage(err));
});
}

// TODO: create visit share endpoint and method
}
16 changes: 8 additions & 8 deletions src/photos/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export type ShareId = string;
export interface Share {
id: ShareId;
bucket: string;
encryptionKey: string;
photoId: string;
encryptedMnemonic: string;
photoIds: PhotoId[];
token: string;
views: number;
createdAt: Date;
Expand All @@ -99,9 +99,9 @@ export interface ShareJSON extends Omit<Share, 'createdAt' | 'updatedAt'> {
createdAt: string;
updatedAt: string;
}
export interface CreatePhotoShareBody {
encryptionKey: string;
views: number;
photoId: string;
bucket: string;
}

export type CreatePhotoShareBody = Pick<Share, 'encryptedMnemonic' | 'views' | 'photoIds' | 'bucket' | 'token'>;

export type GetPhotoShareResponse = Share & {
photos: (Pick<Photo, 'fileId' | 'name' | 'size' | 'type'> & { decryptionKey: string })[];
};

0 comments on commit bbaf5b3

Please sign in to comment.