From: Jakub Czajka Date: Wed, 18 Dec 2024 15:58:41 +0000 (+0100) Subject: [miniflux] Download entries with ydlpd. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=9a7656669db43e5f5f260b4b3b2f5f8ef31f3d83;p=server.git [miniflux] Download entries with ydlpd. --- diff --git a/miniflux/download.sh b/miniflux/download.sh new file mode 100755 index 0000000..88d62a5 --- /dev/null +++ b/miniflux/download.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. +# +# Clicking on the "Download" button on entry's page sends a POST request to +# /entry/download/. This script resolves the to an +# and redirects the client to /ydlpd?url= with HTTP 303 See Other [1]. This +# causes the client to automatically send a GET request to that address. +# +# [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303 + +. /etc/environment + +VIDEO=$(/usr/bin/psql --user=miniflux \ + --dbname=${RSS_DB} \ + --tuples-only \ + --no-align \ + --command=" +SELECT url +FROM entries +WHERE id = ${ENTRY_ID}") + +echo "HTTP/1.1 303 See Other" +echo "Location: /ydlpd?url=${VIDEO}" +echo "Content-Type: text/html; charset=UTF-8" +echo "Content-Length: 0" +echo "" diff --git a/miniflux/rss.conf b/miniflux/rss.conf index dbe0a09..9cc60e6 100644 --- a/miniflux/rss.conf +++ b/miniflux/rss.conf @@ -15,6 +15,26 @@ server { root ${prod_dir}/${rss}; + location ~ ^/entry/download/(\d+)$ { + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + + fastcgi_read_timeout 30; + + fastcgi_param ENTRY_ID ${dollar}1; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/download.sh; + } + + location ~ ^/ydlpd(.*)$ { + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + + fastcgi_read_timeout 30; + + fastcgi_param URL ${dollar}arg_url; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/ydlpd.sh; + } + location / { proxy_pass http://127.0.0.1:4080; proxy_redirect off; diff --git a/miniflux/ydlpd.sh b/miniflux/ydlpd.sh new file mode 100755 index 0000000..3f3b3fa --- /dev/null +++ b/miniflux/ydlpd.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. +# +# If user downloads entry's page, miniflux embeds the HTML. The response needs to +# have the following format [1]: +# +# { +# "content": "", +# "reading_time": "" +# } +# +# Moreover, the HTML embeded in JSON needs to have '\n' instead of new lines. +# This script returns a HTML form to select the format for download and passes +# it alongside video's URL to ydlpd for download. +# +# [1] https://github.com/miniflux/v2/blob/main/internal/ui/static/js/app.js#L355 + +. /etc/environment + +PAGE=$(echo "\ +
+
+ +
+ + +
+
+
" | sed 's/^[ \t]*//g') + +echo "HTTP/1.1 200 OK" +echo "Content-type: text/json" +echo "" +echo -n "{\"content\": \"${PAGE}\"" | sed --null-data 's/\n/\\n/g' +echo -n ", \"reading_time\": \"1\"}"