Bladeren bron

Merge pull request #298 from tracim/fix/249/preview_generator_stabilization

algooapy 7 jaren geleden
bovenliggende
commit
9f2116e854

+ 1 - 1
tracim/setup.py Bestand weergeven

@@ -91,7 +91,7 @@ setup(
91 91
         ]
92 92
     },
93 93
     dependency_links=[
94
-        "http://tg.gy/230",
94
+        'http://github.com/algoo/preview-generator/tarball/master#egg=preview_generator-1.0',
95 95
         ],
96 96
     zip_safe=False
97 97
 )

+ 22 - 2
tracim/tracim/controllers/content.py Bestand weergeven

@@ -8,6 +8,7 @@ import traceback
8 8
 
9 9
 from cgi import FieldStorage
10 10
 from depot.manager import DepotManager
11
+from preview_generator.exception import PreviewGeneratorException
11 12
 from preview_generator.manager import PreviewManager
12 13
 from sqlalchemy.orm.exc import NoResultFound
13 14
 import tg
@@ -17,6 +18,7 @@ from tg import require
17 18
 from tg import predicates
18 19
 from tg.i18n import ugettext as _
19 20
 from tg.predicates import not_anonymous
21
+from typing import List
20 22
 
21 23
 from tracim.controllers import TIMRestController
22 24
 from tracim.controllers import StandardController
@@ -216,7 +218,14 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
216 218
             revision_id = file.revision_id
217 219
 
218 220
         file_path = content_api.get_one_revision_filepath(revision_id)
219
-        nb_page = preview_manager.get_nb_page(file_path=file_path)
221
+
222
+        nb_page = 0
223
+        try:
224
+            nb_page = preview_manager.get_page_nb(file_path=file_path)
225
+        except PreviewGeneratorException as e:
226
+            # INFO - A.P - Silently intercepts preview exception
227
+            # As preview generation isn't mandatory, just register it
228
+            logger.debug(self, 'Exception: {}'.format(e.__str__))
220 229
         preview_urls = []
221 230
         for page in range(int(nb_page)):
222 231
             url_str = '/previews/{}/pages/{}?revision_id={}'
@@ -225,6 +234,16 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
225 234
                                  revision_id)
226 235
             preview_urls.append(url)
227 236
 
237
+        enable_pdf_buttons = False  # type: bool
238
+        try:
239
+            enable_pdf_buttons = \
240
+                preview_manager.has_pdf_preview(file_path=file_path)
241
+        except PreviewGeneratorException as e:
242
+            # INFO - A.P - Silently intercepts preview exception
243
+            # As preview generation isn't mandatory, just register it
244
+            logger.debug(self, 'Exception: {}'.format(e.__str__))
245
+        pdf_available = 'true' if enable_pdf_buttons else 'false'  # type: str
246
+
228 247
         fake_api_breadcrumb = self.get_breadcrumb(file_id)
229 248
         fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
230 249
                                          current_user=current_user_content)
@@ -235,7 +254,8 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
235 254
         result = DictLikeClass(result=dictified_file,
236 255
                                fake_api=fake_api,
237 256
                                nb_page=nb_page,
238
-                               url=preview_urls)
257
+                               url=preview_urls,
258
+                               pdf_available=pdf_available)
239 259
         return result
240 260
 
241 261
     @tg.require(current_user_is_reader())

+ 11 - 6
tracim/tracim/controllers/page.py Bestand weergeven

@@ -1,6 +1,7 @@
1 1
 import tg
2 2
 from tg import expose
3 3
 from tg import tmpl_context
4
+from preview_generator.exception import PreviewGeneratorException
4 5
 from preview_generator.manager import PreviewManager
5 6
 
6 7
 from tracim.config.app_cfg import CFG
@@ -43,12 +44,16 @@ class PagesController(TIMRestController):
43 44
         else:
44 45
             file = content_api.get_one(file_id, self._item_type)
45 46
             file_path = content_api.get_one_revision_filepath(file.revision_id)
46
-        path = preview_manager.get_jpeg_preview(file_path=file_path,
47
-                                                page=page,
48
-                                                height=size,
49
-                                                width=size)
50
-        with open(path, 'rb') as large:
51
-            return large.read()
47
+        try:
48
+            path = preview_manager.get_jpeg_preview(file_path=file_path,
49
+                                                    page=page,
50
+                                                    height=size,
51
+                                                    width=size)
52
+            with open(path, 'rb') as large:
53
+                result = large.read()
54
+        except PreviewGeneratorException:
55
+            result = None
56
+        return result
52 57
 
53 58
     @expose(content_type='image/jpeg')
54 59
     def high_quality(self,

+ 1 - 1
tracim/tracim/templates/file/getone.mak Bestand weergeven

@@ -127,7 +127,7 @@
127 127
                     modifiedAt: '${h.format_short(created_localized)|n}',
128 128
                     owner: '${result.file.owner.name}',
129 129
                     sourceLink: '${download_url}',
130
-                    pdfAvailable: false // FIXME - Côme - 2017/07/24 - backend should return this information
130
+                    pdfAvailable: ${pdf_available}
131 131
                   }
132 132
                 )
133 133
               })()