adonisjs / attachment-lite

Turn any field on your Lucid models to an attachment data type
MIT License
68 stars 20 forks source link

Pre compute URL with expiresIn option. #12

Closed aungpyaekyaw closed 2 years ago

aungpyaekyaw commented 2 years ago

Why this feature is required (specific use-cases will be appreciated)?

Currently we cannot set custom expire time for signed url with preCompute option. Is it possible to add expiresIn option when using pre computed url.

Have you tried any other work arounds?

Not yet.

Are you willing to work on it with little guidance?

Yes.

aungpyaekyaw commented 2 years ago

I found the workaround for expiresIn option.

You can pass a function to preCompute option in model instead of boolean value.

The model

{
 @attachment({ preComputeUrl: preCompute, disk: 's3'})
  public attachment: AttachmentContract
}

A custom pre-compute function.

async function preCompute(disk: DriverContract, attachment: AttachmentContract) {
  return disk.getSignedUrl(attachment.name,{expiresIn: '5hr'})
}
thetutlage commented 2 years ago

You can pass a function to preCompute option in model instead of boolean value.

That's the way to go