39 lines
978 B
Bash
Executable File
39 lines
978 B
Bash
Executable File
#!/bin/bash
|
|
|
|
WATCH_DIR="./data/photos/upload"
|
|
|
|
if [ ! -d "$WATCH_DIR" ]; then
|
|
echo "watch dir not found: $WATCH_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
UPLOAD_URL="https://fotobox.online/upload"
|
|
|
|
FOTOBOX_KEY="bla..." # TODO
|
|
|
|
SLEEP_INTERVAL=10
|
|
|
|
while true; do
|
|
for filepath in "$WATCH_DIR"/*; do
|
|
[ -e "$filepath" ] || continue
|
|
|
|
filename=$(basename "$filepath")
|
|
filesize=$(stat -c %s "$filepath")
|
|
|
|
echo "uploading: $filepath"
|
|
response=$(curl -s -w "\n%{http_code}" -F "file=@${filepath}" -F "filename=${filename}" -F "fotoboxKey=${FOTOBOX_KEY}" "$UPLOAD_URL")
|
|
body=$(echo "$response" | head -n 1)
|
|
status=$(echo "$response" | tail -n 1)
|
|
|
|
expected="Fotobox2|||${filename}|||${filesize}"
|
|
|
|
if [ "$status" -eq 200 ] && [ "$body" = "$expected" ]; then
|
|
echo "SUCCESS"
|
|
rm -f "$filepath"
|
|
else
|
|
echo "FAILED: CODE=$status, Response=$body"
|
|
fi
|
|
done
|
|
sleep "$SLEEP_INTERVAL"
|
|
done
|