Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating the initial sync and healthchecks #25

Merged
merged 4 commits into from
Dec 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
updating the initial sync and healthchecks
petercort committed Dec 28, 2024
commit 07c58104d48e3ec7c0ca3076998118c04fd6ea5c
9 changes: 2 additions & 7 deletions src/commands.js
Original file line number Diff line number Diff line change
@@ -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);
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
@@ -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
@@ -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
});
}