2021-12-03 08:00:40 -05:00
|
|
|
import express from 'express'
|
2023-07-31 08:34:36 -04:00
|
|
|
import { buildLogger } from '@server/helpers/logger.js'
|
|
|
|
import { getResumableUploadPath } from '@server/helpers/upload.js'
|
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
2022-11-07 04:40:43 -05:00
|
|
|
import { LogLevel, Uploadx } from '@uploadx/core'
|
2023-04-21 08:55:10 -04:00
|
|
|
import { extname } from 'path'
|
2022-11-07 04:40:43 -05:00
|
|
|
|
|
|
|
const logger = buildLogger('uploadx')
|
2021-12-03 08:00:40 -05:00
|
|
|
|
2021-12-17 09:49:52 -05:00
|
|
|
const uploadx = new Uploadx({
|
|
|
|
directory: getResumableUploadPath(),
|
2022-04-19 05:44:03 -04:00
|
|
|
|
|
|
|
expiration: { maxAge: undefined, rolling: true },
|
|
|
|
|
2021-12-17 09:49:52 -05:00
|
|
|
// Could be big with thumbnails/previews
|
2022-01-18 03:29:46 -05:00
|
|
|
maxMetadataSize: '10MB',
|
2022-04-19 05:44:03 -04:00
|
|
|
|
2022-11-07 04:40:43 -05:00
|
|
|
logger: {
|
|
|
|
logLevel: CONFIG.LOG.LEVEL as LogLevel,
|
|
|
|
debug: logger.debug.bind(logger),
|
|
|
|
info: logger.info.bind(logger),
|
|
|
|
warn: logger.warn.bind(logger),
|
|
|
|
error: logger.error.bind(logger)
|
|
|
|
},
|
2022-10-28 04:47:06 -04:00
|
|
|
|
2022-01-18 03:29:46 -05:00
|
|
|
userIdentifier: (_, res: express.Response) => {
|
|
|
|
if (!res.locals.oauth) return undefined
|
|
|
|
|
|
|
|
return res.locals.oauth.token.user.id + ''
|
2023-04-21 08:55:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
filename: file => `${file.userId}-${file.id}${extname(file.metadata.filename)}`
|
2021-12-17 09:49:52 -05:00
|
|
|
})
|
2021-12-03 08:00:40 -05:00
|
|
|
|
|
|
|
export {
|
|
|
|
uploadx
|
|
|
|
}
|