mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 09:26:17 -05:00
Reverting to older singlefile container to keep archive screenshot ratio. Using FileGroup.url on ArchivePage.
This commit is contained in:
parent
9ea2dadde5
commit
73cb142ae1
11 changed files with 56 additions and 28 deletions
|
|
@ -1,4 +1,5 @@
|
|||
FROM capsulecode/singlefile
|
||||
# Keep older singlefile version so we can keep screenshots at specific ratio.
|
||||
FROM capsulecode/singlefile:v0.3.32
|
||||
|
||||
USER root
|
||||
WORKDIR /app
|
||||
|
|
@ -14,7 +15,7 @@ COPY docker/archive/requirements.txt /app/requirements.txt
|
|||
RUN pip3 install -r /app/requirements.txt
|
||||
COPY docker/archive /app
|
||||
|
||||
# Install Readability too
|
||||
RUN npm install -g 'git+https://github.com/pirate/readability-extractor'
|
||||
# Install a newer singlefile and Readability.
|
||||
RUN npm install -g single-file-cli@1.1.16 'git+https://github.com/pirate/readability-extractor'
|
||||
|
||||
ENTRYPOINT [ "python3", "/app/main.py"]
|
||||
|
|
|
|||
|
|
@ -84,7 +84,10 @@ async def call_single_file(url) -> bytes:
|
|||
logger.debug(f'archive cmd: {cmd}')
|
||||
stdout, stderr, return_code = await check_output(cmd, always_log_stderr=True)
|
||||
if return_code != 0 or not stdout:
|
||||
raise ValueError(f'Failed to single-file {url}')
|
||||
if stderr:
|
||||
for line in stderr.splitlines():
|
||||
logger.error(line)
|
||||
raise RuntimeError(f'Failed to single-file {url} got the following error: {stderr}')
|
||||
logger.debug(f'done archiving for {url}')
|
||||
return stdout
|
||||
|
||||
|
|
@ -103,19 +106,18 @@ async def extract_readability(path: str, url: str) -> dict:
|
|||
output = json.loads(stdout)
|
||||
except JSONDecodeError as e:
|
||||
stderr = stderr.decode() if stderr else None
|
||||
raise ChildProcessError(f'Failed to extract readability. {stderr}') from e
|
||||
raise RuntimeError(f'Failed to extract readability. {stderr}') from e
|
||||
logger.debug(f'done readability for {url}')
|
||||
return output
|
||||
|
||||
|
||||
async def take_screenshot(url: str) -> bytes:
|
||||
logger.info(f'Screenshot: {url}')
|
||||
cmd = '/usr/bin/chromium-browser' \
|
||||
' --headless' \
|
||||
' --disable-gpu' \
|
||||
' --no-sandbox' \
|
||||
' --screenshot' \
|
||||
' --window-size=1280,720' \
|
||||
' --window-size=1280x720' \
|
||||
f' "{url}"'
|
||||
logger.debug(f'Screenshot cmd: {cmd}')
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
|
|
@ -156,6 +158,7 @@ async def post_archive(request: Request):
|
|||
# Use html suffix so chrome screenshot recognizes it as an HTML file.
|
||||
with tempfile.NamedTemporaryFile('wb', suffix='.html') as fh:
|
||||
fh.write(singlefile)
|
||||
fh.flush()
|
||||
readability = None
|
||||
try:
|
||||
readability = await extract_readability(fh.name, url)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue