file-tree-limit.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const FILE_PER_FOLDER = 2
  2. const DOC_PER_FOLDER = 3
  3. const FOLDER_PER_FOLDER = 2
  4. const MAX_DEPTH = 7
  5. function fakeId() {
  6. return Math.random()
  7. .toString(16)
  8. .replace(/0\./, 'random-test-id-')
  9. }
  10. function makeFileRefs(path) {
  11. const fileRefs = []
  12. for (let index = 0; index < FILE_PER_FOLDER; index++) {
  13. fileRefs.push({ _id: fakeId(), name: `${path}-file-${index}.jpg` })
  14. }
  15. return fileRefs
  16. }
  17. function makeDocs(path) {
  18. const docs = []
  19. for (let index = 0; index < DOC_PER_FOLDER; index++) {
  20. docs.push({ _id: fakeId(), name: `${path}-doc-${index}.tex` })
  21. }
  22. return docs
  23. }
  24. function makeFolders(path, depth = 0) {
  25. const folders = []
  26. for (let index = 0; index < FOLDER_PER_FOLDER; index++) {
  27. const folderPath = `${path}-folder-${index}`
  28. folders.push({
  29. _id: fakeId(),
  30. name: folderPath,
  31. folders: depth < MAX_DEPTH ? makeFolders(folderPath, depth + 1) : [],
  32. fileRefs: makeFileRefs(folderPath),
  33. docs: makeDocs(folderPath)
  34. })
  35. }
  36. return folders
  37. }
  38. export const rootFolderLimit = [
  39. {
  40. _id: fakeId(),
  41. name: 'rootFolder',
  42. folders: makeFolders('root'),
  43. fileRefs: makeFileRefs('root'),
  44. docs: makeDocs('root')
  45. }
  46. ]