diff --git a/ai.go b/ai.go index 470b43e..ef9180d 100644 --- a/ai.go +++ b/ai.go @@ -722,10 +722,12 @@ func ProcessDocument(filePath string) (*Document, error) { log.Printf(" Category: %s, Type: %s", analysis.Category, analysis.DocType) - // Copy to store + // Copy to store (skip if already there — reprocessing from store-backed upload) storePath := filepath.Join(storeDir, hash+ext) - if err := copyFile(filePath, storePath); err != nil { - return nil, fmt.Errorf("store copy failed: %w", err) + if _, statErr := os.Stat(storePath); os.IsNotExist(statErr) { + if err := copyFile(filePath, storePath); err != nil { + return nil, fmt.Errorf("store copy failed: %w", err) + } } // Only set PDFPath for actual PDFs — office/text files have no previewable PDF