freelawproject / doctor

A microservice for document conversion at scale
https://free.law/projects/doctor
BSD 2-Clause "Simplified" License
54 stars 14 forks source link

feat(thumbnail): Add multipage thumbnail support. #158

Closed ERosendo closed 1 year ago

ERosendo commented 1 year ago

This PR adds support generating multiple thumbnails from a PDF and resolves https://github.com/freelawproject/doctor/issues/126.

This new service returns a .zip file containing thumbnails for each page requested.

ERosendo commented 1 year ago

Thank you! @mlissner I've applied the requested changes.

We can also use the FileExtensionValidator to limit the input of this new service. This class from django.core.validators checks the extension of the file that's been uploaded and raises a ValidationError if the extension is not allowed. If We use this validator class, the ThumbnailForm will look like this:

class ThumbnailForm(forms.Form):
  file = forms.FileField(
      label="document",
      required=True,
      validators=[FileExtensionValidator(["pdf"])],
  )
  max_dimension = forms.IntegerField(label="max-dimension", required=False)
  pages = forms.Field(label="pages", required=False)

Let me know what you think.

mlissner commented 1 year ago

Sure, might as well use the validator, why not.

mlissner commented 1 year ago

The rest looks good. If you want to do the validator, go for it. If you want to add the zip bomb protection, go for it. Whatever you do, please merge when you're happy.