+ Working neocities upload script
This commit is contained in:
parent
f2cba8e856
commit
beddd84836
@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
upload_file() {
|
||||
set -e
|
||||
file_path="$1"
|
||||
uri_path="${file_path:6}"
|
||||
|
||||
@ -15,12 +16,13 @@ upload_file() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Sub-routine uploads a single file for
|
||||
base='https://neocities.org/api/upload'
|
||||
# Curl gives us the exit code for this sub-routine's exit code
|
||||
curl \
|
||||
curl -s \
|
||||
-H "Authorization: Bearer ${API_KEY}" \
|
||||
-F "${uri_path}=@${file_path}"
|
||||
-F "${uri_path}=@${file_path}" \
|
||||
'https://neocities.org/api/upload'
|
||||
|
||||
return $!
|
||||
}
|
||||
|
||||
feed_files() {
|
||||
@ -34,20 +36,34 @@ feed_files() {
|
||||
# Main uploading section
|
||||
while read -r line; do
|
||||
if upload_file "$line"; then
|
||||
echo Uploaded $line
|
||||
echo "Pass $line"
|
||||
else
|
||||
echo Failed $line >&2
|
||||
echo "Failed $line" > /dev/stderr
|
||||
fi
|
||||
|
||||
sleep $SLEEP_TIME
|
||||
done < /dev/stdin
|
||||
}
|
||||
|
||||
if [ -d public/ ];then
|
||||
echo Found public directory
|
||||
# Upload all files that we wish to upload
|
||||
find public/ -type f | grep '\.[a-z]*' | feed_files
|
||||
else
|
||||
echo No public directory found
|
||||
verify_api_key() {
|
||||
if [ -z "$API_KEY" ];then
|
||||
echo '$API_KEY env var is not set' > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
verify_public_dir() {
|
||||
# Check that the public directory is present
|
||||
if [ ! -d public/ ];then
|
||||
echo 'No public directory found!' > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Pre flight checks to make sure we don't try uploading without
|
||||
# the required keys/files in place
|
||||
verify_public_dir; verify_api_key
|
||||
|
||||
# Only upload items that have an extension(files) in the case
|
||||
# of data generated by hugo
|
||||
find public/ -type f | \
|
||||
grep '\.[a-z]*' | \
|
||||
feed_files
|
||||
|
Loading…
Reference in New Issue
Block a user