From: Jakub Czajka Date: Tue, 2 Jan 2024 13:47:55 +0000 (+0100) Subject: Enable amending files to directories. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=61c4c4542ccf4bd7a570954f025e8a8727758bfd;p=gdrive_proxy.git Enable amending files to directories. --- diff --git a/COPYING b/COPYING index eb31ee2..5250608 100644 --- 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 + Copyright (C) 2023-2024 Jakub Czajka 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 + gdrive_proxy Copyright (C) 2023-2024 Jakub Czajka 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 index 0000000..46f94c7 --- /dev/null +++ b/amend.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# 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 " + + + + + + +" +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 "\ + +" diff --git a/gdrive_proxy.conf b/gdrive_proxy.conf index 07079f9..aea72dd 100644 --- a/gdrive_proxy.conf +++ b/gdrive_proxy.conf @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Jakub Czajka +# Copyright (c) 2023-2024 Jakub Czajka # 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; diff --git a/gdrive_proxy.sh b/gdrive_proxy.sh index f3cfab1..230c64a 100755 --- a/gdrive_proxy.sh +++ b/gdrive_proxy.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (c) 2023 Jakub Czajka +# Copyright (c) 2023-2024 Jakub Czajka # License: GPL-3.0 or later. . /etc/environment @@ -47,6 +47,17 @@ PAGE=" +
+
+ Amend + + + +
+
+
Download