file-list.js 1.7 KB

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