From 8d1580d10659775486a8224ff8456a5c4864441b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20Schr=C3=B6ter?= <domi@icereed.net>
Date: Mon, 28 Oct 2024 22:51:04 +0100
Subject: [PATCH] fix: Put OCR pages into correct order

A race condition caused the pages to be
in a mixed order.
---
 paperless.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/paperless.go b/paperless.go
index ec2ecb4..b477324 100644
--- a/paperless.go
+++ b/paperless.go
@@ -11,6 +11,7 @@ import (
 	"net/http"
 	"os"
 	"path/filepath"
+	"slices"
 	"strings"
 	"sync"
 
@@ -411,6 +412,9 @@ func (c *PaperlessClient) DownloadDocumentAsImages(ctx context.Context, document
 		return nil, err
 	}
 
+	// sort the image paths to ensure they are in order
+	slices.Sort(imagePaths)
+
 	return imagePaths, nil
 }