Explorar o código

Merge pull request #22219 from overleaf/jpa-handle-missing-hash

[web] gracefully handle missing hash when compiling

GitOrigin-RevId: a9b121716319117ead84b7fed9a67098f63fd9a7
Brian Gough hai 1 ano
pai
achega
bb1072a3a4

+ 11 - 3
services/web/app/src/Features/Compile/ClsiManager.js

@@ -740,11 +740,19 @@ function _finaliseRequest(projectId, options, project, docs, files) {
   for (let path in files) {
   for (let path in files) {
     const file = files[path]
     const file = files[path]
     path = path.replace(/^\//, '') // Remove leading /
     path = path.replace(/^\//, '') // Remove leading /
-    const { bucket, key } = getBlobLocation(historyId, file.hash)
+
+    const filestoreURL = `${Settings.apis.filestore.url}/project/${project._id}/file/${file._id}`
+    let url = filestoreURL
+    let fallbackURL
+    if (file.hash) {
+      const { bucket, key } = getBlobLocation(historyId, file.hash)
+      url = `${Settings.apis.filestore.url}/bucket/${bucket}/key/${key}`
+      fallbackURL = filestoreURL
+    }
     resources.push({
     resources.push({
       path,
       path,
-      url: `${Settings.apis.filestore.url}/bucket/${bucket}/key/${key}`,
-      fallbackURL: `${Settings.apis.filestore.url}/project/${project._id}/file/${file._id}`,
+      url,
+      fallbackURL,
       modified: file.created?.getTime(),
       modified: file.created?.getTime(),
     })
     })
   }
   }

+ 12 - 3
services/web/test/unit/src/Compile/ClsiManagerTests.js

@@ -46,6 +46,11 @@ describe('ClsiManager', function () {
         created: new Date(),
         created: new Date(),
         hash: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
         hash: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
       },
       },
+      '/images/no-hash.png': {
+        name: 'no-hash.png',
+        _id: 'mock-file-id-3',
+        created: new Date(),
+      },
     }
     }
     this.clsiCookieKey = 'clsiserver'
     this.clsiCookieKey = 'clsiserver'
     this.clsiServerId = 'clsi-server-id'
     this.clsiServerId = 'clsi-server-id'
@@ -1027,16 +1032,20 @@ function _makeResources(project, docs, files) {
     })
     })
   }
   }
   for (const [path, file] of Object.entries(files)) {
   for (const [path, file] of Object.entries(files)) {
-    let url
+    let url, fallbackURL
     if (file.hash === GLOBAL_BLOB_HASH) {
     if (file.hash === GLOBAL_BLOB_HASH) {
       url = `${FILESTORE_URL}/bucket/global-blobs/key/aa/aa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`
       url = `${FILESTORE_URL}/bucket/global-blobs/key/aa/aa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`
-    } else {
+      fallbackURL = `${FILESTORE_URL}/project/${project._id}/file/${file._id}`
+    } else if (file.hash) {
       url = `${FILESTORE_URL}/bucket/project-blobs/key/${project.overleaf.history.id}/${file.hash}`
       url = `${FILESTORE_URL}/bucket/project-blobs/key/${project.overleaf.history.id}/${file.hash}`
+      fallbackURL = `${FILESTORE_URL}/project/${project._id}/file/${file._id}`
+    } else {
+      url = `${FILESTORE_URL}/project/${project._id}/file/${file._id}`
     }
     }
     resources.push({
     resources.push({
       path: path.replace(/^\//, ''),
       path: path.replace(/^\//, ''),
       url,
       url,
-      fallbackURL: `${FILESTORE_URL}/project/${project._id}/file/${file._id}`,
+      fallbackURL,
       modified: file.created.getTime(),
       modified: file.created.getTime(),
     })
     })
   }
   }