summaryrefslogtreecommitdiff
path: root/app/node_modules/okservices/oks3/index.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-02-23 18:08:38 +0100
committerJules Laplace <julescarbon@gmail.com>2021-02-23 18:08:38 +0100
commit19516de0a43ac5f2b0afc9891bbef09d229ce4e6 (patch)
tree224a5ecb4e3f6130c4a1c6b3b125421ee2d9a6a7 /app/node_modules/okservices/oks3/index.js
parent542ebb603ecd8a60fc1daf50404cbc24a92e1d74 (diff)
allow arbitrary file upload for pdf
Diffstat (limited to 'app/node_modules/okservices/oks3/index.js')
-rw-r--r--app/node_modules/okservices/oks3/index.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js
index cc40b71..41ee3dc 100644
--- a/app/node_modules/okservices/oks3/index.js
+++ b/app/node_modules/okservices/oks3/index.js
@@ -16,6 +16,7 @@ function OKS3(options) {
if (!options.s3)
throw new Error('S3 configuration not provided to OKS3');
+ if (!options.s3.file) options.s3.file = {}
if (!options.s3.image) options.s3.image = {}
if (!options.s3.audio) options.s3.audio = {}
if (!options.s3.video) options.s3.video = {}
@@ -23,6 +24,8 @@ function OKS3(options) {
// Make sure maxbytes property is there - it can be a number,
// or zero/undefined (for no maximum upload size)
if (options.s3.maxbytes) {
+ if (! ('maxbytes' in options.s3.file))
+ options.s3.file.maxbytes = options.s3.maxbytes
if (! ('maxbytes' in options.s3.image))
options.s3.image.maxbytes = options.s3.maxbytes
if (! ('maxbytes' in options.s3.video))
@@ -30,6 +33,8 @@ function OKS3(options) {
if (! ('maxbytes' in options.s3.audio))
options.s3.audio.maxbytes = options.s3.maxbytes
}
+ if (typeof options.s3.file.allowed !== "boolean")
+ options.s3.file.allowed = true
if (typeof options.s3.image.allowed !== "boolean")
options.s3.image.allowed = true
if (typeof options.s3.video.allowed !== "boolean")
@@ -130,7 +135,34 @@ function OKS3(options) {
});
});
-
+
+
+ router.post('/file', mult.single('file'), function(req, res) {
+ d.run(function () {
+
+ if (! options.s3.image.allowed) {
+ return res.status(500).json({ error: "File uploading not permitted" })
+ }
+
+ upload.put({
+ file: req.file,
+ preserveFilename: options.s3.video.preserveFilename,
+ dirname: options.s3.dirname,
+ types: {
+ 'application/pdf': 'pdf',
+ 'text/plain': 'txt',
+ 'text/html': 'html',
+ },
+ unacceptable: function(err){
+ res.json({ error: err })
+ },
+ success: function(url){
+ res.json({ url: url })
+ }
+ })
+
+ });
+ });
function preserveFilename (stream, cb){
cb(null, stream.filename)
}