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

refactor: performance cw721 media info ( main ) #369

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/services/cw721/cw721-media.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ export default class Cw721MediaService extends BullableService {
// download image/animation from media_uri, then upload to S3
async uploadMediaToS3(media_uri?: string) {
if (media_uri) {
const fileName = this.parseFilename(media_uri);
const uploadAttachmentToS3 = async (
type: string | undefined,
buffer: Buffer
) => {
const params = {
Key: this.parseFilename(media_uri),
Key: fileName,
Body: buffer,
Bucket: BUCKET,
ContentType: type,
Expand All @@ -282,16 +283,30 @@ export default class Cw721MediaService extends BullableService {
}
);
};
const mediaBuffer = await this.downloadAttachment(
this.parseIPFSUri(media_uri)
);
let type: string | undefined = (
await FileType.fileTypeFromBuffer(mediaBuffer)
)?.mime;
if (type === 'application/xml') {
type = 'image/svg+xml';
try {
const s3Object = await s3Client
.headObject({
Bucket: BUCKET,
Key: fileName,
})
.promise();
return {
linkS3: S3_GATEWAY + fileName,
contentType: s3Object.ContentType,
key: fileName,
};
} catch {
Copy link
Member

Choose a reason for hiding this comment

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

catch cái gì

const mediaBuffer = await this.downloadAttachment(
this.parseIPFSUri(media_uri)
);
let type: string | undefined = (
await FileType.fileTypeFromBuffer(mediaBuffer)
)?.mime;
if (type === 'application/xml') {
type = 'image/svg+xml';
}
return uploadAttachmentToS3(type, mediaBuffer);
}
return uploadAttachmentToS3(type, mediaBuffer);
}
return null;
}
Expand Down