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

fix: site map generation #2246

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
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
48 changes: 43 additions & 5 deletions next-sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* eslint-disable import/no-dynamic-require */
const range = require('lodash/range');
const fetch = require('node-fetch');

const CryptoJS = require('crypto-js');
const englishChaptersData = require('./data/chapters/en.json');
const { locales } = require('./i18n.json');

Expand All @@ -19,24 +19,62 @@ const shouldGenerateAdditionalPaths =
const BASE_PATH =
`${isDevelopment ? 'http' : 'https'}://${process.env.NEXT_PUBLIC_VERCEL_URL}` ||
'https://quran.com';
const BASE_AUTH_PATH = process.env.NEXT_PUBLIC_AUTH_BASE_URL;

const { API_GATEWAY_URL } = process.env;
const API_CONTENT_URL = `${API_GATEWAY_URL}/content`;
const API_AUTH_URL = `${API_GATEWAY_URL}/auth`;
const QDC_PREFIX = '/api/qdc';

const chapters = range(1, 115);

const generateSignature = (url) => {
const currentTimestamp = new Date().getTime().toString();

const rawString = `${url}.${currentTimestamp}`;
const signature = CryptoJS.HmacSHA512(rawString, process.env.SIGNATURE_TOKEN);
const encodedSignature = CryptoJS.enc.Base64.stringify(signature);

return { signature: encodedSignature, timestamp: currentTimestamp };
};

const getAvailableCourses = async () => {
const res = await fetch(`${BASE_AUTH_PATH}/courses`);
const coursesURL = `${API_AUTH_URL}/courses`;
const { signature, timestamp } = generateSignature(coursesURL);
const res = await fetch(coursesURL, {
headers: {
'x-auth-signature': signature,
'x-timestamp': timestamp,
'x-internal-client': process.env.INTERNAL_CLIENT_ID,
},
});
const data = await res.json();
return data;
};

const getAvailableTafsirs = async () => {
const res = await fetch(`https://api.qurancdn.com/api/qdc/resources/tafsirs`);
const tafsirsURL = `${API_CONTENT_URL}${QDC_PREFIX}/resources/tafsirs`;
const { signature, timestamp } = generateSignature(tafsirsURL);
const res = await fetch(tafsirsURL, {
headers: {
'x-auth-signature': signature,
'x-timestamp': timestamp,
'x-internal-client': process.env.INTERNAL_CLIENT_ID,
},
});
const data = await res.json();
return data;
};

const getAvailableReciters = async () => {
const res = await fetch(`https://api.qurancdn.com/api/qdc/audio/reciters`);
const recitersURL = `${API_CONTENT_URL}${QDC_PREFIX}/audio/reciters`;
const { signature, timestamp } = generateSignature(recitersURL);
const res = await fetch(recitersURL, {
headers: {
'x-auth-signature': signature,
'x-timestamp': timestamp,
'x-internal-client': process.env.INTERNAL_CLIENT_ID,
},
});
const data = await res.json();
return data;
};
Expand Down