forked from icereed/paperless-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
177 lines (161 loc) · 8.21 KB
/
types.go
File metadata and controls
177 lines (161 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"context"
"gorm.io/gorm"
)
// GetDocumentsApiResponse is the response payload for /documents endpoint.
// But we are only interested in a subset of the fields.
type GetDocumentsApiResponse struct {
Count int `json:"count"`
// Next interface{} `json:"next"`
// Previous interface{} `json:"previous"`
All []int `json:"all"`
Results []GetDocumentApiResponseResult `json:"results"`
}
// GetDocumentApiResponseResult is a part of the response payload for /documents endpoint.
// But we are only interested in a subset of the fields.
type GetDocumentApiResponseResult struct {
ID int `json:"id"`
Correspondent int `json:"correspondent"`
// DocumentType interface{} `json:"document_type"`
// StoragePath interface{} `json:"storage_path"`
Title string `json:"title"`
Content string `json:"content"`
Tags []int `json:"tags"`
// Created time.Time `json:"created"`
CreatedDate string `json:"created_date"`
// Modified time.Time `json:"modified"`
// Added time.Time `json:"added"`
// ArchiveSerialNumber interface{} `json:"archive_serial_number"`
// OriginalFileName string `json:"original_file_name"`
// ArchivedFileName string `json:"archived_file_name"`
// Owner int `json:"owner"`
// UserCanChange bool `json:"user_can_change"`
Notes []interface{} `json:"notes"`
// SearchHit struct {
// Score float64 `json:"score"`
// Highlights string `json:"highlights"`
// NoteHighlights string `json:"note_highlights"`
// Rank int `json:"rank"`
// } `json:"__search_hit__"`
}
// CustomFieldResponse represents a custom field with its value for a document
type CustomFieldResponse struct {
Field int `json:"field"`
Value interface{} `json:"value"`
Name string `json:"name,omitempty"`
}
// CustomFieldSuggestion represents a suggested custom field with its value and name
type CustomFieldSuggestion struct {
ID int `json:"id"`
Name string `json:"name"`
Value interface{} `json:"value"`
}
// GetDocumentApiResponse is the response payload for /documents/{id} endpoint.
// But we are only interested in a subset of the fields.
type GetDocumentApiResponse struct {
ID int `json:"id"`
Correspondent int `json:"correspondent"`
DocumentType int `json:"document_type"`
Title string `json:"title"`
Content string `json:"content"`
Tags []int `json:"tags"`
CreatedDate string `json:"created_date"`
OriginalFileName string `json:"original_file_name"`
Notes []interface{} `json:"notes"`
CustomFields []CustomFieldResponse `json:"custom_fields"`
}
// Document is a stripped down version of the document object from paperless-ngx.
// Response payload for /documents endpoint and part of request payload for /generate-suggestions endpoint
type Document struct {
ID int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Tags []string `json:"tags"`
Correspondent string `json:"correspondent"`
CreatedDate string `json:"created_date"`
OriginalFileName string `json:"original_file_name"`
DocumentTypeName string `json:"document_type_name"`
CustomFields []CustomFieldResponse `json:"custom_fields"`
}
// GenerateSuggestionsRequest is the request payload for generating suggestions for /generate-suggestions endpoint
type GenerateSuggestionsRequest struct {
Documents []Document `json:"documents"`
GenerateTitles bool `json:"generate_titles,omitempty"`
GenerateTags bool `json:"generate_tags,omitempty"`
GenerateCorrespondents bool `json:"generate_correspondents,omitempty"`
GenerateCreatedDate bool `json:"generate_created_date,omitempty"`
GenerateCustomFields bool `json:"generate_custom_fields,omitempty"`
}
// AnalyzeDocumentsRequest is the request payload for the ad-hoc analysis
type AnalyzeDocumentsRequest struct {
DocumentIDs []int `json:"document_ids"`
Prompt string `json:"prompt"`
}
// Settings defines the structure for server-side UI settings
type Settings struct {
CustomFieldsEnable bool `json:"custom_fields_enable"`
CustomFieldsSelectedIDs []int `json:"custom_fields_selected_ids"`
CustomFieldsWriteMode string `json:"custom_fields_write_mode"` // "append" or "replace"
}
// DocumentSuggestion is the response payload for /generate-suggestions endpoint and the request payload for /update-documents endpoint (as an array)
type DocumentSuggestion struct {
ID int `json:"id"`
OriginalDocument Document `json:"original_document"`
SuggestedTitle string `json:"suggested_title,omitempty"`
SuggestedTags []string `json:"suggested_tags,omitempty"`
SuggestedContent string `json:"suggested_content,omitempty"`
SuggestedCorrespondent string `json:"suggested_correspondent,omitempty"`
SuggestedCreatedDate string `json:"suggested_created_date,omitempty"`
SuggestedCustomFields []CustomFieldSuggestion `json:"suggested_custom_fields,omitempty"`
KeepOriginalTags bool `json:"keep_original_tags,omitempty"`
RemoveTags []string `json:"remove_tags,omitempty"`
AddTags []string `json:"add_tags,omitempty"`
CustomFieldsWriteMode string `json:"custom_fields_write_mode,omitempty"`
CustomFieldsEnable bool `json:"custom_fields_enable"`
}
type Correspondent struct {
Name string `json:"name"`
MatchingAlgorithm int `json:"matching_algorithm"`
Match string `json:"match"`
IsInsensitive bool `json:"is_insensitive"`
Owner *int `json:"owner"`
SetPermissions struct {
View struct {
Users []int `json:"users"`
Groups []int `json:"groups"`
} `json:"view"`
Change struct {
Users []int `json:"users"`
Groups []int `json:"groups"`
} `json:"change"`
} `json:"set_permissions"`
}
// OCROptions contains options for the OCR processing
type OCROptions struct {
UploadPDF bool // Whether to upload the generated PDF
ReplaceOriginal bool // Whether to delete the original document after uploading
CopyMetadata bool // Whether to copy metadata from the original document
LimitPages int // Limit on the number of pages to process (0 = no limit)
ProcessMode string // OCR processing mode: "image" (default) or "pdf"
}
// ClientInterface defines the interface for PaperlessClient operations
type ClientInterface interface {
GetDocumentsByTags(ctx context.Context, tags []string, pageSize int) ([]Document, error)
UpdateDocuments(ctx context.Context, documents []DocumentSuggestion, db *gorm.DB, isUndo bool) error
GetDocument(ctx context.Context, documentID int) (Document, error)
GetAllTags(ctx context.Context) (map[string]int, error)
GetAllCorrespondents(ctx context.Context) (map[string]int, error)
GetAllDocumentTypes(ctx context.Context) ([]DocumentType, error)
GetCustomFields(ctx context.Context) ([]CustomField, error)
CreateTag(ctx context.Context, tagName string) (int, error)
DownloadDocumentAsImages(ctx context.Context, documentID int, pageLimit int) ([]string, int, error)
DownloadDocumentAsPDF(ctx context.Context, documentID int, limitPages int, split bool) ([]string, []byte, int, error)
UploadDocument(ctx context.Context, data []byte, filename string, metadata map[string]interface{}) (string, error)
GetTaskStatus(ctx context.Context, taskID string) (map[string]interface{}, error)
DeleteDocument(ctx context.Context, documentID int) error
}
// DocumentProcessor defines the interface for processing documents with OCR
type DocumentProcessor interface {
ProcessDocumentOCR(ctx context.Context, documentID int, options OCROptions, jobID string) (*ProcessedDocument, error)
}