Skip to content

Commit

Permalink
Adding package*.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Graule committed Jul 17, 2024
1 parent 0d9dbb4 commit bddf971
Show file tree
Hide file tree
Showing 4 changed files with 533 additions and 21 deletions.
54 changes: 54 additions & 0 deletions backend/config/functions/satelliteUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// backend/utils/satelliteUtils.js
const axios = require('axios');

async function fetchOrbitalData(strapi, contextId) {
try {
// Fetching the satellite
const satellite = await strapi.entityService.findOne('api::satellite.satellite', contextId);
const noradId = satellite.catalogNumberNORAD;

// Authentication to Space-Track
const authResponse = await axios.post('https://www.space-track.org/ajaxauth/login', {
identity: 'floridg@stud.ntnu.no',
password: 'Vm5JxTtD3-hYBdq'
});

if (authResponse.status === 200) {
// Fetching data from Space-Track
const satelliteResponse = await axios.get(`https://www.space-track.org/basicspacedata/query/class/gp_history/NORAD_CAT_ID/${noradId}/orderby/TLE_LINE1%20ASC/EPOCH/1950-07-02--2024-07-02/format/json`, {
headers: {
Cookie: authResponse.headers['set-cookie']
}
});

if (satelliteResponse.status === 200) {
// Collecting data
const satelliteData = satelliteResponse.data;
const historicalOrbitalData = satelliteData.map(data => ({
epoch: data.EPOCH,
inclination: data.INCLINATION,
eccentricity: data.ECCENTRICITY,
semiMajorAxis: data.SEMIMAJOR_AXIS
}));

// Updating the satellite with the new data
const updatedSatellite = await strapi.entityService.update('api::satellite.satellite', contextId, {
data: {
historicalOrbitalData: historicalOrbitalData,
},
});
return updatedSatellite;
} else {
throw new Error('Error while fetching data from Space-Track');
}
} else {
throw new Error('Authentication failed');
}
} catch (error) {
console.error('Error while fetching data to Space-Track: ', error);
}
}

module.exports = {
fetchOrbitalData,
};
36 changes: 15 additions & 21 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bddf971

Please sign in to comment.