|
|
@@ -7,9 +7,6 @@ from preview_generator.exception import UnavailablePreviewType
|
|
7
|
7
|
from pyramid.config import Configurator
|
|
8
|
8
|
from pyramid.response import FileResponse, FileIter
|
|
9
|
9
|
|
|
10
|
|
-from tracim.exceptions import EmptyLabelNotAllowed
|
|
11
|
|
-from tracim.models.data import UserRoleInWorkspace
|
|
12
|
|
-
|
|
13
|
10
|
try: # Python 3.5+
|
|
14
|
11
|
from http import HTTPStatus
|
|
15
|
12
|
except ImportError:
|
|
|
@@ -20,6 +17,7 @@ from tracim.extensions import hapic
|
|
20
|
17
|
from tracim.lib.core.content import ContentApi
|
|
21
|
18
|
from tracim.views.controllers import Controller
|
|
22
|
19
|
from tracim.views.core_api.schemas import FileContentSchema
|
|
|
20
|
+from tracim.views.core_api.schemas import AllowedJpgPreviewDimSchema
|
|
23
|
21
|
from tracim.views.core_api.schemas import ContentPreviewSizedPathSchema
|
|
24
|
22
|
from tracim.views.core_api.schemas import RevisionPreviewSizedPathSchema
|
|
25
|
23
|
from tracim.views.core_api.schemas import PageQuerySchema
|
|
|
@@ -31,11 +29,14 @@ from tracim.views.core_api.schemas import WorkspaceAndContentIdPathSchema
|
|
31
|
29
|
from tracim.views.core_api.schemas import NoContentSchema
|
|
32
|
30
|
from tracim.lib.utils.authorization import require_content_types
|
|
33
|
31
|
from tracim.lib.utils.authorization import require_workspace_role
|
|
|
32
|
+from tracim.models.data import UserRoleInWorkspace
|
|
34
|
33
|
from tracim.models.context_models import ContentInContext
|
|
35
|
34
|
from tracim.models.context_models import RevisionInContext
|
|
36
|
35
|
from tracim.models.contents import ContentTypeLegacy as ContentType
|
|
37
|
36
|
from tracim.models.contents import file_type
|
|
38
|
37
|
from tracim.models.revision_protection import new_revision
|
|
|
38
|
+from tracim.exceptions import EmptyLabelNotAllowed
|
|
|
39
|
+from tracim.exceptions import PreviewDimNotAllowed
|
|
39
|
40
|
|
|
40
|
41
|
FILE_ENDPOINTS_TAG = 'Files'
|
|
41
|
42
|
|
|
|
@@ -217,16 +218,20 @@ class FileController(Controller):
|
|
217
|
218
|
hapic_data.path.content_id,
|
|
218
|
219
|
content_type=ContentType.Any
|
|
219
|
220
|
)
|
|
|
221
|
+ allowed_dim = api.get_jpg_preview_allowed_dim()
|
|
220
|
222
|
jpg_preview_path = api.get_jpg_preview_path(
|
|
221
|
223
|
content_id=content.content_id,
|
|
222
|
224
|
revision_id=content.revision_id,
|
|
223
|
|
- page=hapic_data.query.page
|
|
|
225
|
+ page=hapic_data.query.page,
|
|
|
226
|
+ width=allowed_dim.dimensions[0].width,
|
|
|
227
|
+ height=allowed_dim.dimensions[0].height,
|
|
224
|
228
|
)
|
|
225
|
229
|
return FileResponse(jpg_preview_path)
|
|
226
|
230
|
|
|
227
|
231
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
228
|
232
|
@require_workspace_role(UserRoleInWorkspace.READER)
|
|
229
|
233
|
@require_content_types([file_type])
|
|
|
234
|
+ @hapic.handle_exception(PreviewDimNotAllowed, HTTPStatus.BAD_REQUEST)
|
|
230
|
235
|
@hapic.input_query(PageQuerySchema())
|
|
231
|
236
|
@hapic.input_path(ContentPreviewSizedPathSchema())
|
|
232
|
237
|
@hapic.output_file([])
|
|
|
@@ -253,6 +258,7 @@ class FileController(Controller):
|
|
253
|
258
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
254
|
259
|
@require_workspace_role(UserRoleInWorkspace.READER)
|
|
255
|
260
|
@require_content_types([file_type])
|
|
|
261
|
+ @hapic.handle_exception(PreviewDimNotAllowed, HTTPStatus.BAD_REQUEST)
|
|
256
|
262
|
@hapic.input_path(RevisionPreviewSizedPathSchema())
|
|
257
|
263
|
@hapic.input_query(PageQuerySchema())
|
|
258
|
264
|
@hapic.output_file([])
|
|
|
@@ -283,9 +289,16 @@ class FileController(Controller):
|
|
283
|
289
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
284
|
290
|
@require_workspace_role(UserRoleInWorkspace.READER)
|
|
285
|
291
|
@require_content_types([file_type])
|
|
286
|
|
- @hapic.output_file([])
|
|
|
292
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
|
293
|
+ @hapic.output_body(AllowedJpgPreviewDimSchema())
|
|
287
|
294
|
def allowed_dim_preview_jpg(self, context, request: TracimRequest, hapic_data=None):
|
|
288
|
|
- raise NotImplemented()
|
|
|
295
|
+ app_config = request.registry.settings['CFG']
|
|
|
296
|
+ api = ContentApi(
|
|
|
297
|
+ current_user=request.current_user,
|
|
|
298
|
+ session=request.dbsession,
|
|
|
299
|
+ config=app_config,
|
|
|
300
|
+ )
|
|
|
301
|
+ return api.get_jpg_preview_allowed_dim()
|
|
289
|
302
|
|
|
290
|
303
|
# File infos
|
|
291
|
304
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|