mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add in a few null checks
These were discovered by using a project that was messed up with the moving folder bug where the folder ended up without an id, docs or fileRefs array
This commit is contained in:
parent
9706585d21
commit
3d8ac9f292
3 changed files with 13 additions and 11 deletions
|
@ -46,12 +46,12 @@ module.exports = ProjectEditorHandler =
|
|||
signUpDate : user.signUpDate
|
||||
|
||||
buildFolderModelView: (folder) ->
|
||||
fileRefs = _.filter folder.fileRefs, (file)-> file?
|
||||
fileRefs = _.filter (folder.fileRefs or []), (file)-> file?
|
||||
_id : folder._id
|
||||
name : folder.name
|
||||
folders : @buildFolderModelView childFolder for childFolder in folder.folders
|
||||
folders : @buildFolderModelView childFolder for childFolder in (folder.folders or [])
|
||||
fileRefs : @buildFileModelView file for file in fileRefs
|
||||
docs : @buildDocModelView doc for doc in folder.docs
|
||||
docs : @buildDocModelView doc for doc in (folder.docs or [])
|
||||
|
||||
buildFileModelView: (file) ->
|
||||
_id : file._id
|
||||
|
|
|
@ -22,7 +22,9 @@ module.exports = ProjectEntityHandler =
|
|||
folders = {}
|
||||
processFolder = (basePath, folder) ->
|
||||
folders[basePath] = folder
|
||||
processFolder path.join(basePath, childFolder.name), childFolder for childFolder in folder.folders
|
||||
for childFolder in (folder.folders or [])
|
||||
if childFolder.name?
|
||||
processFolder path.join(basePath, childFolder.name), childFolder
|
||||
|
||||
ProjectGetter.getProjectWithoutDocLines project_id, (err, project) ->
|
||||
return callback(err) if err?
|
||||
|
@ -43,11 +45,11 @@ module.exports = ProjectEntityHandler =
|
|||
for docContent in docContentsArray
|
||||
docContents[docContent._id] = docContent
|
||||
|
||||
ProjectEntityHandler.getAllFolders project_id, (error, folders) ->
|
||||
ProjectEntityHandler.getAllFolders project_id, (error, folders = {}) ->
|
||||
return callback(error) if error?
|
||||
docs = {}
|
||||
for folderPath, folder of folders
|
||||
for doc in folder.docs
|
||||
for doc in (folder.docs or [])
|
||||
content = docContents[doc._id.toString()]
|
||||
if content?
|
||||
docs[path.join(folderPath, doc.name)] = {
|
||||
|
@ -61,11 +63,11 @@ module.exports = ProjectEntityHandler =
|
|||
|
||||
getAllFiles: (project_id, callback) ->
|
||||
logger.log project_id:project_id, "getting all files for project"
|
||||
@getAllFolders project_id, (err, folders) ->
|
||||
@getAllFolders project_id, (err, folders = {}) ->
|
||||
return callback(err) if err?
|
||||
files = {}
|
||||
for folderPath, folder of folders
|
||||
for file in folder.fileRefs
|
||||
for file in (folder.fileRefs or [])
|
||||
if file?
|
||||
files[path.join(folderPath, file.name)] = file
|
||||
callback null, files
|
||||
|
|
|
@ -20,13 +20,13 @@ module.exports = ReferencesHandler =
|
|||
ids = []
|
||||
|
||||
_process = (folder) ->
|
||||
folder.docs.forEach (doc) ->
|
||||
(folder.docs or []).forEach (doc) ->
|
||||
if doc?.name?.match(/^.*\.bib$/)
|
||||
ids.push(doc._id)
|
||||
folder.folders.forEach (folder) ->
|
||||
(folder.folders or []).forEach (folder) ->
|
||||
_process(folder)
|
||||
|
||||
project.rootFolder.forEach (rootFolder) ->
|
||||
(project.rootFolder or []).forEach (rootFolder) ->
|
||||
_process(rootFolder)
|
||||
|
||||
return ids
|
||||
|
|
Loading…
Reference in a new issue