docs: uploadController.js

This commit is contained in:
Bobby 2022-04-16 20:44:11 +07:00
parent fff5ebbdd4
commit 4b9740cf5c
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09

View File

@ -20,6 +20,8 @@ const self = {
onHold: new Set()
}
/** Preferences */
const fileIdentifierLengthFallback = 32
const fileIdentifierLengthChangeable = !config.uploads.fileIdentifierLength.force &&
typeof config.uploads.fileIdentifierLength.min === 'number' &&
@ -48,6 +50,8 @@ const urlExtensionsFilter = Array.isArray(config.uploads.urlExtensionsFilter) &&
const temporaryUploads = Array.isArray(config.uploads.temporaryUploadAges) &&
config.uploads.temporaryUploadAges.length
/** Chunks helper class & function **/
class ChunksData {
constructor (uuid, root) {
this.uuid = uuid
@ -96,6 +100,8 @@ const initChunks = async uuid => {
return chunksData[uuid]
}
/** Multer */
const executeMulter = multer({
// Guide: https://github.com/expressjs/multer#limits
limits: {
@ -164,6 +170,8 @@ const executeMulter = multer({
})
}).array('files[]')
/** Helper functions */
self.isExtensionFiltered = extname => {
// If empty extension needs to be filtered
if (!extname && config.filterNoExtension) return true
@ -257,6 +265,8 @@ self.parseStripTags = stripTags => {
return Boolean(parseInt(stripTags))
}
/** Uploads */
self.upload = async (req, res, next) => {
try {
let user
@ -357,6 +367,8 @@ self.actuallyUploadFiles = async (req, res, user, albumid, age) => {
return self.sendUploadResponse(req, res, user, result)
}
/** URL uploads */
self.actuallyUploadUrls = async (req, res, user, albumid, age) => {
if (!config.uploads.urlMaxSize) {
throw new ClientError('Upload by URLs is disabled at the moment.', { statusCode: 403 })
@ -477,6 +489,8 @@ self.actuallyUploadUrls = async (req, res, user, albumid, age) => {
}
}
/** Chunk uploads */
self.finishChunks = async (req, res, next) => {
try {
if (!chunkedUploads) {
@ -620,6 +634,8 @@ self.cleanUpChunks = async (uuid, onTimeout) => {
delete chunksData[uuid]
}
/** Virus scanning (ClamAV) */
self.assertPassthroughScans = async (req, user, infoMap) => {
const foundThreats = []
const unableToScan = []
@ -710,6 +726,8 @@ self.scanFiles = async (req, user, infoMap) => {
return result
}
/** Strip tags (EXIF, etc.) */
self.stripTags = async (req, infoMap) => {
if (!self.parseStripTags(req.headers.striptags)) return
@ -729,6 +747,8 @@ self.stripTags = async (req, infoMap) => {
}
}
/** Database functions */
self.storeFilesToDb = async (req, res, user, infoMap) => {
const files = []
const exists = []
@ -839,6 +859,8 @@ self.storeFilesToDb = async (req, res, user, infoMap) => {
return [...files, ...exists]
}
/** Final response */
self.sendUploadResponse = async (req, res, user, result) => {
// Send response
return res.json({
@ -874,6 +896,8 @@ self.sendUploadResponse = async (req, res, user, result) => {
})
}
/** Delete uploads */
self.delete = async (req, res, next) => {
// Map /api/delete requests to /api/bulkdelete
let body
@ -915,6 +939,8 @@ self.bulkDelete = async (req, res, next) => {
}
}
/** List uploads */
self.list = async (req, res, next) => {
try {
const user = await utils.authorize(req)