2014-02-12 10:23:40 +00:00
|
|
|
logger = require "logger-sharelatex"
|
2017-04-03 15:18:30 +00:00
|
|
|
metrics = require "metrics-sharelatex"
|
2014-02-12 10:23:40 +00:00
|
|
|
fs = require "fs"
|
|
|
|
Path = require "path"
|
|
|
|
FileSystemImportManager = require "./FileSystemImportManager"
|
|
|
|
ProjectUploadManager = require "./ProjectUploadManager"
|
2016-09-05 14:58:31 +00:00
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
module.exports = ProjectUploadController =
|
|
|
|
uploadProject: (req, res, next) ->
|
|
|
|
timer = new metrics.Timer("project-upload")
|
2016-09-05 14:58:31 +00:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2015-06-30 15:37:21 +00:00
|
|
|
{originalname, path} = req.files.qqfile
|
|
|
|
name = Path.basename(originalname, ".zip")
|
2014-02-12 10:23:40 +00:00
|
|
|
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
|
2016-09-05 14:58:31 +00:00
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
uploadFile: (req, res, next) ->
|
|
|
|
timer = new metrics.Timer("file-upload")
|
2016-08-02 14:36:59 +00:00
|
|
|
name = req.files.qqfile?.originalname
|
|
|
|
path = req.files.qqfile?.path
|
2014-02-12 10:23:40 +00:00
|
|
|
project_id = req.params.Project_id
|
|
|
|
folder_id = req.query.folder_id
|
2015-03-02 12:46:02 +00:00
|
|
|
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
|
2016-02-29 16:03:22 +00:00
|
|
|
logger.log folder_id:folder_id, project_id:project_id, "getting upload file request"
|
2016-09-05 14:58:31 +00:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2018-01-02 12:43:41 +00:00
|
|
|
|
2018-02-01 15:31:42 +00:00
|
|
|
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
|
2017-06-08 14:12:18 +00:00
|
|
|
|