Skip to content

Commit

Permalink
feat: save form selection, detect new config files on startup
Browse files Browse the repository at this point in the history
Changes:
- Add new configuration files to startup check to ensure the default configuration file is not moved into the directory mounted to /config if any of those files are present
- Persist selected download option between page reloads with localStorage
- Add settings for Jinja HTML template syntax highlighting in VS Code
  • Loading branch information
qx6ghqkz committed Jan 18, 2025
1 parent 5d1e625 commit 41a0ec7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"files.associations": {
"*.html": "jinja-html"
},
"emmet.includeLanguages": {
"jinja-html": "html"
},
"python.analysis.typeCheckingMode": "basic",
"[python]": {
"editor.formatOnSave": true,
Expand Down
16 changes: 8 additions & 8 deletions gallery_dl_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def redirect(request: Request):
return RedirectResponse(url="/gallery-dl")


async def dl_queue_list(request: Request):
async def homepage(request: Request):
return templates.TemplateResponse(
"index.html",
{
Expand All @@ -49,18 +49,18 @@ async def dl_queue_list(request: Request):
)


async def q_put(request: Request):
async def submit_form(request: Request):
global blank_sent

if not blank_sent:
blank.info("")
blank_sent = True

form = await request.form()
form_data = await request.form()

url = form.get("url")
ui = form.get("ui")
video_opts = form.get("video-opts")
url = form_data.get("url")
ui = form_data.get("ui")
video_opts = form_data.get("video-opts")

data = [url, ui, video_opts]
data = [None if isinstance(value, UploadFile) else value for value in data]
Expand Down Expand Up @@ -165,8 +165,8 @@ def download_task(url: str, options: dict[str, str]):

routes = [
Route("/", endpoint=redirect, methods=["GET"]),
Route("/gallery-dl", endpoint=dl_queue_list, methods=["GET"]),
Route("/gallery-dl/q", endpoint=q_put, methods=["POST"]),
Route("/gallery-dl", endpoint=homepage, methods=["GET"]),
Route("/gallery-dl/q", endpoint=submit_form, methods=["POST"]),
Route("/gallery-dl/logs", endpoint=log_route, methods=["GET"]),
Mount("/icons", app=StaticFiles(directory=utils.resource_path("icons")), name="icons"),
]
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl_server/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = "0.6.0"
__version__ = "0.6.1"
11 changes: 10 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ start() {

init_conf() {
dir="/config"
files=("gallery-dl.conf" "config.json")
files=(
"gallery-dl.conf"
"gallery-dl.yaml"
"gallery-dl.yml"
"gallery-dl.toml"
"config.json"
"config.yaml"
"config.yml"
"config.toml"
)

if [[ -d "$dir" ]]; then
rm -f "$dir/hosts" "$dir/hostname" "$dir/resolv.conf" >/dev/null 2>&1
Expand Down
19 changes: 19 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ <h1 class="mb-2 display-4">gallery-dl</h1>
});
}

document.addEventListener("DOMContentLoaded", (event) => {
setSelectedValue();
const selectElement = document.querySelector("select[name='video-opts']");
selectElement.addEventListener("change", storeSelectedValue);
});

function setSelectedValue() {
const selectedValue = localStorage.getItem("selectedValue");
if (selectedValue) {
const selectElement = document.querySelector("select[name='video-opts']");
selectElement.value = selectedValue;
}
}

function storeSelectedValue() {
const selectElement = document.querySelector("select[name='video-opts']");
localStorage.setItem("selectedValue", selectElement.value);
}

fetchLogs();

setInterval(fetchLogs, 1000);
Expand Down

0 comments on commit 41a0ec7

Please sign in to comment.