generated from polijrorg/template-node-ts-prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:polijrorg/Apogeo-Back
- Loading branch information
Showing
11 changed files
with
1,532 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# npm | ||
node_modules | ||
package-lock.json | ||
yarn.lock | ||
*.log | ||
*.gz | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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 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,32 @@ | ||
import { Users } from '@prisma/client'; | ||
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3'; | ||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; | ||
|
||
const bucketRegion = process.env.BUCKET_REGION | ||
const accessKey = process.env.ACCESS_KEY | ||
const secretAccessKey = process.env.SECRET_ACCESS_KEY | ||
|
||
export default async function generateUserImageUrl(user: Users): Promise<String | null> { | ||
let url = null; | ||
|
||
if (user.image) { | ||
|
||
const s3 = new S3Client({ | ||
region: bucketRegion, | ||
credentials: { | ||
accessKeyId: accessKey as string, | ||
secretAccessKey: secretAccessKey as string | ||
} | ||
}); | ||
|
||
const getObjectParams = { | ||
Bucket: process.env.BUCKET_NAME, | ||
Key: user.image, | ||
} | ||
|
||
const command = new GetObjectCommand(getObjectParams); | ||
url = await getSignedUrl(s3, command, { expiresIn: 3600 }); | ||
} | ||
|
||
return url; | ||
} |
Oops, something went wrong.