diff --git a/.dockerignore b/.dockerignore index f5a08be39..dba77200f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -18,3 +18,6 @@ dist/ db-migration-worker/ neo4j/ + +public/uploads/* +!.gitkeep diff --git a/.gitignore b/.gitignore index 6d42de246..b909223f8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ yarn-error.log dist/* coverage.lcov .nyc_output/ +public/uploads/* +!.gitkeep diff --git a/db-migration-worker/Dockerfile b/db-migration-worker/Dockerfile index 92dff618f..025be88a4 100644 --- a/db-migration-worker/Dockerfile +++ b/db-migration-worker/Dockerfile @@ -1,7 +1,7 @@ FROM mongo:4 RUN apt-get update \ - && apt-get -y install --no-install-recommends openssh-client \ + && apt-get -y install --no-install-recommends openssh-client rsync \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* COPY .ssh /root/.ssh/ diff --git a/db-migration-worker/import.sh b/db-migration-worker/import.sh index ba07217c0..0251a3582 100755 --- a/db-migration-worker/import.sh +++ b/db-migration-worker/import.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -for var in "SSH_USERNAME" "SSH_HOST" "MONGODB_USERNAME" "MONGODB_PASSWORD" "MONGODB_DATABASE" "MONGODB_AUTH_DB" +for var in "SSH_USERNAME" "SSH_HOST" "MONGODB_USERNAME" "MONGODB_PASSWORD" "MONGODB_DATABASE" "MONGODB_AUTH_DB" "UPLOADS_DIRECTORY" do if [[ -z "${!var}" ]]; then echo "${var} is undefined" @@ -14,6 +14,7 @@ echo "MONGODB_USERNAME ${MONGODB_USERNAME}" echo "MONGODB_PASSWORD ${MONGODB_PASSWORD}" echo "MONGODB_DATABASE ${MONGODB_DATABASE}" echo "MONGODB_AUTH_DB ${MONGODB_AUTH_DB}" +echo "UPLOADS_DIRECTORY ${UPLOADS_DIRECTORY}" echo "-------------------------------------------------" mongo ${MONGODB_DATABASE} --eval "db.dropDatabase();" @@ -24,6 +25,8 @@ mongodump --host localhost -d ${MONGODB_DATABASE} --port 27018 --username ${MONG ssh -S my-ctrl-socket -O check -l ${SSH_USERNAME} ${SSH_HOST} ssh -S my-ctrl-socket -O exit -l ${SSH_USERNAME} ${SSH_HOST} +rsync --archive --update --verbose ${SSH_USERNAME}@${SSH_HOST}:${UPLOADS_DIRECTORY}/* /uploads/ + for collection in "categories" "badges" "users" "contributions" "comments" "follows" "shouts" do mongoexport --db ${MONGODB_DATABASE} --collection $collection --out "/mongo-export/$collection.json" diff --git a/docker-compose.override.yml b/docker-compose.override.yml index c5e7d5cf9..0592b801b 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -9,6 +9,7 @@ services: volumes: - .:/nitro-backend - /nitro-backend/node_modules + - uploads:/nitro-backend/public/uploads command: yarn run dev neo4j: volumes: @@ -24,6 +25,7 @@ services: context: db-migration-worker volumes: - mongo-export:/mongo-export + - uploads:/uploads - ./db-migration-worker/.ssh/:/root/.ssh/ networks: - hc-network @@ -34,7 +36,9 @@ services: - "MONGODB_PASSWORD=${MONGODB_PASSWORD}" - "MONGODB_AUTH_DB=${MONGODB_AUTH_DB}" - "MONGODB_DATABASE=${MONGODB_DATABASE}" + - "UPLOADS_DIRECTORY=${UPLOADS_DIRECTORY}" command: "--smallfiles --logpath=/dev/null" volumes: mongo-export: + uploads: diff --git a/neo4j/import/badges.cql b/neo4j/import/badges.cql new file mode 100644 index 000000000..90e4755b4 --- /dev/null +++ b/neo4j/import/badges.cql @@ -0,0 +1,10 @@ +CALL apoc.load.json('file:/mongo-export/badges.json') YIELD value as badge +MERGE(b:Badge {id: badge._id["$oid"]}) +ON CREATE SET +b.key = badge.key, +b.type = badge.type, +b.icon = badge.image.path, +b.status = badge.status, +b.createdAt = badge.createdAt.`$date`, +b.updatedAt = badge.updatedAt.`$date` +; diff --git a/neo4j/import/categories.cql b/neo4j/import/categories.cql new file mode 100644 index 000000000..a2bf6a352 --- /dev/null +++ b/neo4j/import/categories.cql @@ -0,0 +1,89 @@ +CALL apoc.load.json('file:/mongo-export/categories.json') YIELD value as category +MERGE(c:Category {id: category._id["$oid"]}) +ON CREATE SET +c.name = category.title, +c.slug = category.slug, +c.icon = category.icon, +c.createdAt = category.createdAt.`$date`, +c.updatedAt = category.updatedAt.`$date` +; + +MATCH (c:Category) +WHERE (c.icon = "categories-justforfun") +SET c.icon = 'smile' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-luck") +SET c.icon = 'heart-o' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-health") +SET c.icon = 'medkit' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-environment") +SET c.icon = 'tree' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-animal-justice") +SET c.icon = 'paw' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-human-rights") +SET c.icon = 'balance-scale' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-education") +SET c.icon = 'graduation-cap' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-cooperation") +SET c.icon = 'users' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-politics") +SET c.icon = 'university' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-economy") +SET c.icon = 'money' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-technology") +SET c.icon = 'flash' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-internet") +SET c.icon = 'mouse-pointer' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-art") +SET c.icon = 'paint-brush' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-freedom-of-speech") +SET c.icon = 'bullhorn' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-sustainability") +SET c.icon = 'shopping-cart' +; + +MATCH (c:Category) +WHERE (c.icon = "categories-peace") +SET c.icon = 'angellist' +; diff --git a/neo4j/import/follows.cql b/neo4j/import/follows.cql new file mode 100644 index 000000000..0dad6a435 --- /dev/null +++ b/neo4j/import/follows.cql @@ -0,0 +1,4 @@ +CALL apoc.load.json('file:/mongo-export/follows.json') YIELD value as follow +MATCH (u1:User {id: follow.userId}), (u2:User {id: follow.foreignId}) +MERGE (u1)-[:FOLLOWS]->(u2) +; diff --git a/neo4j/import/import.sh b/neo4j/import/import.sh index 319f1a591..80b6595fc 100755 --- a/neo4j/import/import.sh +++ b/neo4j/import/import.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" echo "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;" | cypher-shell -for collection in "users" "contributions" "comments" +for collection in "badges" "categories" "users" "follows" "contributions" "shouts" "comments" do echo "Import ${collection}..." && cypher-shell < $SCRIPT_DIRECTORY/$collection.cql done diff --git a/neo4j/import/shouts.cql b/neo4j/import/shouts.cql new file mode 100644 index 000000000..60aca50c9 --- /dev/null +++ b/neo4j/import/shouts.cql @@ -0,0 +1,4 @@ +CALL apoc.load.json('file:/mongo-export/shouts.json') YIELD value as shout +MATCH (u:User {id: shout.userId}), (p:Post {id: shout.foreignId}) +MERGE (u)-[:SHOUTED]->(p) +; diff --git a/neo4j/import/todo b/neo4j/import/todo index 0b86c8bc5..139597f9c 100644 --- a/neo4j/import/todo +++ b/neo4j/import/todo @@ -1,29 +1,2 @@ -CALL apoc.load.json('file:/mongo-export/categories.json') YIELD value as category -MERGE(c:Category {id: category._id["$oid"]}) -ON CREATE SET c.name = category.title, - c.slug = category.slug, - c.icon = category.icon -CALL apoc.load.json('file:/mongo-export/badges.json') YIELD value as badge -MERGE(b:Badge {id: badge._id["$oid"]}) -ON CREATE SET b.key = badge.key, - b.type = badge.type, - b.icon = badge.image.path, - b.status = badge.status - - - - - - -CALL apoc.load.json('file:/mongo-export/follows.json') YIELD value as follow -MATCH (u1:User {id: follow.userId}), - (u2:User {id: follow.foreignId}) -MERGE (u1)-[:FOLLOWS]->(u2) - - -CALL apoc.load.json('file:/mongo-export/shouts.json') YIELD value as shout -MATCH (u:User {id: shout.userId}), - (p:Post {id: shout.foreignId}) -MERGE (u)-[:SHOUTED]->(p) diff --git a/public/.gitkeep b/public/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/public/img/badges/fundraisingbox_de_airship.svg b/public/img/badges/fundraisingbox_de_airship.svg new file mode 100644 index 000000000..078dcf4f9 --- /dev/null +++ b/public/img/badges/fundraisingbox_de_airship.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_alienship.svg b/public/img/badges/fundraisingbox_de_alienship.svg new file mode 100644 index 000000000..e891c5fa9 --- /dev/null +++ b/public/img/badges/fundraisingbox_de_alienship.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_balloon.svg b/public/img/badges/fundraisingbox_de_balloon.svg new file mode 100644 index 000000000..6fc436d86 --- /dev/null +++ b/public/img/badges/fundraisingbox_de_balloon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_bigballoon.svg b/public/img/badges/fundraisingbox_de_bigballoon.svg new file mode 100644 index 000000000..e2650963a --- /dev/null +++ b/public/img/badges/fundraisingbox_de_bigballoon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_crane.svg b/public/img/badges/fundraisingbox_de_crane.svg new file mode 100644 index 000000000..4904c5ec5 --- /dev/null +++ b/public/img/badges/fundraisingbox_de_crane.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_glider.svg b/public/img/badges/fundraisingbox_de_glider.svg new file mode 100644 index 000000000..0c15955de --- /dev/null +++ b/public/img/badges/fundraisingbox_de_glider.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_helicopter.svg b/public/img/badges/fundraisingbox_de_helicopter.svg new file mode 100644 index 000000000..3a84e4466 --- /dev/null +++ b/public/img/badges/fundraisingbox_de_helicopter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/fundraisingbox_de_starter.svg b/public/img/badges/fundraisingbox_de_starter.svg new file mode 100644 index 000000000..99980560e --- /dev/null +++ b/public/img/badges/fundraisingbox_de_starter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_bear.svg b/public/img/badges/indiegogo_en_bear.svg new file mode 100644 index 000000000..43465a0e6 --- /dev/null +++ b/public/img/badges/indiegogo_en_bear.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_panda.svg b/public/img/badges/indiegogo_en_panda.svg new file mode 100644 index 000000000..a2f211e85 --- /dev/null +++ b/public/img/badges/indiegogo_en_panda.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_rabbit.svg b/public/img/badges/indiegogo_en_rabbit.svg new file mode 100644 index 000000000..c8c0c9727 --- /dev/null +++ b/public/img/badges/indiegogo_en_rabbit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_racoon.svg b/public/img/badges/indiegogo_en_racoon.svg new file mode 100644 index 000000000..619cb75f1 --- /dev/null +++ b/public/img/badges/indiegogo_en_racoon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_rhino.svg b/public/img/badges/indiegogo_en_rhino.svg new file mode 100644 index 000000000..71c0eb1ad --- /dev/null +++ b/public/img/badges/indiegogo_en_rhino.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_tiger.svg b/public/img/badges/indiegogo_en_tiger.svg new file mode 100644 index 000000000..88583a472 --- /dev/null +++ b/public/img/badges/indiegogo_en_tiger.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_turtle.svg b/public/img/badges/indiegogo_en_turtle.svg new file mode 100644 index 000000000..6b5431c2e --- /dev/null +++ b/public/img/badges/indiegogo_en_turtle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_whale.svg b/public/img/badges/indiegogo_en_whale.svg new file mode 100644 index 000000000..458e03b6d --- /dev/null +++ b/public/img/badges/indiegogo_en_whale.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/indiegogo_en_wolf.svg b/public/img/badges/indiegogo_en_wolf.svg new file mode 100644 index 000000000..e4952d86f --- /dev/null +++ b/public/img/badges/indiegogo_en_wolf.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/user_role_admin.svg b/public/img/badges/user_role_admin.svg new file mode 100644 index 000000000..101e7458d --- /dev/null +++ b/public/img/badges/user_role_admin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/user_role_developer.svg b/public/img/badges/user_role_developer.svg new file mode 100644 index 000000000..55d363c9a --- /dev/null +++ b/public/img/badges/user_role_developer.svg @@ -0,0 +1 @@ +</> \ No newline at end of file diff --git a/public/img/badges/user_role_moderator.svg b/public/img/badges/user_role_moderator.svg new file mode 100644 index 000000000..bb2e5fde6 --- /dev/null +++ b/public/img/badges/user_role_moderator.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_bee.svg b/public/img/badges/wooold_de_bee.svg new file mode 100644 index 000000000..e716c6116 --- /dev/null +++ b/public/img/badges/wooold_de_bee.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_butterfly.svg b/public/img/badges/wooold_de_butterfly.svg new file mode 100644 index 000000000..6d2b83e31 --- /dev/null +++ b/public/img/badges/wooold_de_butterfly.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_double_rainbow.svg b/public/img/badges/wooold_de_double_rainbow.svg new file mode 100644 index 000000000..406001188 --- /dev/null +++ b/public/img/badges/wooold_de_double_rainbow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_end_of_rainbow.svg b/public/img/badges/wooold_de_end_of_rainbow.svg new file mode 100644 index 000000000..2ae24cb7b --- /dev/null +++ b/public/img/badges/wooold_de_end_of_rainbow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_flower.svg b/public/img/badges/wooold_de_flower.svg new file mode 100644 index 000000000..ffc4b3da4 --- /dev/null +++ b/public/img/badges/wooold_de_flower.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_lifetree.svg b/public/img/badges/wooold_de_lifetree.svg new file mode 100644 index 000000000..5a89fa5f9 --- /dev/null +++ b/public/img/badges/wooold_de_lifetree.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_magic_rainbow.svg b/public/img/badges/wooold_de_magic_rainbow.svg new file mode 100644 index 000000000..74df95190 --- /dev/null +++ b/public/img/badges/wooold_de_magic_rainbow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/badges/wooold_de_super_founder.svg b/public/img/badges/wooold_de_super_founder.svg new file mode 100644 index 000000000..b437f6383 --- /dev/null +++ b/public/img/badges/wooold_de_super_founder.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/middleware/fixImageUrlsMiddleware.js b/src/middleware/fixImageUrlsMiddleware.js index c3b828dae..e5dc47a6d 100644 --- a/src/middleware/fixImageUrlsMiddleware.js +++ b/src/middleware/fixImageUrlsMiddleware.js @@ -7,7 +7,7 @@ const legacyUrls = [ export const fixUrl = (url) => { legacyUrls.forEach((legacyUrl) => { - url = url.replace(legacyUrl, '') + url = url.replace(legacyUrl, '/api') }) return url } diff --git a/src/middleware/fixImageUrlsMiddleware.spec.js b/src/middleware/fixImageUrlsMiddleware.spec.js index 081154c5c..89d2a520d 100644 --- a/src/middleware/fixImageUrlsMiddleware.spec.js +++ b/src/middleware/fixImageUrlsMiddleware.spec.js @@ -4,14 +4,14 @@ describe('fixImageURLs', () => { describe('image url of legacy alpha', () => { it('removes domain', () => { const url = 'https://api-alpha.human-connection.org/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png' - expect(fixImageURLs(url)).toEqual('/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png') + expect(fixImageURLs(url)).toEqual('/api/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png') }) }) describe('image url of legacy staging', () => { it('removes domain', () => { const url = 'https://staging-api.human-connection.org/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg' - expect(fixImageURLs(url)).toEqual('/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg') + expect(fixImageURLs(url)).toEqual('/api/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg') }) }) diff --git a/src/server.js b/src/server.js index 76e8419b7..728237562 100644 --- a/src/server.js +++ b/src/server.js @@ -2,6 +2,7 @@ import { GraphQLServer } from 'graphql-yoga' import { makeExecutableSchema } from 'apollo-server' import { augmentSchema } from 'neo4j-graphql-js' import { typeDefs, resolvers } from './graphql-schema' +import express from 'express' import dotenv from 'dotenv' import mocks from './mocks' import middleware from './middleware' @@ -68,6 +69,7 @@ const createServer = (options) => { passport.use('jwt', jwtStrategy(driver)) server.express.use(passport.initialize()) + server.express.use(express.static('public')) server.express.post('/graphql', passport.authenticate(['jwt'], { session: false })) return server