import{getS3Client as e}from"../../utils/s3/s3Client.mjs";import{DeleteObjectCommand as t,PutObjectCommand as n}from"@aws-sdk/client-s3";const r=(e,t)=>{let{hostname:n,pathname:r}=new URL(e),i=(n+r).replace(/\/$/,``).replaceAll(`.`,`_`).replace(/[^a-z0-9.\-_]/gi,`_`);return t?`screenshots/${t}/${i}.jpg`:`screenshots/${i}.jpg`},i=async(t,i,a)=>{let o=r(i,a);return await e().send(new n({Bucket:process.env.S3_BUCKET_NAME,Key:o,Body:t,ContentType:`image/jpeg`})),`${process.env.S3_PUBLIC_URL}/${o}`},a=async n=>{let r=process.env.S3_PUBLIC_URL??``,i=n.startsWith(r)?n.slice(r.length+1):n.split(`/`).pop();i&&await e().send(new t({Bucket:process.env.S3_BUCKET_NAME,Key:i}))};export{a as deleteShowcaseScreenshot,i as uploadShowcaseScreenshot};
//# sourceMappingURL=showcaseUploadScreenshot.service.mjs.map