-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(s3): new parameter "format" for png images #5
Conversation
@@ -52,10 +52,11 @@ export default class StorageS3 { | |||
return this; | |||
} | |||
|
|||
async transform(fromKey, toKey, transform = sharp().jpeg()) { | |||
async transform(fromKey, toKey, transform = sharp(), format) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args 不應該 required, required, option, required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
寫一個 toFormat
保留 transform
的彈性
@@ -52,10 +52,11 @@ export default class StorageS3 { | |||
return this; | |||
} | |||
|
|||
async transform(fromKey, toKey, transform = sharp().jpeg()) { | |||
async transform(fromKey, toKey, format, transform = sharp()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transform()
不需要,format
可以維持 transform
的彈性
await this.s3.copyObject({ CopySource: `${this.bucket}/uploader/${key}`, Key: `media/${toKey}` }).promise(); | ||
await this.transform(`media/${toKey}`, `media/${toKey}_cover`); | ||
await this.transform(`media/${toKey}`, `media/${toKey}_cover`, format); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await this.transform(media/${toKey}, media/${toKey}_cover, toFormat(sharp(), format));
const cacheName = `cache/${key}_cover_${[width, height].join('x')}`; | ||
|
||
try { | ||
await this.s3.headObject({ Key: cacheName }).promise(); | ||
} catch (e) { | ||
await this.transform(`media/${key}_cover`, cacheName, sharp().resize(width, height).jpeg()); | ||
await this.transform(`media/${key}_cover`, cacheName, format, sharp().resize(width, height)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await this.transform(media/${key}_cover, cacheName, toFormat(sharp().resize(width, height), format));
4829dfb
to
5a4056c
Compare
@wl00887404 測試需要可以 pass |
tmotx/tickets#42
Related: https://github.com/tmotx/platform/pull/367