Merge pull request #8701 from overleaf/bg-simple-iterable-paths

simple iterable paths

GitOrigin-RevId: f6906016888ccfc95c88858bdac4d2633fc1c5f4
This commit is contained in:
Brian Gough
2022-07-04 11:12:01 +01:00
committed by Copybot
parent be71ea690d
commit 5a3318f5b3
7 changed files with 53 additions and 15 deletions
@@ -4,6 +4,7 @@ const Errors = require('../Errors/Errors')
const ProjectGetter = require('./ProjectGetter')
const { promisifyAll } = require('../../util/promises')
const OError = require('@overleaf/o-error')
const { iterablePaths } = require('./IterablePath')
const ProjectEntityHandler = {
getAllDocs(projectId, callback) {
@@ -26,7 +27,7 @@ const ProjectEntityHandler = {
}
const docs = {}
for (const { path: folderPath, folder } of folders) {
for (const doc of folder.docs || []) {
for (const doc of iterablePaths(folder, 'docs')) {
const content = docContents[doc._id.toString()]
if (content != null) {
docs[path.join(folderPath, doc.name)] = {
@@ -51,7 +52,7 @@ const ProjectEntityHandler = {
}
const files = {}
for (const { path: folderPath, folder } of folders) {
for (const file of folder.fileRefs || []) {
for (const file of iterablePaths(folder, 'fileRefs')) {
if (file != null) {
files[path.join(folderPath, file.name)] = file
}
@@ -80,12 +81,12 @@ const ProjectEntityHandler = {
const docs = []
const files = []
for (const { path: folderPath, folder } of folders) {
for (const doc of folder.docs || []) {
for (const doc of iterablePaths(folder, 'docs')) {
if (doc != null) {
docs.push({ path: path.join(folderPath, doc.name), doc })
}
}
for (const file of folder.fileRefs || []) {
for (const file of iterablePaths(folder, 'fileRefs')) {
if (file != null) {
files.push({ path: path.join(folderPath, file.name), file })
}
@@ -111,7 +112,7 @@ const ProjectEntityHandler = {
const folders = ProjectEntityHandler._getAllFoldersFromProject(project)
const docPath = {}
for (const { path: folderPath, folder } of folders) {
for (const doc of folder.docs || []) {
for (const doc of iterablePaths(folder, 'docs')) {
docPath[doc._id] = path.join(folderPath, doc.name)
}
}
@@ -171,7 +172,7 @@ const ProjectEntityHandler = {
return path.join(basePath, docInCurrentFolder.name)
} else {
let docPath, childFolder
for (childFolder of folder.folders || []) {
for (childFolder of iterablePaths(folder, 'folders')) {
docPath = recursivelyFindDocInFolder(
path.join(basePath, childFolder.name),
docId,
@@ -211,7 +212,7 @@ const ProjectEntityHandler = {
const processFolder = (basePath, folder) => {
folders.push({ path: basePath, folder })
if (folder.folders) {
for (const childFolder of folder.folders) {
for (const childFolder of iterablePaths(folder, 'folders')) {
if (childFolder.name != null) {
const childPath = path.join(basePath, childFolder.name)
processFolder(childPath, childFolder)