:-'Generic Commit'

This commit is contained in:
Your Name 2025-05-29 23:26:50 +12:00
parent fc4096d649
commit 7a82afaf4c

39
sos/sos
View File

@ -27,6 +27,7 @@ EOF
} }
function die() { function die() {
echo "FATAL:"
echo "$@" echo "$@"
exit 1 exit 1
} }
@ -50,14 +51,40 @@ function upload() {
fi fi
# upload the file # upload the file
echo "Uploading $file to $server - $label..." TARGET_URL="https://$server/upload"
echo "Uploading $file to $TARGET_URL"
METADATA_JSON=$(cat<<EOF
{
"labeltags": ["$label"],
"description": "Uploaded by sos"
}
EOF
)
echo "Metadata:"
echo "$METADATA_JSON | jq"
TOKENPATH="$HOME/.config/sos/write_token.txt"
if [ ! -f "$TOKENPATH" ]; then
die "Token file not found: $TOKENPATH. Please create it and put your write token in it."
fi
WRITE_TOKEN=$(cat "$TOKENPATH")
METADATA="{\"labeltags\":[\"$label\"],\"description\":\"Uploaded by sos\"}"
HASH="" HASH=""
JSON=$(curl -s -X POST -F "file=@$file" -F "metadata=$METADATA" "https://$server/$label") || die "Failed to upload $file to $server - $label"
HASH=$(echo "$JSON" | jq -r '.hash') UPLOAD_RESPONSE=$(curl -X PUT \
JSON2=$(curl -s "https://$server/meta/$HASH") || die "Failed to get meta for $HASH" -H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@${file}" \
-F "metadata=${METADATA_JSON}" \
"$TARGET_URL" \
) || die "Failed to upload $file to $TARGET_URL"
echo "Repsonse:"
echo "$UPLOAD_RESPONSE"
HASH=$(echo "$UPLOAD_RESPONSE" | jq -r '.hash')
JSON2=$(eval "curl -s \"https://$server/meta/$HASH\"") || die "Failed to get meta for $HASH"
FILENAME=$(echo "$JSON2" | jq -r '.filename') FILENAME=$(echo "$JSON2" | jq -r '.filename')
echo "Download URL: https://$server/$label > $FILENAME" echo "Download URL: https://$server/$label > $FILENAME"