-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathFileConfig.ts
More file actions
205 lines (186 loc) · 7.39 KB
/
FileConfig.ts
File metadata and controls
205 lines (186 loc) · 7.39 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import { z } from "zod";
import { DuplexAssemblyMode } from "./DuplexAssemblyMode.js";
import { ScanFormat, parseScanFormat } from "./scanFormat.js";
import { parseScanMode, ScanMode } from "./scanMode.js";
// Configuration schema for the config file
export const configSchema = z
.strictObject({
///
/// Network and Identification
///
ip: z.string().optional(), // IP address of the device (optional)
name: z.string().optional(), // Device name (used for mDNS if IP is not set)
label: z.string().optional(), // Display label on the device screen
///
/// Connectivity & Debug
///
deviceUpPollingInterval: z.number().min(0).optional(), // Polling interval (ms) to check if device is reachable
debug: z.boolean().optional(), // Enable debug mode for reporting issues
///
/// Directories & File Naming
///
directory: z.string().optional(), // Directory to store scan results
tempDirectory: z.string().optional(), // Temporary directory for file processing
pattern: z.string().optional(), // Pattern for naming scanned files
///
/// Scan Settings
///
// Note: width/height = 0 is treated as "not configured" by the business logic
// width/height = "max" means "use device maximum"
width: z
.union([
z.number().int().min(0), // 0 or positive integer (0 = not configured)
z.literal("max"), // The string "max"
])
.optional(), // Scan width in pixels
height: z
.union([
z.number().int().min(0), // 0 or positive integer (0 = not configured)
z.literal("max"), // The string "max"
])
.optional(), // Scan height in pixels
resolution: z.number().int().positive().optional(), // DPI resolution
mode: z
.preprocess(
(val) => {
if (typeof val !== "string") {
return val;
}
return parseScanMode(val.toLowerCase());
},
z.enum(Object.values(ScanMode) as [ScanMode, ...ScanFormat[]]),
)
.optional(), // The scan mode
image_format: z
.preprocess(
(val) => {
if (typeof val !== "string") {
return val;
}
return parseScanFormat(val.toLowerCase());
},
z.enum(Object.values(ScanFormat) as [ScanFormat, ...ScanFormat[]]),
)
.optional(),
paper_size: z.string().optional(), // Paper size preset (A4, Letter, Legal, A5, B5, Max)
paper_orientation: z.enum(["portrait", "landscape"]).optional(), // Applied to paper_size only
paper_dim: z.string().optional(), // Custom paper dimensions (e.g., "21x29.7cm", "8.5x11in")
prefer_escl: z.boolean().optional(), // Always upload scans as PDF
///
/// Duplex Scanning Options
///
add_emulated_duplex: z.boolean().optional(), // Enable emulated duplex feature
emulated_duplex_label: z.string().optional(), // Label for emulated duplex target
emulated_duplex_assembly_mode: z
.enum(Object.values(DuplexAssemblyMode))
.optional(),
///
/// Single Scan Options
///
single_scan_duplex: z.boolean().optional(), // Use duplex for single scans (if supported)
single_scan_pdf: z.boolean().optional(), // Output format for single scans: PDF (true) or JPG (false)
///
/// Auto Scan (Document Feeder)
///
autoscan_duplex: z.boolean().optional(), // Use duplex for auto scans (if supported)
autoscan_pdf: z.boolean().optional(), // Output format for auto scans: PDF (true) or JPG (false)
autoscan_pollingInterval: z.number().min(0).optional(), // Interval (ms) to poll the document feeder
autoscan_startScanDelay: z.number().min(0).optional(), // Delay (ms) before auto scan starts after feeder is loaded
///
/// Paperless Integration
///
paperless_post_document_url: z.string().optional(), // Paperless POST URL
paperless_token: z.string().optional(), // Paperless API token
paperless_token_file: z.string().optional(), // Paperless API token
paperless_group_multi_page_scan_into_a_pdf: z.boolean().optional(), // Group multi-page scans into a single PDF
paperless_always_send_as_pdf_file: z.boolean().optional(), // Always upload scans as PDF
///
/// Nextcloud Integration
///
nextcloud_url: z.string().optional(), // Nextcloud server URL
nextcloud_username: z.string().optional(), // Nextcloud username
nextcloud_password: z.string().optional(), // Nextcloud password
nextcloud_password_file: z.string().optional(), // Path to file containing Nextcloud password
nextcloud_upload_folder: z.string().optional(), // Upload folder path on Nextcloud
///
/// Common to external destination (paperless & nextcloud)
///
keep_files: z.boolean().optional(), // Keep scanned files locally after upload
///
/// Health Check
///
enableHealthCheck: z.boolean().optional(), // Enable HTTP health check endpoint
healthCheckPort: z.number().int().positive().max(65535).optional(), // Port for health check endpoint
})
.superRefine((value, ctx) => {
if (value.paper_size !== undefined && value.paper_dim !== undefined) {
ctx.addIssue({
code: "custom",
message:
"Config cannot specify both paper_size and paper_dim. Choose one or the other.",
path: ["paper_size"],
});
ctx.addIssue({
code: "custom",
message:
"Config cannot specify both paper_size and paper_dim. Choose one or the other.",
path: ["paper_dim"],
});
}
const hasPaperSizeConfig =
value.paper_size !== undefined || value.paper_dim !== undefined;
// Consider width/height as configured only if they are defined and not 0
// (0 is treated as "not set" in the codebase)
const hasManualWidth =
value.width !== undefined && value.width !== 0 && value.width !== "max";
const hasManualHeight =
value.height !== undefined &&
value.height !== 0 &&
value.height !== "max";
const hasManualSize = hasManualWidth || hasManualHeight;
if (hasPaperSizeConfig && hasManualSize) {
if (hasManualWidth) {
ctx.addIssue({
code: "custom",
message:
"Config cannot specify width/height with paper_size or paper_dim. Choose one or the other.",
path: ["width"],
});
}
if (hasManualHeight) {
ctx.addIssue({
code: "custom",
message:
"Config cannot specify width/height with paper_size or paper_dim. Choose one or the other.",
path: ["height"],
});
}
}
if (value.paper_orientation !== undefined) {
if (value.paper_dim !== undefined) {
ctx.addIssue({
code: "custom",
message:
"paper_orientation cannot be used with paper_dim. Orientation is implicit in custom dimensions.",
path: ["paper_orientation"],
});
}
if (hasManualSize) {
ctx.addIssue({
code: "custom",
message:
"paper_orientation cannot be used with width/height. Orientation is implicit in pixel dimensions.",
path: ["paper_orientation"],
});
}
if (value.paper_size === undefined) {
ctx.addIssue({
code: "custom",
message: "paper_orientation requires paper_size to be set.",
path: ["paper_orientation"],
});
}
}
});
// Infer the TypeScript type from the schema
export type FileConfig = z.infer<typeof configSchema>;