diff --git a/backend/Dockerfile b/backend/Dockerfile index 3dae08143..cfaecac9e 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -25,4 +25,5 @@ ENV NODE_ENV=production COPY --from=build-and-test /nitro-backend/dist ./dist COPY ./public/img/ ./public/img/ COPY ./public/providers.json ./public/providers.json +COPY ./public/add_image_aspect_ratio.sh ./public/add_image_aspect_ratio.sh RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache diff --git a/backend/add_teaser_image_heights.sh b/backend/add_teaser_image_heights.sh deleted file mode 100755 index 154ccdafb..000000000 --- a/backend/add_teaser_image_heights.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -shopt -s nullglob -TEMP_FILE=/var/lib/neo4j/import/temp.json -for image in public/uploads/*; do - [ -e "$image" ] || continue - export IMAGE_METADATA=$( identify -format '%w %h' "$image" ) - JSON_STRING=$( jq -n \ - --arg imageURL "$image" \ - --arg imageMetaData "$IMAGE_METADATA" \ - '{imageURL: $imageURL, imageMetaData: $imageMetaData}' ) - echo "$JSON_STRING," >> "$TEMP_FILE" -done - -ENV_FILE=$(dirname "$0")/.env -[[ -f "$ENV_FILE" ]] && source "$ENV_FILE" - -if [ -z "$NEO4J_USERNAME" ] || [ -z "$NEO4J_PASSWORD" ]; then - echo "Please set NEO4J_USERNAME and NEO4J_PASSWORD environment variables." - echo "Database manipulation is not possible without connecting to the database." - echo "E.g. you could \`cp .env.template .env\` unless you run the script in a docker container" -fi - -until echo 'RETURN "Connection successful" as info;' | cypher-shell -do - echo "Connecting to neo4j failed, trying again..." - sleep 1 -done -echo " -WITH "file:${TEMP_FILE}" -AS url -CALL apoc.load.json(url) YIELD value as post -MATCH (p:Post {image: post.imageURL}) return p; -" | cypher-shell diff --git a/backend/public/add_image_aspect_ratio.sh b/backend/public/add_image_aspect_ratio.sh new file mode 100755 index 000000000..7fe2c5871 --- /dev/null +++ b/backend/public/add_image_aspect_ratio.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +if [ -z "$NEO4J_USERNAME" ] || [ -z "$NEO4J_PASSWORD" ]; then + echo "Please set NEO4J_USERNAME and NEO4J_PASSWORD environment variables." + echo "Database manipulation is not possible without connecting to the database." + echo "E.g. you could \`cp .env.template .env\` unless you run the script in a docker container" +fi + +until echo 'RETURN "Connection successful" as info;' | cypher-shell +do + echo "Connecting to neo4j failed, trying again..." + sleep 1 +done + +shopt -s nullglob +for image in uploads/*; do + [ -e "$image" ] || continue + IMAGE_WIDTH=$( identify -format '%w' "$image" ) + IMAGE_HEIGHT=$( identify -format '%h' "$image" ) + IMAGE_ASPECT_RATIO=$(echo | awk "{ print ${IMAGE_WIDTH}/${IMAGE_HEIGHT}}") + + + echo "$image" + echo "$IMAGE_ASPECT_RATIO" + echo " + match (post:Post {image: '/"${image}"'}) + set post.imageAspectRatio = "${IMAGE_ASPECT_RATIO}" + return post; + " | cypher-shell +done diff --git a/neo4j/add_teaser_image_heights.sh b/neo4j/add_teaser_image_heights.sh deleted file mode 100644 index 890492ddc..000000000 --- a/neo4j/add_teaser_image_heights.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -e - -echo "images" -shopt -s nullglob -for image in *; do -# [ -e "$image" ] || continue - echo "$image" -done - -# ENV_FILE=$(dirname "$0")/.env -# [[ -f "$ENV_FILE" ]] && source "$ENV_FILE" - -# if [ -z "$NEO4J_USERNAME" ] || [ -z "$NEO4J_PASSWORD" ]; then -# echo "Please set NEO4J_USERNAME and NEO4J_PASSWORD environment variables." -# echo "Database manipulation is not possible without connecting to the database." -# echo "E.g. you could \`cp .env.template .env\` unless you run the script in a docker container" -# fi - -# until echo 'RETURN "Connection successful" as info;' | cypher-shell -# do -# echo "Connecting to neo4j failed, trying again..." -# sleep 1 -# done - -# echo " -# MATCH (post:Post) where post.teaserImageHeight is not null return post; -# " | cypher-shell \ No newline at end of file