Skip to content

Commit

Permalink
support upload of attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal committed Nov 20, 2023
1 parent cdcd88c commit 54bf042
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions interactive_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,45 @@ if [ "$app" == 0 ] && [ "$UPTIMEROBOT_API_KEY" != "" ] && [ "$UPTIMEROBOT_ALERT_
fi
fi

if [ "$app" == 0 ]; then
#if [ "$app" == 0 ]; then
if [ -n "$4" ]; then
baseConfig="$4"
else
echo "Which basic config do you want to include?"
read -r baseConfig
fi
if [ -n "$baseConfig" ]; then
# Needs to be in CouchDB '/_bulk_docs' format: https://docs.couchdb.org/en/stable/api/database/bulk-api.html#updating-documents-in-bulk
curl -u "admin:$COUCHDB_PASSWORD" -d "@baseConfigs/$baseConfig.json" -H 'Content-Type: application/json' "https://$APP_URL/db/app/_bulk_docs"
if [ "$backend" == 1 ]; then
couchdb="https://$APP_URL/db/couchdb"
else
couchdb="https://$APP_URL/db"
fi

# Needs to be in CouchDB '/_bulk_docs' format: https://docs.couchdb.org/en/stable/api/database/bulk-api.html#updating-documents-in-bulk
curl -u "admin:$COUCHDB_PASSWORD" -d "@baseConfigs/$baseConfig/entities.json" -H 'Content-Type: application/json' "$couchdb/app/_bulk_docs"
if [ -d "baseConfigs/$baseConfig/attachments" ]; then
# Uploading attachments - ONLY IMAGES ARE SUPPORTED
# create folder inside 'attachments' with name of the entity containing images with name of the property
for dir in baseConfigs/"$baseConfig"/attachments/*
do
entity=${dir##*/}
# Create parent document
rev=$(curl -X PUT -u "admin:$COUCHDB_PASSWORD" "$couchdb/app-attachments/$entity")
rev="${rev#*\"rev\":\"}"
rev="${rev%%\"*}"
for file in dir/*
do
prop="${file##*/}"
ext="${prop##*.}"
prop="${prop%%.*}"
# Upload image
rev=$(curl -X PUT -u "admin:$COUCHDB_PASSWORD" -H "Content-Type: image/$ext" -d "@$file" "$couchdb/app-attachments/$entity/$prop?rev=$rev")
rev="${rev#*\"rev\":\"}"
rev="${rev%%\"*}"
done
done
fi
fi
fi
#fi

echo "app is now available under https://$APP_URL"

0 comments on commit 54bf042

Please sign in to comment.