Просмотр исходного кода

Show preview for PDF image (#11793)

GitOrigin-RevId: 5c7dde42cdfcf9952e47487358f7e2b52658cc59
Alf Eaton 3 лет назад
Родитель
Сommit
6175df9f95

+ 10 - 4
services/web/frontend/js/ide/file-tree/FileTreeManager.js

@@ -292,19 +292,25 @@ export default FileTreeManager = class FileTreeManager {
     return this._findEntityByPathInFolder(this.$scope.rootFolder, path)
     return this._findEntityByPathInFolder(this.$scope.rootFolder, path)
   }
   }
 
 
-  getPreviewUrlByPath(path) {
-    for (const extension of [
+  getPreviewByPath(path) {
+    for (const suffix of [
       '',
       '',
       '.png',
       '.png',
       '.jpg',
       '.jpg',
       '.jpeg',
       '.jpeg',
+      '.pdf',
       '.PNG',
       '.PNG',
       '.JPG',
       '.JPG',
       '.JPEG',
       '.JPEG',
+      '.PDF',
     ]) {
     ]) {
-      const entity = this.findEntityByPath(path + extension)
+      const entity = this.findEntityByPath(path + suffix)
+
       if (entity) {
       if (entity) {
-        return `/project/${this.$scope.project._id}/file/${entity.id}`
+        return {
+          url: `/project/${this.$scope.project._id}/file/${entity.id}`,
+          extension: entity.name.split('.').pop(),
+        }
       }
       }
     }
     }
     return null
     return null

+ 1 - 1
services/web/frontend/stories/decorators/scope.tsx

@@ -98,7 +98,7 @@ const initialize = () => {
       findEntityByPath: () => null,
       findEntityByPath: () => null,
       getEntityPath: () => null,
       getEntityPath: () => null,
       getRootDocDirname: () => undefined,
       getRootDocDirname: () => undefined,
-      getPreviewUrlByPath: () => undefined,
+      getPreviewByPath: () => null,
     },
     },
     editorManager: {
     editorManager: {
       getCurrentDocId: () => 'foo',
       getCurrentDocId: () => 'foo',

+ 1 - 1
services/web/test/frontend/helpers/editor-providers.js

@@ -52,7 +52,7 @@ export function EditorProviders({
     findEntityByPath: () => null,
     findEntityByPath: () => null,
     getEntityPath: () => '',
     getEntityPath: () => '',
     getRootDocDirname: () => '',
     getRootDocDirname: () => '',
-    getPreviewUrlByPath: path => path,
+    getPreviewByPath: path => ({ url: path, extension: 'png' }),
   },
   },
   editorManager = {
   editorManager = {
     getCurrentDocId: () => 'foo',
     getCurrentDocId: () => 'foo',