filesafe/routes/nojs.js
Bobby Wibowo bd722129de
Updates, now supports uploading by URLs!
* Added upload by URLs. It has its own max size (config.uploads.urlMaxSize), make sure your config matches config.sample.js.
Here's a brief video showing it in action: https://i.fiery.me/CUhQ.mp4.

* /api/upload now supports uploading by URLs. Devs will only need to POST a JSON request containing a key named "urls", which is an array of the urls to upload.

* Added file extension filter to /api/upload/finishchunks.

* Added proper total chunks size check to /api/upload/finishchunks.

* Various code improvements.
2018-05-11 21:34:13 +07:00

40 lines
1.0 KiB
JavaScript

const config = require('./../config')
const routes = require('express').Router()
const uploadController = require('./../controllers/uploadController')
const renderOptions = {
uploadDisabled: false,
maxFileSize: config.cloudflare.noJsMaxSize || config.uploads.maxSize
}
if (config.private) {
if (config.enableUserAccounts) {
renderOptions.uploadDisabled = 'Anonymous upload is disabled.'
} else {
renderOptions.uploadDisabled = 'Running in private mode.'
}
}
routes.get('/nojs', async (req, res, next) => {
return res.render('nojs', { renderOptions })
})
routes.post('/nojs', (req, res, next) => {
// TODO: Support upload by URLs.
res._json = res.json
res.json = (...args) => {
const result = args[0]
const options = { renderOptions }
options.errorMessage = result.success ? '' : (result.description || 'An unexpected error occurred.')
options.files = result.files || [{}]
return res.render('nojs', options)
}
return uploadController.upload(req, res, next)
})
module.exports = routes