]> git.ekhem.eu.org Git - gdrive_proxy.git/commitdiff
Wrap `download` to return HTTP responses.
authorJakub Czajka <jakub@ekhem.eu.org>
Tue, 21 Nov 2023 23:30:33 +0000 (00:30 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Mon, 4 Dec 2023 02:17:06 +0000 (03:17 +0100)
download.sh [new file with mode: 0755]

diff --git a/download.sh b/download.sh
new file mode 100755 (executable)
index 0000000..2cc5bf9
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+. /etc/environment
+
+# Replace %2F with '/' and remove %0D%0A.
+NAME=$(echo ${NAME_ON_DRIVE} | sed 's/%2F/\//g; s/%0D%0A//g')
+
+echo "HTTP/1.1 200 OK"
+echo "Content-Type: text/html"
+echo "
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv='Refresh' content='0;URL=/$(basename ${NAME})' />
+  <style>
+    body {
+      white-space: pre-wrap;
+    }
+  </style>
+</head>
+<body>"
+echo "Downloading ${NAME}"
+python3 -u -m gdrive_knife 2>&1 download --token ${gdrive_auth_token} \
+    --key ${gdrive_encryption_key} --leave-as-archive ${NAME} /tmp
+echo "\
+</body>
+</html>"