mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Returning error when archive failed.
This commit is contained in:
parent
40f493ee68
commit
aa1e2f266e
1 changed files with 18 additions and 14 deletions
|
|
@ -108,22 +108,26 @@ def prepare_bytes(b: bytes) -> str:
|
|||
@app.post('/json')
|
||||
async def post_archive(request: Request):
|
||||
url = request.json['url']
|
||||
singlefile, screenshot = await asyncio.gather(call_single_file(url), take_screenshot(url))
|
||||
with tempfile.NamedTemporaryFile('wb') as fh:
|
||||
fh.write(singlefile)
|
||||
readability = await extract_readability(fh.name, url)
|
||||
try:
|
||||
singlefile, screenshot = await asyncio.gather(call_single_file(url), take_screenshot(url))
|
||||
with tempfile.NamedTemporaryFile('wb') as fh:
|
||||
fh.write(singlefile)
|
||||
readability = await extract_readability(fh.name, url)
|
||||
|
||||
# Compress for smaller response.
|
||||
singlefile = prepare_bytes(singlefile)
|
||||
screenshot = prepare_bytes(screenshot)
|
||||
# Compress for smaller response.
|
||||
singlefile = prepare_bytes(singlefile)
|
||||
screenshot = prepare_bytes(screenshot)
|
||||
|
||||
ret = dict(
|
||||
url=url,
|
||||
singlefile=singlefile,
|
||||
readability=readability,
|
||||
screenshot=screenshot,
|
||||
)
|
||||
return response.json(ret)
|
||||
ret = dict(
|
||||
url=url,
|
||||
singlefile=singlefile,
|
||||
readability=readability,
|
||||
screenshot=screenshot,
|
||||
)
|
||||
return response.json(ret)
|
||||
except Exception:
|
||||
logger.fatal(f'Failed to archive {url}', exc_info=True)
|
||||
return response.json({'error': f'Failed to archive {url}'})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue