-
Notifications
You must be signed in to change notification settings - Fork 0
Shosh file module updates #94
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3191d17
started implementing abstract class from boilerplate, still need to u…
shoshannaTM 9d57f8d
tests passing
shoshannaTM b6c7aaa
switched to file storage dir from data path
shoshannaTM 222524c
Added get stub to config service
shoshannaTM 12d0fda
addressed comments on pr, except test mocks
shoshannaTM 98df182
removed watermark from s3 file service
shoshannaTM 7fd7df6
removed promise wrapper
shoshannaTM 50cf09a
removed trailing comma
shoshannaTM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { Injectable, Logger } from '@nestjs/common'; | ||
| import { ConfigService } from '@nestjs/config'; | ||
| import { join } from 'path'; | ||
| import sharp from 'sharp'; | ||
| import { File } from 'src/dal/entity/file.entity'; | ||
| import Stream, { Readable } from 'stream'; | ||
| import { FileServiceInterface } from './interfaces/file-service.interface'; | ||
| import { FileUpload } from './interfaces/file-upload.interface'; | ||
|
|
||
| @Injectable() | ||
| export abstract class FileService implements FileServiceInterface { | ||
| public logger = new Logger(FileService.name); | ||
|
|
||
| public watermark: Promise<Buffer<ArrayBufferLike>>; | ||
|
|
||
| constructor(readonly configService: ConfigService) {} | ||
|
|
||
| abstract storeImageFromFileUpload( | ||
| upload: Promise<FileUpload> | FileUpload, | ||
| userId: any, | ||
| ): Promise<File>; | ||
| abstract delete(fileName: string): Promise<void>; | ||
| abstract deleteById(fileId: any, userId: any): Promise<any>; | ||
| abstract get(fileName: string): Promise<Readable>; | ||
| abstract getByShareableId(shareableId: string): Promise<Readable>; | ||
|
|
||
| async getWatermark() { | ||
| return sharp( | ||
| join( | ||
| process.cwd(), | ||
| 'public', | ||
| 'assets', | ||
| this.configService.getOrThrow('ICON_NAME'), | ||
| ), | ||
| ) | ||
| .resize(150, 150) | ||
| .extend({ | ||
| top: 0, | ||
| bottom: 20, | ||
| left: 20, | ||
| right: 0, | ||
| background: { r: 0, g: 0, b: 0, alpha: 0 }, | ||
| }) | ||
| .composite([ | ||
| { | ||
| input: Buffer.from([0, 0, 0, 200]), | ||
| raw: { | ||
| width: 1, | ||
| height: 1, | ||
| channels: 4, | ||
| }, | ||
| tile: true, | ||
| blend: 'dest-in', | ||
| }, | ||
| ]) | ||
| .toBuffer(); | ||
| } | ||
|
|
||
| async watermarkImage( | ||
| fileStream: Stream.Readable | undefined, | ||
| ): Promise<Readable | undefined> { | ||
| const watermark = await this.getWatermark(); | ||
| return fileStream?.pipe( | ||
| sharp() | ||
| .jpeg() | ||
| .resize(1080, 1080, { fit: sharp.fit.inside }) | ||
| .composite([{ input: watermark, gravity: 'southwest' }]), | ||
| ); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.