diff --git a/CHANGELOG.md b/CHANGELOG.md index 1338590..d90295d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog +### Version 1.0.1 + +#### bugfix +* PR [#22](https://github.com/petercort/FBF-Buddy/pull/22) - Setup db connection + + + ### Version 0.1.0 #### enhancement diff --git a/package.json b/package.json index a5839d0..56604ef 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fbf-event-buddy", "private": true, - "version": "1.0.0", + "version": "1.0.1", "description": "Cycling event app for Discord", "main": "app.js", "engines": { diff --git a/src/app.js b/src/app.js index 9522d2c..2935d5c 100644 --- a/src/app.js +++ b/src/app.js @@ -8,7 +8,7 @@ require('dotenv').config(); let discordToken; if (process.env.NODE_ENV === 'production'){ - const discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8'); + discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8'); } else { discordToken = process.env.discordToken } diff --git a/src/commands/utility/connect_strava.js b/src/commands/utility/connect_strava.js index ec4e76f..f7f0bc1 100644 --- a/src/commands/utility/connect_strava.js +++ b/src/commands/utility/connect_strava.js @@ -5,14 +5,14 @@ const fs = require('node:fs'); require('dotenv').config(); let stravaClientId; -let stravaRedirectURI; +let stravaRedirectUri; if (process.env.NODE_ENV === 'production') { stravaClientId = fs.readFileSync("/mnt/secrets-store/stravaClientId", 'utf8'); - stravaRedirectURI = fs.readFileSync("/mnt/secrets-store/stravaRedirectURI", 'utf8'); + stravaRedirectUri = fs.readFileSync("/mnt/secrets-store/stravaRedirectUri", 'utf8'); } else { stravaClientId = process.env.stravaClientId; - stravaRedirectURI = process.env.stravaRedirectURI; + stravaRedirectUri = process.env.stravaRedirectUri; } module.exports = { @@ -21,7 +21,7 @@ module.exports = { .setDescription('Connect your Strava account to collect ride data.'), async execute(interaction) { const userId = interaction.user.id; - const stravaAuthUrl = `https://www.strava.com/oauth/authorize?client_id=${stravaClientId}&response_type=code&redirect_uri=${stravaRedirectURI}/${userId}&scope=read,activity:read_all,profile:read_all`; + const stravaAuthUrl = `https://www.strava.com/oauth/authorize?client_id=${stravaClientId}&response_type=code&redirect_uri=${stravaRedirectUri}/${userId}&scope=read,activity:read_all,profile:read_all`; const embed = new EmbedBuilder() .setTitle('Connect Strava') diff --git a/src/dbObjects.js b/src/dbObjects.js index 9960d5f..84b1dcd 100644 --- a/src/dbObjects.js +++ b/src/dbObjects.js @@ -2,28 +2,11 @@ const { Sequelize } = require('sequelize'); const fs = require('node:fs'); require('dotenv').config(); -let usePostgres = true; -let database; -let username; -let password; -let host; let sequelize; -let config; + if (process.env.NODE_ENV === 'production') { - database = fs.readFileSync("/mnt/secrets-store/database", 'utf8') - username = fs.readFileSync("/mnt/secrets-store/username", 'utf8') - password = fs.readFileSync("/mnt/secrets-store/password", 'utf8') - host = fs.readFileSync("/mnt/secrets-store/host", 'utf8') - config = { - host: process.env.host, - dialect: 'sqlite', - logging: false, - storage: 'database.sqlite', - } - sequelize = new Sequelize(database, username, password, config); -} else if (usePostgres) { - const databaseUrl = process.env.databaseUrl + const databaseUrl = fs.readFileSync("/mnt/secrets-store/databaseUrl", 'utf8') const config = { dialect: 'postgres', ssl: { @@ -33,10 +16,10 @@ if (process.env.NODE_ENV === 'production') { } sequelize = new Sequelize(databaseUrl, config) } else { - database = process.env.database - username = process.env.username - password = process.env.password - config = { + const database = process.env.database + const username = process.env.username + const password = process.env.password + const config = { host: process.env.host, dialect: 'sqlite', logging: false, diff --git a/src/shared_library/strava_authentication.js b/src/shared_library/strava_authentication.js index 6363648..8664b9e 100644 --- a/src/shared_library/strava_authentication.js +++ b/src/shared_library/strava_authentication.js @@ -4,20 +4,20 @@ const fs = require('node:fs'); require('dotenv').config(); let stravaClientId; -let stravaClentSecret; +let stravaClientSecret; if (process.env.NODE_ENV === 'production') { stravaClientId = fs.readFileSync("/mnt/secrets-store/stravaClientId", 'utf8'); - stravaClentSecret = fs.readFileSync("/mnt/secrets-store/stravaClentSecret", 'utf8'); + stravaClientSecret = fs.readFileSync("/mnt/secrets-store/stravaClientSecret", 'utf8'); } else { stravaClientId = process.env.stravaClientId; - stravaClentSecret = process.env.stravaClentSecret; + stravaClientSecret = process.env.stravaClientSecret; } async function firstTimeAuth(userId, code){ try { const response = await axios.post('https://www.strava.com/oauth/token', { client_id: stravaClientId, - client_secret: stravaClentSecret, + client_secret: stravaClientSecret, code: code, grant_type: 'authorization_code' }); @@ -43,7 +43,7 @@ async function getStravaAuthentication(userData) { console.log('Token is expired, refreshing...'); const refreshTokenResponse = await axios.post('https://www.strava.com/oauth/token', { client_id: stravaClientId, - client_secret: stravaClentSecret, + client_secret: stravaClientSecret, grant_type: 'refresh_token', refresh_token: userData.refreshToken, });