1 import express from 'express'
2 import { buildLogger } from '@server/helpers/logger'
3 import { getResumableUploadPath } from '@server/helpers/upload'
4 import { CONFIG } from '@server/initializers/config'
5 import { LogLevel, Uploadx } from '@uploadx/core'
6 import { extname } from 'path'
8 const logger = buildLogger('uploadx')
10 const uploadx = new Uploadx({
11 directory: getResumableUploadPath(),
13 expiration: { maxAge: undefined, rolling: true },
15 // Could be big with thumbnails/previews
16 maxMetadataSize: '10MB',
19 logLevel: CONFIG.LOG.LEVEL as LogLevel,
20 debug: logger.debug.bind(logger),
21 info: logger.info.bind(logger),
22 warn: logger.warn.bind(logger),
23 error: logger.error.bind(logger)
26 userIdentifier: (_, res: express.Response) => {
27 if (!res.locals.oauth) return undefined
29 return res.locals.oauth.token.user.id + ''
32 filename: file => `${file.userId}-${file.id}${extname(file.metadata.filename)}`