소스 검색

WIP preview_info

Guénaël Muller 6 년 전
부모
커밋
f345b7b4f4
2개의 변경된 파일40개의 추가작업 그리고 12개의 파일을 삭제
  1. 1 0
      setup.py
  2. 39 12
      tracim/views/contents_api/file_controller.py

+ 1 - 0
setup.py 파일 보기

35
     'filedepot',
35
     'filedepot',
36
     'babel',
36
     'babel',
37
     'python-slugify',
37
     'python-slugify',
38
+    'preview-generator',
38
     # mail-notifier
39
     # mail-notifier
39
     'mako',
40
     'mako',
40
     'lxml',
41
     'lxml',

+ 39 - 12
tracim/views/contents_api/file_controller.py 파일 보기

32
 from tracim.models.contents import ContentTypeLegacy as ContentType
32
 from tracim.models.contents import ContentTypeLegacy as ContentType
33
 from tracim.models.contents import file_type
33
 from tracim.models.contents import file_type
34
 from tracim.models.revision_protection import new_revision
34
 from tracim.models.revision_protection import new_revision
35
+from preview_generator.manager import PreviewManager
35
 
36
 
36
 FILE_ENDPOINTS_TAG = 'Files'
37
 FILE_ENDPOINTS_TAG = 'Files'
37
 
38
 
44
     @require_content_types([file_type])
45
     @require_content_types([file_type])
45
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
46
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
46
     #@hapic.input_files()
47
     #@hapic.input_files()
47
-    @hapic.output_file([])
48
+    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
48
     def upload_file(self, context, request: TracimRequest, hapic_data=None):
49
     def upload_file(self, context, request: TracimRequest, hapic_data=None):
49
         # TODO - G.M - 2018-07-05 - Do this endpoint
50
         # TODO - G.M - 2018-07-05 - Do this endpoint
50
         app_config = request.registry.settings['CFG']
51
         app_config = request.registry.settings['CFG']
69
                 new_mimetype=file.type,
70
                 new_mimetype=file.type,
70
                 new_content=file.file,
71
                 new_content=file.file,
71
             )
72
             )
72
-        file = DepotManager.get().get(content.depot_file)
73
-        response = request.response
74
-        response.content_type = file.content_type
75
-        response.app_iter = FileIter(file)
76
-        return response
73
+
74
+        return
77
 
75
 
78
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
76
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
79
-    @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
77
+    @require_workspace_role(UserRoleInWorkspace.READER)
80
     @require_content_types([file_type])
78
     @require_content_types([file_type])
81
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
79
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
82
     @hapic.output_file([])
80
     @hapic.output_file([])
100
 
98
 
101
 
99
 
102
     # Previews
100
     # Previews
103
-    # def get_file_preview(self):
104
-    #     # TODO - G.M - 2018-07-05 - Do this endpoint
105
-    #     pass
106
-    
101
+    @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
102
+    @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
103
+    @require_content_types([file_type])
104
+    @hapic.input_path(WorkspaceAndContentIdPathSchema())
105
+    #@hapic.output_file([])
106
+    def get_file_preview_info(self, context, request: TracimRequest, hapic_data=None):  # nopep8
107
+        # TODO - G.M - 2018-07-05 - Do this endpoint
108
+        app_config = request.registry.settings['CFG']
109
+        preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True)  # nopep8
110
+        api = ContentApi(
111
+            current_user=request.current_user,
112
+            session=request.dbsession,
113
+            config=app_config,
114
+        )
115
+        content = api.get_one(
116
+            hapic_data.path.content_id,
117
+            content_type=ContentType.Any
118
+        )
119
+        file_path = api.get_one_revision_filepath(content.revision_id)
120
+        return {
121
+            'nb_pages': preview_manager.get_page_nb(file_path),
122
+            'pdf_preview': preview_manager.has_pdf_preview(file_path),
123
+            'mimetype':  preview_manager.get_mimetype(file_path),
124
+        }
125
+
107
     # File infos
126
     # File infos
108
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
127
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
109
     @require_workspace_role(UserRoleInWorkspace.READER)
128
     @require_workspace_role(UserRoleInWorkspace.READER)
264
         )
283
         )
265
         configurator.add_view(self.get_file_revisions, route_name='file_revisions')  # nopep8
284
         configurator.add_view(self.get_file_revisions, route_name='file_revisions')  # nopep8
266
 
285
 
267
-        # get file revisions
286
+        # get file status
268
         configurator.add_route(
287
         configurator.add_route(
269
             'set_file_status',
288
             'set_file_status',
270
             '/workspaces/{workspace_id}/files/{content_id}/status',  # nopep8
289
             '/workspaces/{workspace_id}/files/{content_id}/status',  # nopep8
271
             request_method='PUT'
290
             request_method='PUT'
272
         )
291
         )
273
         configurator.add_view(self.set_file_status, route_name='set_file_status')  # nopep8
292
         configurator.add_view(self.set_file_status, route_name='set_file_status')  # nopep8
293
+
294
+        # get preview info
295
+        configurator.add_route(
296
+            'preview_info',
297
+            '/workspaces/{workspace_id}/files/{content_id}/preview/info',  # nopep8
298
+            request_method='GET'
299
+        )
300
+        configurator.add_view(self.get_file_preview_info, route_name='preview_info')  # nopep8