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
|
signUpDate : user.signUpDate
|
||||||
|
|
||||||
buildFolderModelView: (folder) ->
|
buildFolderModelView: (folder) ->
|
||||||
fileRefs = _.filter folder.fileRefs, (file)-> file?
|
fileRefs = _.filter (folder.fileRefs or []), (file)-> file?
|
||||||
_id : folder._id
|
_id : folder._id
|
||||||
name : folder.name
|
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
|
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) ->
|
buildFileModelView: (file) ->
|
||||||
_id : file._id
|
_id : file._id
|
||||||
|
|
|
@ -22,7 +22,9 @@ module.exports = ProjectEntityHandler =
|
||||||
folders = {}
|
folders = {}
|
||||||
processFolder = (basePath, folder) ->
|
processFolder = (basePath, folder) ->
|
||||||
folders[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) ->
|
ProjectGetter.getProjectWithoutDocLines project_id, (err, project) ->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
|
@ -43,11 +45,11 @@ module.exports = ProjectEntityHandler =
|
||||||
for docContent in docContentsArray
|
for docContent in docContentsArray
|
||||||
docContents[docContent._id] = docContent
|
docContents[docContent._id] = docContent
|
||||||
|
|
||||||
ProjectEntityHandler.getAllFolders project_id, (error, folders) ->
|
ProjectEntityHandler.getAllFolders project_id, (error, folders = {}) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
docs = {}
|
docs = {}
|
||||||
for folderPath, folder of folders
|
for folderPath, folder of folders
|
||||||
for doc in folder.docs
|
for doc in (folder.docs or [])
|
||||||
content = docContents[doc._id.toString()]
|
content = docContents[doc._id.toString()]
|
||||||
if content?
|
if content?
|
||||||
docs[path.join(folderPath, doc.name)] = {
|
docs[path.join(folderPath, doc.name)] = {
|
||||||
|
@ -61,11 +63,11 @@ module.exports = ProjectEntityHandler =
|
||||||
|
|
||||||
getAllFiles: (project_id, callback) ->
|
getAllFiles: (project_id, callback) ->
|
||||||
logger.log project_id:project_id, "getting all files for project"
|
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?
|
return callback(err) if err?
|
||||||
files = {}
|
files = {}
|
||||||
for folderPath, folder of folders
|
for folderPath, folder of folders
|
||||||
for file in folder.fileRefs
|
for file in (folder.fileRefs or [])
|
||||||
if file?
|
if file?
|
||||||
files[path.join(folderPath, file.name)] = file
|
files[path.join(folderPath, file.name)] = file
|
||||||
callback null, files
|
callback null, files
|
||||||
|
|
|
@ -20,13 +20,13 @@ module.exports = ReferencesHandler =
|
||||||
ids = []
|
ids = []
|
||||||
|
|
||||||
_process = (folder) ->
|
_process = (folder) ->
|
||||||
folder.docs.forEach (doc) ->
|
(folder.docs or []).forEach (doc) ->
|
||||||
if doc?.name?.match(/^.*\.bib$/)
|
if doc?.name?.match(/^.*\.bib$/)
|
||||||
ids.push(doc._id)
|
ids.push(doc._id)
|
||||||
folder.folders.forEach (folder) ->
|
(folder.folders or []).forEach (folder) ->
|
||||||
_process(folder)
|
_process(folder)
|
||||||
|
|
||||||
project.rootFolder.forEach (rootFolder) ->
|
(project.rootFolder or []).forEach (rootFolder) ->
|
||||||
_process(rootFolder)
|
_process(rootFolder)
|
||||||
|
|
||||||
return ids
|
return ids
|
||||||
|
|
Loading…
Reference in a new issue