home
·
contact
·
privacy
projects
/
ytplom
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f10ff07
)
Refactor redirects.
master
author
Christian Heller
<c.heller@plomlompom.de>
Wed, 27 Nov 2024 06:54:10 +0000
(07:54 +0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Wed, 27 Nov 2024 06:54:10 +0000
(07:54 +0100)
src/ytplom/misc.py
patch
|
blob
|
history
diff --git
a/src/ytplom/misc.py
b/src/ytplom/misc.py
index dcb84d860f8281308c45fc84fb8b64ef4c3e1e23..59a9a934983f67107ad582a4a4a4cd6e2cace157 100644
(file)
--- a/
src/ytplom/misc.py
+++ b/
src/ytplom/misc.py
@@
-701,6
+701,9
@@
class TaskHandler(BaseHTTPRequestHandler):
if content:
self.wfile.write(content)
if content:
self.wfile.write(content)
+ def _redirect(self, target: PathStr) -> None:
+ self._send_http(headers=[('Location', target)], code=302)
+
def do_POST(self) -> None: # pylint:disable=invalid-name
"""Map POST requests to handlers for various paths."""
url = urlparse(self.path)
def do_POST(self) -> None: # pylint:disable=invalid-name
"""Map POST requests to handlers for various paths."""
url = urlparse(self.path)
@@
-728,7
+731,7
@@
class TaskHandler(BaseHTTPRequestHandler):
elif 'reload' == command:
self.server.player.reload()
sleep(0.5) # avoid redir happening before current_file update
elif 'reload' == command:
self.server.player.reload()
sleep(0.5) # avoid redir happening before current_file update
- self._
send_http(headers=[('Location', '/')], code=302
)
+ self._
redirect(PathStr('/')
)
def _receive_video_flag(self,
rel_path_b64: B64Str,
def _receive_video_flag(self,
rel_path_b64: B64Str,
@@
-743,9
+746,7
@@
class TaskHandler(BaseHTTPRequestHandler):
file.save(conn)
conn.commit_close()
file.ensure_absence_if_deleted()
file.save(conn)
conn.commit_close()
file.ensure_absence_if_deleted()
- self._send_http(headers=[('Location',
- f'/{PAGE_NAMES["file"]}/{rel_path_b64}')],
- code=302)
+ self._redirect(PathStr(f'/{PAGE_NAMES["file"]}/{rel_path_b64}'))
def _receive_yt_query(self, query_txt: QueryText) -> None:
conn = DbConnection()
def _receive_yt_query(self, query_txt: QueryText) -> None:
conn = DbConnection()
@@
-797,10
+798,7
@@
class TaskHandler(BaseHTTPRequestHandler):
result.save(conn)
result.save_to_query(conn, query_data.id_)
conn.commit_close()
result.save(conn)
result.save_to_query(conn, query_data.id_)
conn.commit_close()
- self._send_http(
- headers=[('Location',
- f'/{PAGE_NAMES["yt_query"]}/{query_data.id_}')],
- code=302)
+ self._redirect(PathStr(f'/{PAGE_NAMES["yt_query"]}/{query_data.id_}'))
def do_GET(self) -> None: # pylint:disable=invalid-name
"""Map GET requests to handlers for various paths."""
def do_GET(self) -> None: # pylint:disable=invalid-name
"""Map GET requests to handlers for various paths."""
@@
-863,9
+861,7
@@
class TaskHandler(BaseHTTPRequestHandler):
except NotFoundException:
conn.commit_close()
self.server.downloads.queue_download(video_id)
except NotFoundException:
conn.commit_close()
self.server.downloads.queue_download(video_id)
- self._send_http(headers=[('Location',
- f'/{PAGE_NAMES["yt_result"]}/{video_id}')],
- code=302)
+ self._redirect(PathStr(f'/{PAGE_NAMES["yt_result"]}/{video_id}'))
return
conn.commit_close()
with open(file_data.full_path, 'rb') as video_file:
return
conn.commit_close()
with open(file_data.full_path, 'rb') as video_file: