|
@@ -32,6 +32,7 @@ from tracim.models.context_models import RevisionInContext
|
32
|
32
|
from tracim.models.contents import ContentTypeLegacy as ContentType
|
33
|
33
|
from tracim.models.contents import file_type
|
34
|
34
|
from tracim.models.revision_protection import new_revision
|
|
35
|
+from preview_generator.manager import PreviewManager
|
35
|
36
|
|
36
|
37
|
FILE_ENDPOINTS_TAG = 'Files'
|
37
|
38
|
|
|
@@ -44,7 +45,7 @@ class FileController(Controller):
|
44
|
45
|
@require_content_types([file_type])
|
45
|
46
|
@hapic.input_path(WorkspaceAndContentIdPathSchema())
|
46
|
47
|
|
47
|
|
- @hapic.output_file([])
|
|
48
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)
|
48
|
49
|
def upload_file(self, context, request: TracimRequest, hapic_data=None):
|
49
|
50
|
|
50
|
51
|
app_config = request.registry.settings['CFG']
|
|
@@ -69,14 +70,11 @@ class FileController(Controller):
|
69
|
70
|
new_mimetype=file.type,
|
70
|
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
|
76
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
79
|
|
- @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
|
|
77
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
80
|
78
|
@require_content_types([file_type])
|
81
|
79
|
@hapic.input_path(WorkspaceAndContentIdPathSchema())
|
82
|
80
|
@hapic.output_file([])
|
|
@@ -100,10 +98,31 @@ class FileController(Controller):
|
100
|
98
|
|
101
|
99
|
|
102
|
100
|
|
103
|
|
-
|
104
|
|
-
|
105
|
|
-
|
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
|
+
|
|
106
|
+ def get_file_preview_info(self, context, request: TracimRequest, hapic_data=None):
|
|
107
|
+
|
|
108
|
+ app_config = request.registry.settings['CFG']
|
|
109
|
+ preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True)
|
|
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
|
126
|
|
108
|
127
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
109
|
128
|
@require_workspace_role(UserRoleInWorkspace.READER)
|
|
@@ -264,10 +283,18 @@ class FileController(Controller):
|
264
|
283
|
)
|
265
|
284
|
configurator.add_view(self.get_file_revisions, route_name='file_revisions')
|
266
|
285
|
|
267
|
|
-
|
|
286
|
+
|
268
|
287
|
configurator.add_route(
|
269
|
288
|
'set_file_status',
|
270
|
289
|
'/workspaces/{workspace_id}/files/{content_id}/status',
|
271
|
290
|
request_method='PUT'
|
272
|
291
|
)
|
273
|
292
|
configurator.add_view(self.set_file_status, route_name='set_file_status')
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+ configurator.add_route(
|
|
296
|
+ 'preview_info',
|
|
297
|
+ '/workspaces/{workspace_id}/files/{content_id}/preview/info',
|
|
298
|
+ request_method='GET'
|
|
299
|
+ )
|
|
300
|
+ configurator.add_view(self.get_file_preview_info, route_name='preview_info')
|