overleaf/services/web/app/coffee/Features/Uploads/ProjectUploadController.coffee
Ersun Warncke 362c1f64db Merge pull request #1252 from sharelatex/ew-collabratec-upload-fix-v1-proxy
upgrade to latest (forked) version of multer, proxy collabratec uploads

GitOrigin-RevId: 682caf12a81ee828e544a5e3903ea49bbd173fe0
2018-12-13 13:09:26 +00:00

54 lines
2 KiB
CoffeeScript

logger = require "logger-sharelatex"
metrics = require "metrics-sharelatex"
fs = require "fs"
Path = require "path"
FileSystemImportManager = require "./FileSystemImportManager"
ProjectUploadManager = require "./ProjectUploadManager"
AuthenticationController = require('../Authentication/AuthenticationController')
module.exports = ProjectUploadController =
uploadProject: (req, res, next) ->
timer = new metrics.Timer("project-upload")
user_id = AuthenticationController.getLoggedInUserId(req)
{originalname, path} = req.file
name = Path.basename(originalname, ".zip")
ProjectUploadManager.createProjectFromZipArchive user_id, name, path, (error, project) ->
fs.unlink path, ->
timer.done()
if error?
logger.error
err: error, file_path: path, file_name: name,
"error uploading project"
res.send success: false
else
logger.log
project: project._id, file_path: path, file_name: name,
"uploaded project"
res.send success: true, project_id: project._id
uploadFile: (req, res, next) ->
timer = new metrics.Timer("file-upload")
name = req.file?.originalname
path = req.file?.path
project_id = req.params.Project_id
folder_id = req.query.folder_id
if !name? or name.length == 0 or name.length > 150
logger.err project_id:project_id, name:name, "bad name when trying to upload file"
return res.send success: false
logger.log folder_id:folder_id, project_id:project_id, "getting upload file request"
user_id = AuthenticationController.getLoggedInUserId(req)
FileSystemImportManager.addEntity user_id, project_id, folder_id, name, path, true, (error, entity) ->
fs.unlink path, ->
timer.done()
if error?
logger.error
err: error, project_id: project_id, file_path: path,
file_name: name, folder_id: folder_id,
"error uploading file"
res.send success: false
else
logger.log
project_id: project_id, file_path: path, file_name: name, folder_id: folder_id
"uploaded file"
res.send success: true, entity_id: entity?._id, entity_type: entity?.type