@geekbeer/minion 3.27.0 → 3.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/linux/routes/files.js +28 -2
- package/package.json +1 -1
- package/win/routes/files.js +28 -2
package/linux/routes/files.js
CHANGED
|
@@ -16,6 +16,28 @@ const fsSync = require('fs')
|
|
|
16
16
|
const path = require('path')
|
|
17
17
|
const { spawn } = require('child_process')
|
|
18
18
|
|
|
19
|
+
/** Map file extensions to MIME types for preview */
|
|
20
|
+
const PREVIEW_MIME_TYPES = {
|
|
21
|
+
'.md': 'text/markdown; charset=utf-8',
|
|
22
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
23
|
+
'.log': 'text/plain; charset=utf-8',
|
|
24
|
+
'.csv': 'text/csv; charset=utf-8',
|
|
25
|
+
'.json': 'application/json; charset=utf-8',
|
|
26
|
+
'.xml': 'application/xml; charset=utf-8',
|
|
27
|
+
'.yaml': 'text/yaml; charset=utf-8',
|
|
28
|
+
'.yml': 'text/yaml; charset=utf-8',
|
|
29
|
+
'.toml': 'text/plain; charset=utf-8',
|
|
30
|
+
'.pdf': 'application/pdf',
|
|
31
|
+
'.png': 'image/png',
|
|
32
|
+
'.jpg': 'image/jpeg',
|
|
33
|
+
'.jpeg': 'image/jpeg',
|
|
34
|
+
'.gif': 'image/gif',
|
|
35
|
+
'.webp': 'image/webp',
|
|
36
|
+
'.svg': 'image/svg+xml',
|
|
37
|
+
'.ico': 'image/x-icon',
|
|
38
|
+
'.bmp': 'image/bmp',
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
const { verifyToken } = require('../../core/lib/auth')
|
|
20
42
|
const { config } = require('../../core/config')
|
|
21
43
|
|
|
@@ -176,9 +198,13 @@ async function fileRoutes(fastify) {
|
|
|
176
198
|
}
|
|
177
199
|
|
|
178
200
|
const filename = path.basename(resolved)
|
|
201
|
+
const isPreview = request.query.preview === 'true'
|
|
202
|
+
const ext = path.extname(filename).toLowerCase()
|
|
203
|
+
const mimeType = isPreview && PREVIEW_MIME_TYPES[ext]
|
|
204
|
+
|
|
179
205
|
reply
|
|
180
|
-
.type('application/octet-stream')
|
|
181
|
-
.header('Content-Disposition',
|
|
206
|
+
.type(mimeType || 'application/octet-stream')
|
|
207
|
+
.header('Content-Disposition', `${isPreview && mimeType ? 'inline' : 'attachment'}; filename="${encodeURIComponent(filename)}"`)
|
|
182
208
|
.header('Content-Length', stat.size)
|
|
183
209
|
|
|
184
210
|
return reply.send(fsSync.createReadStream(resolved))
|
package/package.json
CHANGED
package/win/routes/files.js
CHANGED
|
@@ -13,6 +13,28 @@ const zlib = require('zlib')
|
|
|
13
13
|
const { verifyToken } = require('../../core/lib/auth')
|
|
14
14
|
const { config } = require('../../core/config')
|
|
15
15
|
|
|
16
|
+
/** Map file extensions to MIME types for preview */
|
|
17
|
+
const PREVIEW_MIME_TYPES = {
|
|
18
|
+
'.md': 'text/markdown; charset=utf-8',
|
|
19
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
20
|
+
'.log': 'text/plain; charset=utf-8',
|
|
21
|
+
'.csv': 'text/csv; charset=utf-8',
|
|
22
|
+
'.json': 'application/json; charset=utf-8',
|
|
23
|
+
'.xml': 'application/xml; charset=utf-8',
|
|
24
|
+
'.yaml': 'text/yaml; charset=utf-8',
|
|
25
|
+
'.yml': 'text/yaml; charset=utf-8',
|
|
26
|
+
'.toml': 'text/plain; charset=utf-8',
|
|
27
|
+
'.pdf': 'application/pdf',
|
|
28
|
+
'.png': 'image/png',
|
|
29
|
+
'.jpg': 'image/jpeg',
|
|
30
|
+
'.jpeg': 'image/jpeg',
|
|
31
|
+
'.gif': 'image/gif',
|
|
32
|
+
'.webp': 'image/webp',
|
|
33
|
+
'.svg': 'image/svg+xml',
|
|
34
|
+
'.ico': 'image/x-icon',
|
|
35
|
+
'.bmp': 'image/bmp',
|
|
36
|
+
}
|
|
37
|
+
|
|
16
38
|
const FILES_DIR = path.join(config.HOME_DIR, 'files')
|
|
17
39
|
const MAX_UPLOAD_SIZE = 50 * 1024 * 1024
|
|
18
40
|
|
|
@@ -173,9 +195,13 @@ async function fileRoutes(fastify) {
|
|
|
173
195
|
}
|
|
174
196
|
|
|
175
197
|
const filename = path.basename(resolved)
|
|
198
|
+
const isPreview = request.query.preview === 'true'
|
|
199
|
+
const ext = path.extname(filename).toLowerCase()
|
|
200
|
+
const mimeType = isPreview && PREVIEW_MIME_TYPES[ext]
|
|
201
|
+
|
|
176
202
|
reply
|
|
177
|
-
.type('application/octet-stream')
|
|
178
|
-
.header('Content-Disposition',
|
|
203
|
+
.type(mimeType || 'application/octet-stream')
|
|
204
|
+
.header('Content-Disposition', `${isPreview && mimeType ? 'inline' : 'attachment'}; filename="${encodeURIComponent(filename)}"`)
|
|
179
205
|
.header('Content-Length', stat.size)
|
|
180
206
|
|
|
181
207
|
return reply.send(fsSync.createReadStream(resolved))
|