Skip to content

Commit

Permalink
Merge pull request #25 from petercort/issue24
Browse files Browse the repository at this point in the history
updating the initial sync and healthchecks
  • Loading branch information
petercort authored Dec 28, 2024
2 parents aa5617d + 571c102 commit 7e8a8eb
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog


### Version 1.1.0

#### bugfix
* PR [#25](https://github.com/petercort/FBF-Buddy/pull/25) - updating the initial sync and healthchecks



### Version 1.0.2

#### bugfix
Expand Down
2 changes: 1 addition & 1 deletion app.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.3
1.1.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fbf-event-buddy",
"private": true,
"version": "1.0.2",
"version": "1.1.0",
"description": "Cycling event app for Discord",
"main": "app.js",
"engines": {
Expand Down
9 changes: 2 additions & 7 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ const rest = new REST().setToken(discordToken);
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(appId, guildId),
{ body: commands },
);
await rest.put(
const data = await rest.put(
Routes.applicationCommands(appId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 19 additions & 3 deletions src/strava_webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ const fs = require('node:fs');
const { firstTimeAuth, getStravaAuthentication } = require('./shared_library/strava_authentication.js');
const app = express();
app.use(express.json());
const discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8');
require('dotenv').config()
let discordToken;

if (process.env.NODE_ENV === 'production') {
discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8');
} else {
discordToken = process.env.discordToken;
}

client.login(discordToken);

app.get('/', (req, res) => {
// send a 200 response to the root path
res.sendStatus(200);
});

app.post('/webhook', async (req, res) => {
console.log("webhook event received!", req.body);
// get the object_id and owner id
Expand Down Expand Up @@ -107,13 +120,16 @@ async function setupBikes(athleteId, userId, strava_access_token) {
// get the athlete page
// Fetch details for each bike from Strava's /gear endpoint and update the database
for (const bike of athleteResponse.data.bikes) {
const bikeData = await axios.get(`https://www.strava.com/api/v3/gear/${bike.id}`, {
headers: { Authorization: `Bearer ${strava_access_token}` }
});
// Update the database with the bike details
await BikesTable.upsert({
bikeId: bike.id,
userId: userId,
name: bike.name,
brand: bike.brand_name,
model: bike.model_name,
brand: bikeData.data.brand_name,
model: bikeData.data.model_name,
distance: bike.distance
});
}
Expand Down

0 comments on commit 7e8a8eb

Please sign in to comment.