updated uploader to handle media files

This commit is contained in:
shockrah 2020-07-24 18:46:38 -07:00
parent b9b850d738
commit 0f91d2f3d5

View File

@ -7,11 +7,23 @@ auth="Authorization: Bearer $KEY"
site=.mirror site=.mirror
_upload_html() { _upload_html() {
# fix this comparison cuz its busted
if [ ${1:0:1} = "" ];then if [ ${1:0:1} = "" ];then
echo Path must start with ./ echo Path must start with ./
exit 1 exit 1
fi fi
echo $(pwd) for f in $@;do
remote_path=${f:1}
echo curl -H "$auth" -F "$remote_path=@$f" $url/api/upload
curl -H "$auth" -F "$remote_path=@$f" $url/api/upload
done
}
_upload_media() {
[[ "${1:0:1}" == "./" ]] && \
echo 'Path must start with ./' && \
exit 1
for f in $@;do for f in $@;do
remote_path=${f:1} remote_path=${f:1}
echo curl -H "$auth" -F "$remote_path=@$f" $url/api/upload echo curl -H "$auth" -F "$remote_path=@$f" $url/api/upload
@ -40,11 +52,15 @@ folder() {
_help() { _help() {
cat <<EOF cat <<EOF
PATHS:
Use a fake relative path as if we were in "$site"
Example: gensite -m ./media/img/some-post/image.jpg ...
Options: Options:
h => Reuploads all the html content h => Reuploads all the html content
r => Uploads all root html pages r => Uploads all root html pages
f [FOLDER] => Upload all html in [FOLDER] f [FOLDER] => Upload all html in [FOLDER]
s [PATH] => Upload single html page with mirrord path s [PATH] => Upload single html page with mirrord path
m [PATH] => Upload any amount of media files
EOF EOF
} }
@ -52,13 +68,14 @@ if [ -z $1 ];then
_help _help
else else
pushd $site > /dev/null pushd $site > /dev/null
while getopts ':Hhrf:s:' opt;do while getopts ':Hhrf:s:m:' opt;do
case $opt in case $opt in
H) _help;; H) _help;;
h) _upload_html $(find -name '*.html');; # Upload all html content h) _upload_html $(find -name '*.html');; # Upload all html content
r) _upload_html ./*.html;; # Upload all root html pages r) _upload_html ./*.html;; # Upload all root html pages
f) _upload_html $2/*.html;;# Upload html in the spec'd folder f) _upload_html $2/*.html;;# Upload html in the spec'd folder
s) _upload_html $2;;# upload single html page s) _upload_html $2;;# upload single html page
m) _upload_media $2;;# upload raw file
esac esac
done done
popd > /dev/null popd > /dev/null