wrolpi/modules/otp/api.py
Roland 02f8584762
Squashed commit of the following:
commit 1663e1be9e
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 19:37:25 2021 -0700

    Setting downloader to video when a channel schedules it's videos for download.

commit a6811f9e87
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 19:33:27 2021 -0700

    Setting channel downloader when spreading channel downloads.

commit b63c8f132a
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 19:28:53 2021 -0700

    Fixing DownloadManager.kill

commit 120ce7cd2c
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 19:10:12 2021 -0700

    Fixing OTP api urls.

commit d3b985241b
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 19:07:48 2021 -0700

    Channel Cancel button does not submit form.

commit 9d1a0ecd55
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 19:00:53 2021 -0700

    A Channel without an existing Download cannot be downloaded.

commit e7c920f382
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 18:41:02 2021 -0700

    Fixing typing.

commit d56c8fde24
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 18:36:02 2021 -0700

    Testing bad downloader param.

commit e3c57ef674
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 18:31:35 2021 -0700

    Adding __json__ to Downloader for sending them to the FE.  Hiding ChannelDownloader because it will be handled specifically.

commit 047b507119
Author: Roland <roland@learningselfreliance.com>
Date:   Thu Dec 30 18:20:37 2021 -0700

    Downloader can be specified by the user.

commit 4a169ba43c
Author: Roland <roland@learningselfreliance.com>
Date:   Tue Dec 28 18:37:30 2021 -0700

    Download info a set in create_downloads.

commit 8778d53fa1
Author: Roland <roland@learningselfreliance.com>
Date:   Tue Dec 28 18:21:43 2021 -0700

    Fixing Download.info_json name.

commit b28bacfd5b
Author: Roland <roland@learningselfreliance.com>
Date:   Tue Dec 28 18:17:53 2021 -0700

    Downloader names are in the class, not in the init.

commit f5ce952da0
Author: Roland <roland@learningselfreliance.com>
Date:   Tue Dec 28 18:07:42 2021 -0700

    Download info can be saved during the download process and can be used by the Downloader.
2021-12-30 20:45:11 -07:00

50 lines
1.4 KiB
Python

import random
from http import HTTPStatus
from string import ascii_letters
from sanic import response
from sanic.request import Request
from wrolpi.root_api import get_blueprint
from wrolpi.schema import validate_doc
from .common import generate_html, generate_pdf, encrypt_otp, decrypt_otp
from .schema import EncryptOTPRequest, DecryptOTPRequest
bp = get_blueprint('OTP', '/api/otp')
@bp.post('/encrypt_otp')
@validate_doc(
summary='Encrypt a message with OTP',
consumes=EncryptOTPRequest,
)
async def post_encrypt_otp(_: Request, data: dict):
data = encrypt_otp(data['otp'], data['plaintext'])
return response.json(data)
@bp.post('/decrypt_otp')
@validate_doc(
summary='Decrypt a message with OTP',
consumes=DecryptOTPRequest,
)
async def post_decrypt_otp(_: Request, data: dict):
data = decrypt_otp(data['otp'], data['ciphertext'])
return response.json(data)
@bp.get('/html')
async def get_new_otp(_: Request):
return response.html(generate_html())
@bp.get('/pdf')
async def get_new_otp_pdf(_: Request):
random_name = ''.join(random.choice(ascii_letters) for _ in range(8))
filename = f'one-time-pad-{random_name}.pdf'
headers = {
'Content-type': 'application/pdf',
'Content-Disposition': f'attachment;filename={filename}'
}
contents = generate_pdf()
return response.raw(contents, HTTPStatus.OK, headers)