Created
October 15, 2020 19:38
-
-
Save jschmidtnj/f069dba80d525d328b4f1d7931bb663f to your computer and use it in GitHub Desktop.
media download resolver with type graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ObjectId } from 'mongodb'; | |
| import { Resolver, FieldResolver, ResolverInterface, Root } from 'type-graphql'; | |
| import { DownloadLinks } from '../schema/structure/baseFile'; | |
| import Media from '../schema/structure/media'; | |
| import { fileBucket, getMediaKey, getS3DownloadSignedURL } from '../utils/aws'; | |
| @Resolver(_of => Media) | |
| class DownloadLinksResolver implements ResolverInterface<Media> { | |
| @FieldResolver(_returns => DownloadLinks) | |
| async downloadLinks(@Root() media: Media): Promise<DownloadLinks> { | |
| return { | |
| original: await getS3DownloadSignedURL(getMediaKey(media._id as ObjectId), fileBucket), | |
| blurred: await getS3DownloadSignedURL(getMediaKey(media._id as ObjectId), fileBucket) | |
| }; | |
| } | |
| } | |
| export default DownloadLinksResolver; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment