mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
separate out file uploads
This commit is contained in:
parent
cdfa2de68d
commit
d949338ed4
1 changed files with 23 additions and 28 deletions
|
@ -140,19 +140,24 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback null, doc, folder_id
|
callback null, doc, folder_id
|
||||||
|
|
||||||
|
uploadFile: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (error, fileRef, fileStoreUrl) ->)->
|
||||||
|
if not SafePath.isCleanFilename fileName
|
||||||
|
return callback new Errors.InvalidNameError("invalid element name")
|
||||||
|
fileRef = new File(
|
||||||
|
name: fileName
|
||||||
|
linkedFileData: linkedFileData
|
||||||
|
)
|
||||||
|
FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
|
||||||
|
if err?
|
||||||
|
logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error uploading image to s3"
|
||||||
|
return callback(err)
|
||||||
|
callback(null, fileRef, fileStoreUrl)
|
||||||
|
|
||||||
addFile: wrapWithLock
|
addFile: wrapWithLock
|
||||||
beforeLock: (next) ->
|
beforeLock: (next) ->
|
||||||
(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (error, fileRef, folder_id) ->)->
|
(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback) ->
|
||||||
if not SafePath.isCleanFilename fileName
|
ProjectEntityUpdateHandler.uploadFile project_id, folder_id, fileName, fsPath, linkedFileData, userId, (error, fileRef, fileStoreUrl) ->
|
||||||
return callback new Errors.InvalidNameError("invalid element name")
|
return callback(error) if error?
|
||||||
fileRef = new File(
|
|
||||||
name: fileName
|
|
||||||
linkedFileData: linkedFileData
|
|
||||||
)
|
|
||||||
FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
|
|
||||||
if err?
|
|
||||||
logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error uploading image to s3"
|
|
||||||
return callback(err)
|
|
||||||
next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
|
next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
|
||||||
withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id) ->)->
|
withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id) ->)->
|
||||||
ProjectEntityMongoUpdateHandler.addFile project_id, folder_id, fileRef, (err, result, project) ->
|
ProjectEntityMongoUpdateHandler.addFile project_id, folder_id, fileRef, (err, result, project) ->
|
||||||
|
@ -214,23 +219,13 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
callback(null, doc, folder_id, result?.path?.fileSystem)
|
callback(null, doc, folder_id, result?.path?.fileSystem)
|
||||||
|
|
||||||
addFileWithoutUpdatingHistory: wrapWithLock
|
addFileWithoutUpdatingHistory: wrapWithLock
|
||||||
|
# This method should never be called directly, except when importing a project
|
||||||
|
# from Overleaf. It skips sending updates to the project history, which will break
|
||||||
|
# the history unless you are making sure it is updated in some other way.
|
||||||
beforeLock: (next) ->
|
beforeLock: (next) ->
|
||||||
(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
|
(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback) ->
|
||||||
# This method should never be called directly, except when importing a project
|
ProjectEntityUpdateHandler.uploadFile project_id, folder_id, fileName, fsPath, linkedFileData, userId, (error, fileRef, fileStoreUrl) ->
|
||||||
# from Overleaf. It skips sending updates to the project history, which will break
|
return callback(error) if error?
|
||||||
# the history unless you are making sure it is updated in some other way.
|
|
||||||
|
|
||||||
if not SafePath.isCleanFilename fileName
|
|
||||||
return callback new Errors.InvalidNameError("invalid element name")
|
|
||||||
|
|
||||||
fileRef = new File(
|
|
||||||
name: fileName
|
|
||||||
linkedFileData: linkedFileData
|
|
||||||
)
|
|
||||||
FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
|
|
||||||
if err?
|
|
||||||
logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error uploading image to s3"
|
|
||||||
return callback(err)
|
|
||||||
next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
|
next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
|
||||||
withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
|
withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
|
||||||
ProjectEntityMongoUpdateHandler.addFile project_id, folder_id, fileRef, (err, result, project) ->
|
ProjectEntityMongoUpdateHandler.addFile project_id, folder_id, fileRef, (err, result, project) ->
|
||||||
|
|
Loading…
Reference in a new issue