]> git.ekhem.eu.org Git - gdrive_proxy.git/commitdiff
Enable amending files to directories.
authorJakub Czajka <jakub@ekhem.eu.org>
Tue, 2 Jan 2024 13:47:55 +0000 (14:47 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Tue, 2 Jan 2024 14:10:19 +0000 (15:10 +0100)
COPYING
amend.sh [new file with mode: 0644]
gdrive_proxy.conf
gdrive_proxy.sh

diff --git a/COPYING b/COPYING
index eb31ee232b606afba83eb130b057948a59787166..5250608f7ae0d2e1780621c4ff074b189c0a2821 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively
 state the exclusion of warranty; and each file should have at least
 the "copyright" line and a pointer to where the full notice is found.
 
-    Copyright (C) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+    Copyright (C) 2023-2024 Jakub Czajka <jakub@ekhem.eu.org>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -651,7 +651,7 @@ Also add information on how to contact you by electronic and paper mail.
   If the program does terminal interaction, make it output a short
 notice like this when it starts in an interactive mode:
 
-    gdrive_proxy Copyright (C) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+    gdrive_proxy Copyright (C) 2023-2024 Jakub Czajka <jakub@ekhem.eu.org>
     This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
     This is free software, and you are welcome to redistribute it
     under certain conditions; type `show c' for details.
diff --git a/amend.sh b/amend.sh
new file mode 100644 (file)
index 0000000..46f94c7
--- /dev/null
+++ b/amend.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# Copyright (c) 2024 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+. /etc/environment
+
+FILE_TO_AMEND=$(sed --expression='/Content-Disposition.*filename/!d' \
+  --expression='s/^.*filename=\"// ; s/\".*$//' "${PATH_TO_FILE}")
+
+# See upload.sh.
+NAME_ON_DRIVE=$(sed --silent 'x;$p' "${PATH_TO_FILE}" | tr --delete '\r\n')
+sed --in-place --silent --expression='1,4d' \
+    --expression=':a;N;4,9ba;P;D' ${PATH_TO_FILE}
+
+# See download.sh.
+FULL_NAME=$(echo ${NAME_ON_DRIVE} | sed 's/%2F/\//g; s/%0D%0A//g')
+BASE_NAME=$(basename "${FULL_NAME}")
+
+# Clear /tmp for download.
+if [ -e "/tmp/${BASE_NAME}" ]
+then
+    rm -rf "/tmp/${BASE_NAME}"
+fi
+
+echo "HTTP/1.1 200 OK"
+echo "Content-Type: text/html"
+echo "
+<!DOCTYPE html>
+<html>
+<meta name='viewport' content='width=device-width'>
+<head>
+  <style>
+    body {
+      white-space: pre-wrap;
+    }
+  </style>
+</head>
+<body>"
+echo "Downloading ${FULL_NAME}"
+python3 -u -m gdrive_knife 2>&1 download --token ${gdrive_auth_token} \
+  --key ${gdrive_encryption_key} ${FULL_NAME} /tmp
+
+if [ ! -d "/tmp/${BASE_NAME}" ]
+then
+    echo "${FULL_NAME} is not a directory. Not amending."
+else
+    echo "Amending ${FILE_TO_AMEND}"
+    mv ${PATH_TO_FILE} /tmp/${BASE_NAME}/${FILE_TO_AMEND}
+
+    echo "Uploading ${FULL_NAME}"
+    python3 -u -m gdrive_knife 2>&1 upload --token ${gdrive_auth_token} \
+        --key ${gdrive_encryption_key} /tmp/${BASE_NAME} ${FULL_NAME}
+fi
+
+echo "\
+</body>
+</html>"
index 07079f95677d599952e6ad22b3f95107d82a6a36..aea72ddb0ceea45a449aac46b7566444409fbc7b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# Copyright (c) 2023-2024 Jakub Czajka <jakub@ekhem.eu.org>
 # License: GPL-3.0 or later.
 
 server {
@@ -69,6 +69,23 @@ server {
         fastcgi_param SCRIPT_FILENAME ${dollar}document_root/upload.sh;
     }
 
+    location = /amend {
+        include fastcgi_params;
+        fastcgi_pass unix:/var/run/fcgiwrap.socket;
+
+        client_body_in_file_only clean;
+        client_body_temp_path /tmp;
+
+        fastcgi_pass_request_body off;
+        fastcgi_pass_request_headers off;
+
+        fastcgi_buffering off;
+        fastcgi_param NO_BUFFERING "";
+
+        fastcgi_param PATH_TO_FILE ${dollar}request_body_file;
+        fastcgi_param SCRIPT_FILENAME ${dollar}document_root/amend.sh;
+    }
+
     location = / {
         include fastcgi_params;
         fastcgi_pass unix:/var/run/fcgiwrap.socket;
index f3cfab1e78a6fe4c530c2ec4fad4a610231847dd..230c64a04914c5cfc4cbcc7c77af3948b4f8aac4 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# Copyright (c) 2023-2024 Jakub Czajka <jakub@ekhem.eu.org>
 # License: GPL-3.0 or later.
 
 . /etc/environment
@@ -47,6 +47,17 @@ PAGE="
     </fieldset>
   </form>
 
+  <form action='/amend' method='post' enctype='multipart/form-data'>
+    <fieldset>
+      <legend>Amend</legend>
+      <input type='file' name='file' required />
+      <select id='name' name='name'>
+        $(format_files "<option value='{}'>{}</option>")
+      </select>
+      <button type='submit'>Amend</button>
+    </fieldset>
+  </form>
+
   <form action='/download'>
     <fieldset>
       <legend>Download</legend>