1
1
const { EncryptionManager } = require ( "../EncryptionManager" ) ;
2
2
3
+ /**
4
+ * @typedef {Object } CollectorOptions
5
+ * @property {string } whisperProvider - The provider to use for whisper, defaults to "local"
6
+ * @property {string } WhisperModelPref - The model to use for whisper if set.
7
+ * @property {string } openAiKey - The API key to use for OpenAI interfacing, mostly passed to OAI Whisper provider.
8
+ * @property {Object } ocr - The OCR options
9
+ * @property {{allowAnyIp: "true"|null|undefined} } runtimeSettings - The runtime settings that are passed to the collector. Persisted across requests.
10
+ */
11
+
3
12
// When running locally will occupy the 0.0.0.0 hostname space but when deployed inside
4
13
// of docker this endpoint is not exposed so it is only on the Docker instances internal network
5
14
// so no additional security is needed on the endpoint directly. Auth is done however by the express
@@ -15,6 +24,10 @@ class CollectorApi {
15
24
console . log ( `\x1b[36m[CollectorApi]\x1b[0m ${ text } ` , ...args ) ;
16
25
}
17
26
27
+ /**
28
+ * Attach options to the request passed to the collector API
29
+ * @returns {CollectorOptions }
30
+ */
18
31
#attachOptions( ) {
19
32
return {
20
33
whisperProvider : process . env . WHISPER_PROVIDER || "local" ,
@@ -23,6 +36,9 @@ class CollectorApi {
23
36
ocr : {
24
37
langList : process . env . TARGET_OCR_LANG || "eng" ,
25
38
} ,
39
+ runtimeSettings : {
40
+ allowAnyIp : process . env . COLLECTOR_ALLOW_ANY_IP ?? "false" ,
41
+ } ,
26
42
} ;
27
43
}
28
44
@@ -45,6 +61,12 @@ class CollectorApi {
45
61
} ) ;
46
62
}
47
63
64
+ /**
65
+ * Process a document
66
+ * - Will append the options to the request body
67
+ * @param {string } filename - The filename of the document to process
68
+ * @returns {Promise<Object> } - The response from the collector API
69
+ */
48
70
async processDocument ( filename = "" ) {
49
71
if ( ! filename ) return false ;
50
72
@@ -75,10 +97,16 @@ class CollectorApi {
75
97
} ) ;
76
98
}
77
99
100
+ /**
101
+ * Process a link
102
+ * - Will append the options to the request body
103
+ * @param {string } link - The link to process
104
+ * @returns {Promise<Object> } - The response from the collector API
105
+ */
78
106
async processLink ( link = "" ) {
79
107
if ( ! link ) return false ;
80
108
81
- const data = JSON . stringify ( { link } ) ;
109
+ const data = JSON . stringify ( { link, options : this . #attachOptions ( ) } ) ;
82
110
return await fetch ( `${ this . endpoint } /process-link` , {
83
111
method : "POST" ,
84
112
headers : {
@@ -101,8 +129,19 @@ class CollectorApi {
101
129
} ) ;
102
130
}
103
131
132
+ /**
133
+ * Process raw text as a document for the collector
134
+ * - Will append the options to the request body
135
+ * @param {string } textContent - The text to process
136
+ * @param {Object } metadata - The metadata to process
137
+ * @returns {Promise<Object> } - The response from the collector API
138
+ */
104
139
async processRawText ( textContent = "" , metadata = { } ) {
105
- const data = JSON . stringify ( { textContent, metadata } ) ;
140
+ const data = JSON . stringify ( {
141
+ textContent,
142
+ metadata,
143
+ options : this . #attachOptions( ) ,
144
+ } ) ;
106
145
return await fetch ( `${ this . endpoint } /process-raw-text` , {
107
146
method : "POST" ,
108
147
headers : {
@@ -151,10 +190,21 @@ class CollectorApi {
151
190
} ) ;
152
191
}
153
192
193
+ /**
194
+ * Get the content of a link only in a specific format
195
+ * - Will append the options to the request body
196
+ * @param {string } link - The link to get the content of
197
+ * @param {"text"|"html" } captureAs - The format to capture the content as
198
+ * @returns {Promise<Object> } - The response from the collector API
199
+ */
154
200
async getLinkContent ( link = "" , captureAs = "text" ) {
155
201
if ( ! link ) return false ;
156
202
157
- const data = JSON . stringify ( { link, captureAs } ) ;
203
+ const data = JSON . stringify ( {
204
+ link,
205
+ captureAs,
206
+ options : this . #attachOptions( ) ,
207
+ } ) ;
158
208
return await fetch ( `${ this . endpoint } /util/get-link` , {
159
209
method : "POST" ,
160
210
headers : {
0 commit comments