pr_27230.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. diff --git a/services/web/app.mjs b/services/web/app.mjs
  2. index b7c723da3d77..3f54cc36a8c3 100644
  3. --- a/services/web/app.mjs
  4. +++ b/services/web/app.mjs
  5. @@ -56,14 +56,8 @@ if (Settings.catchErrors) {
  6. // Create ./data/dumpFolder if needed
  7. FileWriter.ensureDumpFolderExists()
  8. -if (
  9. - !Features.hasFeature('project-history-blobs') &&
  10. - !Features.hasFeature('filestore')
  11. -) {
  12. - throw new Error(
  13. - 'invalid config: must enable either project-history-blobs (Settings.enableProjectHistoryBlobs=true) or enable filestore (Settings.disableFilestore=false)'
  14. - )
  15. -}
  16. +// Validate combination of feature flags.
  17. +Features.validateSettings()
  18. // handle SIGTERM for graceful shutdown in kubernetes
  19. process.on('SIGTERM', function (signal) {
  20. diff --git a/services/web/app/src/Features/History/HistoryURLHelper.js b/services/web/app/src/Features/History/HistoryURLHelper.js
  21. index 8b8d8cbdd730..acb43ced68e0 100644
  22. --- a/services/web/app/src/Features/History/HistoryURLHelper.js
  23. +++ b/services/web/app/src/Features/History/HistoryURLHelper.js
  24. @@ -8,7 +8,7 @@ function projectHistoryURLWithFilestoreFallback(
  25. ) {
  26. const filestoreURL = `${Settings.apis.filestore.url}/project/${projectId}/file/${fileRef._id}?from=${origin}`
  27. // TODO: When this file is converted to ES modules we will be able to use Features.hasFeature('project-history-blobs'). Currently we can't stub the feature return value in tests.
  28. - if (fileRef.hash && Settings.enableProjectHistoryBlobs) {
  29. + if (fileRef.hash && Settings.filestoreMigrationLevel >= 1) {
  30. return {
  31. url: `${Settings.apis.project_history.url}/project/${historyId}/blob/${fileRef.hash}`,
  32. fallbackURL: filestoreURL,
  33. diff --git a/services/web/app/src/infrastructure/Features.js b/services/web/app/src/infrastructure/Features.js
  34. index aaf51103b9b8..89c8e6b841d0 100644
  35. --- a/services/web/app/src/infrastructure/Features.js
  36. +++ b/services/web/app/src/infrastructure/Features.js
  37. @@ -19,8 +19,7 @@ const trackChangesModuleAvailable =
  38. * @property {boolean | undefined} enableGithubSync
  39. * @property {boolean | undefined} enableGitBridge
  40. * @property {boolean | undefined} enableHomepage
  41. - * @property {boolean | undefined} enableProjectHistoryBlobs
  42. - * @property {boolean | undefined} disableFilestore
  43. + * @property {number} filestoreMigrationLevel
  44. * @property {boolean | undefined} enableSaml
  45. * @property {boolean | undefined} ldap
  46. * @property {boolean | undefined} oauth
  47. @@ -29,7 +28,39 @@ const trackChangesModuleAvailable =
  48. * @property {boolean | undefined} saml
  49. */
  50. +/**
  51. + * @return {{'project-history-blobs': boolean, filestore: boolean}}
  52. + */
  53. +function getFilestoreMigrationOptions() {
  54. + switch (Settings.filestoreMigrationLevel) {
  55. + case 0:
  56. + return {
  57. + 'project-history-blobs': false,
  58. + filestore: true,
  59. + }
  60. + case 1:
  61. + return {
  62. + 'project-history-blobs': true,
  63. + filestore: true,
  64. + }
  65. +
  66. + case 2:
  67. + return {
  68. + 'project-history-blobs': true,
  69. + filestore: false,
  70. + }
  71. + default:
  72. + throw new Error(
  73. + `invalid OVERLEAF_FILESTORE_MIGRATION_LEVEL=${Settings.filestoreMigrationLevel}, expected 0, 1 or 2`
  74. + )
  75. + }
  76. +}
  77. +
  78. const Features = {
  79. + validateSettings() {
  80. + getFilestoreMigrationOptions() // throws for invalid settings
  81. + },
  82. +
  83. /**
  84. * @returns {boolean}
  85. */
  86. @@ -89,9 +120,9 @@ const Features = {
  87. Settings.enabledLinkedFileTypes.includes('url')
  88. )
  89. case 'project-history-blobs':
  90. - return Boolean(Settings.enableProjectHistoryBlobs)
  91. + return getFilestoreMigrationOptions()['project-history-blobs']
  92. case 'filestore':
  93. - return Boolean(Settings.disableFilestore) === false
  94. + return getFilestoreMigrationOptions().filestore
  95. case 'support':
  96. return supportModuleAvailable
  97. case 'symbol-palette':
  98. diff --git a/services/web/config/settings.defaults.js b/services/web/config/settings.defaults.js
  99. index bd0730d5d00c..4df63ebd7c6c 100644
  100. --- a/services/web/config/settings.defaults.js
  101. +++ b/services/web/config/settings.defaults.js
  102. @@ -440,6 +440,9 @@ module.exports = {
  103. ','
  104. ),
  105. + filestoreMigrationLevel:
  106. + parseInt(process.env.OVERLEAF_FILESTORE_MIGRATION_LEVEL, 10) || 0,
  107. +
  108. // i18n
  109. // ------
  110. //
  111. diff --git a/services/history-v1/storage/scripts/back_fill_file_hash.mjs b/services/history-v1/storage/scripts/back_fill_file_hash.mjs
  112. index 0ccadaf5a955..2e12328e5c49 100644
  113. --- a/services/history-v1/storage/scripts/back_fill_file_hash.mjs
  114. +++ b/services/history-v1/storage/scripts/back_fill_file_hash.mjs
  115. @@ -150,10 +150,6 @@ const CONCURRENT_BATCHES = parseInt(process.env.CONCURRENT_BATCHES || '2', 10)
  116. const RETRIES = parseInt(process.env.RETRIES || '10', 10)
  117. const RETRY_DELAY_MS = parseInt(process.env.RETRY_DELAY_MS || '100', 10)
  118. -const USER_FILES_BUCKET_NAME = process.env.USER_FILES_BUCKET_NAME || ''
  119. -if (!USER_FILES_BUCKET_NAME) {
  120. - throw new Error('env var USER_FILES_BUCKET_NAME is missing')
  121. -}
  122. const RETRY_FILESTORE_404 = process.env.RETRY_FILESTORE_404 === 'true'
  123. const BUFFER_DIR = fs.mkdtempSync(
  124. process.env.BUFFER_DIR_PREFIX || '/tmp/back_fill_file_hash-'
  125. diff --git a/services/web/app/src/infrastructure/Features.js b/services/web/app/src/infrastructure/Features.js
  126. index 89c8e6b841d0..6147e70e0faf 100644
  127. --- a/services/web/app/src/infrastructure/Features.js
  128. +++ b/services/web/app/src/infrastructure/Features.js
  129. @@ -28,37 +28,13 @@ const trackChangesModuleAvailable =
  130. * @property {boolean | undefined} saml
  131. */
  132. -/**
  133. - * @return {{'project-history-blobs': boolean, filestore: boolean}}
  134. - */
  135. -function getFilestoreMigrationOptions() {
  136. - switch (Settings.filestoreMigrationLevel) {
  137. - case 0:
  138. - return {
  139. - 'project-history-blobs': false,
  140. - filestore: true,
  141. - }
  142. - case 1:
  143. - return {
  144. - 'project-history-blobs': true,
  145. - filestore: true,
  146. - }
  147. -
  148. - case 2:
  149. - return {
  150. - 'project-history-blobs': true,
  151. - filestore: false,
  152. - }
  153. - default:
  154. +const Features = {
  155. + validateSettings() {
  156. + if (![0, 1, 2].includes(Settings.filestoreMigrationLevel)) {
  157. throw new Error(
  158. `invalid OVERLEAF_FILESTORE_MIGRATION_LEVEL=${Settings.filestoreMigrationLevel}, expected 0, 1 or 2`
  159. )
  160. - }
  161. -}
  162. -
  163. -const Features = {
  164. - validateSettings() {
  165. - getFilestoreMigrationOptions() // throws for invalid settings
  166. + }
  167. },
  168. /**
  169. @@ -120,9 +96,9 @@ const Features = {
  170. Settings.enabledLinkedFileTypes.includes('url')
  171. )
  172. case 'project-history-blobs':
  173. - return getFilestoreMigrationOptions()['project-history-blobs']
  174. + return Settings.filestoreMigrationLevel > 0
  175. case 'filestore':
  176. - return getFilestoreMigrationOptions().filestore
  177. + return Settings.filestoreMigrationLevel < 2
  178. case 'support':
  179. return supportModuleAvailable
  180. case 'symbol-palette':