mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 22:25:59 -05:00
d7357b4d62
Improvements to handling of file/folder upload conflicts GitOrigin-RevId: 526edf30dfbaec7ee1e03ffd156365f09be25e86
42 lines
1 KiB
TypeScript
42 lines
1 KiB
TypeScript
import { findInTree } from '../util/find-in-tree'
|
|
import { Folder } from '../../../../../types/folder'
|
|
import { Doc } from '../../../../../types/doc'
|
|
import { FileRef } from '../../../../../types/file-ref'
|
|
|
|
export function isNameUniqueInFolder(
|
|
tree: Folder,
|
|
parentFolderId: string,
|
|
name: string
|
|
): boolean {
|
|
return !(
|
|
findFileByNameInFolder(tree, parentFolderId, name) ||
|
|
findFolderByNameInFolder(tree, parentFolderId, name)
|
|
)
|
|
}
|
|
|
|
export function findFileByNameInFolder(
|
|
tree: Folder,
|
|
parentFolderId: string,
|
|
name: string
|
|
): Doc | FileRef | undefined {
|
|
if (tree._id !== parentFolderId) {
|
|
tree = findInTree(tree, parentFolderId).entity
|
|
}
|
|
|
|
return (
|
|
tree.docs.find(entity => entity.name === name) ||
|
|
tree.fileRefs.find(entity => entity.name === name)
|
|
)
|
|
}
|
|
|
|
export function findFolderByNameInFolder(
|
|
tree: Folder,
|
|
parentFolderId: string,
|
|
name: string
|
|
): Folder | undefined {
|
|
if (tree._id !== parentFolderId) {
|
|
tree = findInTree(tree, parentFolderId).entity
|
|
}
|
|
|
|
return tree.folders.find(entity => entity.name === name)
|
|
}
|