|
@@ 462-507 (lines=46) @@
|
| 459 |
|
as_attachment=hapic_data.query.force_download |
| 460 |
|
) |
| 461 |
|
|
| 462 |
|
@hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS]) |
| 463 |
|
@require_workspace_role(UserRoleInWorkspace.READER) |
| 464 |
|
@require_content_types([FILE_TYPE]) |
| 465 |
|
@hapic.handle_exception(UnavailablePreview, HTTPStatus.BAD_REQUEST) |
| 466 |
|
@hapic.handle_exception(PageOfPreviewNotFound, HTTPStatus.BAD_REQUEST) |
| 467 |
|
@hapic.handle_exception(PreviewDimNotAllowed, HTTPStatus.BAD_REQUEST) |
| 468 |
|
@hapic.input_path(RevisionPreviewSizedPathSchema()) |
| 469 |
|
@hapic.input_query(PageQuerySchema()) |
| 470 |
|
@hapic.output_file([]) |
| 471 |
|
def sized_preview_jpg_revision(self, context, request: TracimRequest, hapic_data=None): # nopep8 |
| 472 |
|
""" |
| 473 |
|
Obtain resized jpg preview of a specific revision of content. |
| 474 |
|
""" |
| 475 |
|
app_config = request.registry.settings['CFG'] |
| 476 |
|
api = ContentApi( |
| 477 |
|
show_archived=True, |
| 478 |
|
show_deleted=True, |
| 479 |
|
current_user=request.current_user, |
| 480 |
|
session=request.dbsession, |
| 481 |
|
config=app_config, |
| 482 |
|
) |
| 483 |
|
content = api.get_one( |
| 484 |
|
hapic_data.path.content_id, |
| 485 |
|
content_type=CONTENT_TYPES.Any_SLUG |
| 486 |
|
) |
| 487 |
|
revision = api.get_one_revision( |
| 488 |
|
revision_id=hapic_data.path.revision_id, |
| 489 |
|
content=content |
| 490 |
|
) |
| 491 |
|
jpg_preview_path = api.get_jpg_preview_path( |
| 492 |
|
content_id=content.content_id, |
| 493 |
|
revision_id=revision.revision_id, |
| 494 |
|
page_number=hapic_data.query.page, |
| 495 |
|
height=hapic_data.path.height, |
| 496 |
|
width=hapic_data.path.width, |
| 497 |
|
) |
| 498 |
|
filename = "{label}_page_{page_number}_{width}x{height}.jpg".format( |
| 499 |
|
label=revision.label, |
| 500 |
|
page_number=hapic_data.query.page, |
| 501 |
|
width=hapic_data.path.width, |
| 502 |
|
height=hapic_data.path.height |
| 503 |
|
) |
| 504 |
|
return HapicFile( |
| 505 |
|
file_path=jpg_preview_path, |
| 506 |
|
filename=filename, |
| 507 |
|
as_attachment=hapic_data.query.force_download |
| 508 |
|
) |
| 509 |
|
|
| 510 |
|
@hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS]) |
|
@@ 418-459 (lines=42) @@
|
| 415 |
|
as_attachment=hapic_data.query.force_download |
| 416 |
|
) |
| 417 |
|
|
| 418 |
|
@hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS]) |
| 419 |
|
@require_workspace_role(UserRoleInWorkspace.READER) |
| 420 |
|
@require_content_types([FILE_TYPE]) |
| 421 |
|
@hapic.handle_exception(UnavailablePreview, HTTPStatus.BAD_REQUEST) |
| 422 |
|
@hapic.handle_exception(PageOfPreviewNotFound, HTTPStatus.BAD_REQUEST) |
| 423 |
|
@hapic.handle_exception(PreviewDimNotAllowed, HTTPStatus.BAD_REQUEST) |
| 424 |
|
@hapic.input_query(PageQuerySchema()) |
| 425 |
|
@hapic.input_path(ContentPreviewSizedPathSchema()) |
| 426 |
|
@hapic.output_file([]) |
| 427 |
|
def sized_preview_jpg(self, context, request: TracimRequest, hapic_data=None): # nopep8 |
| 428 |
|
""" |
| 429 |
|
Obtain resized jpg preview of last revision of content. |
| 430 |
|
""" |
| 431 |
|
app_config = request.registry.settings['CFG'] |
| 432 |
|
api = ContentApi( |
| 433 |
|
show_archived=True, |
| 434 |
|
show_deleted=True, |
| 435 |
|
current_user=request.current_user, |
| 436 |
|
session=request.dbsession, |
| 437 |
|
config=app_config, |
| 438 |
|
) |
| 439 |
|
content = api.get_one( |
| 440 |
|
hapic_data.path.content_id, |
| 441 |
|
content_type=CONTENT_TYPES.Any_SLUG |
| 442 |
|
) |
| 443 |
|
jpg_preview_path = api.get_jpg_preview_path( |
| 444 |
|
content_id=content.content_id, |
| 445 |
|
revision_id=content.revision_id, |
| 446 |
|
page_number=hapic_data.query.page, |
| 447 |
|
height=hapic_data.path.height, |
| 448 |
|
width=hapic_data.path.width, |
| 449 |
|
) |
| 450 |
|
filename = "{label}_page_{page_number}_{width}x{height}.jpg".format( |
| 451 |
|
label=content.label, |
| 452 |
|
page_number=hapic_data.query.page, |
| 453 |
|
width=hapic_data.path.width, |
| 454 |
|
height=hapic_data.path.height |
| 455 |
|
) |
| 456 |
|
return HapicFile( |
| 457 |
|
file_path=jpg_preview_path, |
| 458 |
|
filename=filename, |
| 459 |
|
as_attachment=hapic_data.query.force_download |
| 460 |
|
) |
| 461 |
|
|
| 462 |
|
@hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS]) |