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)
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,
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()
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."""
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: