Skip to content

Commit

Permalink
Fix page parameter for zip worker (#4431)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Jun 27, 2024
2 parents 40aa821 + d006e90 commit f208464
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion web/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ func ArchiveDownloadCreateHandler(c echo.Context) error {
if _, err := jsonapi.Bind(c.Request().Body, archive); err != nil {
return err
}
if len(archive.Files) == 0 && len(archive.IDs) == 0 {
if len(archive.Files) == 0 && len(archive.IDs) == 0 && len(archive.Pages) == 0 {
return c.JSON(http.StatusBadRequest, "Can't create an archive with no files")
}
if strings.Contains(archive.Name, "/") {
Expand Down
9 changes: 5 additions & 4 deletions worker/archive/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func createZip(fs vfs.VFS, files map[string]interface{}, dirID, filename string)
w := zip.NewWriter(z)
for filePath, target := range files {
var fileID string
var page int64
var page int
switch target := target.(type) {
case string:
fileID = target
case map[string]interface{}:
fileID, _ = target["id"].(string)
page, _ = target["page"].(int64)
page64, _ := target["page"].(float64)
page = int(page64)
}
err = addFileToZip(fs, w, fileID, filePath, page)
if err != nil {
Expand All @@ -66,7 +67,7 @@ func createZip(fs vfs.VFS, files map[string]interface{}, dirID, filename string)
return zerr
}

func addFileToZip(fs vfs.VFS, w *zip.Writer, fileID, filePath string, page int64) error {
func addFileToZip(fs vfs.VFS, w *zip.Writer, fileID, filePath string, page int) error {
file, err := fs.FileByID(fileID)
if err != nil {
return err
Expand Down Expand Up @@ -95,7 +96,7 @@ func addFileToZip(fs vfs.VFS, w *zip.Writer, fileID, filePath string, page int64
_, err = io.Copy(f, fr)
return err
}
extracted, err := config.PDF().ExtractPage(fr, int(page))
extracted, err := config.PDF().ExtractPage(fr, page)
if err != nil {
return err
}
Expand Down

0 comments on commit f208464

Please sign in to comment.