file-list.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const topFileTypes = ['bbl', 'gls', 'ind']
  2. // NOTE: Updating this list requires a corresponding change in
  3. // * services/clsi/app/js/OutputFileArchiveManager.js
  4. const ignoreFiles = ['output.fls', 'output.fdb_latexmk']
  5. export const buildFileList = (
  6. outputFiles,
  7. clsiServerId,
  8. compileGroup,
  9. outputFilesArchive
  10. ) => {
  11. const files = { top: [], other: [] }
  12. if (outputFiles) {
  13. const params = new URLSearchParams()
  14. if (clsiServerId) {
  15. params.set('clsiserverid', clsiServerId)
  16. }
  17. if (compileGroup) {
  18. params.set('compileGroup', compileGroup)
  19. }
  20. const queryString = params.toString()
  21. const allFiles = []
  22. // filter out ignored files and set some properties
  23. for (const file of outputFiles.values()) {
  24. if (!ignoreFiles.includes(file.path)) {
  25. file.main = file.path.startsWith('output.')
  26. if (queryString.length) {
  27. file.url += `?${queryString}`
  28. }
  29. allFiles.push(file)
  30. }
  31. }
  32. // sort main files first, then alphabetical
  33. allFiles.sort((a, b) => {
  34. if (a.main && !b.main) {
  35. return -1
  36. }
  37. if (b.main && !a.main) {
  38. return 1
  39. }
  40. return a.path.localeCompare(b.path, undefined, { numeric: true })
  41. })
  42. // group files into "top" and "other"
  43. for (const file of allFiles) {
  44. if (topFileTypes.includes(file.type)) {
  45. files.top.push(file)
  46. } else if (!(file.type === 'pdf' && file.main === true)) {
  47. files.other.push(file)
  48. }
  49. }
  50. const archivableFiles = [...files.top, ...files.other]
  51. if (outputFilesArchive && archivableFiles.length > 0) {
  52. archivableFiles.forEach(file => params.append('files', file.path))
  53. files.archive = {
  54. ...outputFilesArchive,
  55. fileCount: archivableFiles.length,
  56. url: `${outputFilesArchive.url}?${params.toString()}`,
  57. }
  58. }
  59. }
  60. return files
  61. }