Skip to content

Commit

Permalink
updating the initial sync and healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
petercort committed Dec 28, 2024
1 parent 710441d commit 07c5810
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 10 deletions.
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 07c5810

Please sign in to comment.