Skip to content

Commit

Permalink
Bug fix on content-length mismatch after VideoJS plugin integration
Browse files Browse the repository at this point in the history
Fix misinformed logging for forbidden list and auth counter
Cleanup databases when proxy server fails to bind to port number
Use organization default runners across all workflows
Use an in-house `pypi-publisher`
  • Loading branch information
dormant-user committed May 21, 2024
1 parent 8df978e commit 277eee3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
coronation:
runs-on: self-hosted
runs-on: thevickypedia-default
permissions:
actions: write
steps:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: none-shall-pass

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
push:
branches:
- main

jobs:
none-shall-pass:
runs-on: self-hosted
runs-on: thevickypedia-default
steps:
- uses: actions/checkout@v4
- uses: thevickypedia/none-shall-pass@v4
- uses: thevickypedia/none-shall-pass@v5
24 changes: 5 additions & 19 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,9 @@ on:
workflow_dispatch:

jobs:
deploy:
runs-on: self-hosted
pypi-publisher:
runs-on: thevickypedia-default
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Create packages
run: python -m build
- name: Run twine check
run: twine check dist/*
- name: Upload to pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.whl
- uses: thevickypedia/pypi-publisher@v3
env:
token: ${{ secrets.PYPI_TOKEN }}
12 changes: 6 additions & 6 deletions pyfilebrowser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ def cleanup(self, log: bool = True) -> None:
self.logger.info("Removed config database %s", download.executable.filebrowser_db)
except FileNotFoundError as warn:
self.logger.warning(warn) if log else None
if self.proxy_engine:
try:
os.remove(proxy_settings.database)
self.logger.info("Removed proxy database %s", proxy_settings.database)
except FileNotFoundError as warn:
self.logger.warning(warn) if log else None
try:
os.remove(proxy_settings.database)
self.logger.info("Removed proxy database %s", proxy_settings.database)
except FileNotFoundError as warn:
self.logger.warning(warn) if self.proxy_engine and log else None

def exit_process(self) -> None:
"""Deletes the database file, and all the subtitles that were created by this application."""
Expand Down Expand Up @@ -183,6 +182,7 @@ def background_tasks(self, auth_map: Dict[str, str]) -> None:
except OSError as error:
self.logger.error(error)
self.logger.critical("Cannot initiate proxy server")
self.cleanup()
raise
log_config = struct.LoggerConfig(self.logger).get()
if proxy_settings.debug:
Expand Down
8 changes: 6 additions & 2 deletions pyfilebrowser/proxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ async def proxy_engine(proxy_request: Request) -> Response:
if proxy_request.url.path == "/api/login":
if server_response.status_code == 403:
await handle_auth_error(proxy_request)
else:
elif (proxy_request.client in settings.session.forbid or
settings.session.auth_counter.get(proxy_request.client.host)):
LOGGER.debug("Removing %s from forbidden list", proxy_request.client.host)
settings.session.forbid.discard(proxy_request.client.host)

Expand All @@ -149,11 +150,14 @@ async def proxy_engine(proxy_request: Request) -> Response:
LOGGER.debug("Removing %s from auth DB", proxy_request.client.host)
database.remove_record(host=proxy_request.client.host)
content_type = server_response.headers.get("content-type", "")
if "text/html" in content_type:
if "text" in content_type:
content = server_response.text
else:
content = server_response.content
server_response.headers.pop("content-encoding", None)
# fixme: there should be a better way to handle this
if "javascript" in content_type: # todo: not sure if this is solely because of VideoJS plugin
server_response.headers.pop("content-length", None)
proxy_response = Response(
content=content,
status_code=server_response.status_code,
Expand Down

0 comments on commit 277eee3

Please sign in to comment.