fix(api): handle trailing / in MS transcript urls (#51766)

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Oliver Eyton-Williams
2023-10-18 17:50:13 +02:00
committed by GitHub
parent 1ad87a0cfa
commit ec51cbbd9f

View File

@@ -112,6 +112,17 @@ function deleteUserTokenResponse(req, res) {
return res.send({ userToken: null });
}
export const getMsTranscriptApiUrl = msTranscript => {
// example msTranscriptUrl: https://learn.microsoft.com/en-us/users/mot01/transcript/8u6awert43q1plo
const url = new URL(msTranscript);
const transcriptUrlRegex = /\/transcript\/([^/]+)\/?/;
const id = transcriptUrlRegex.exec(url.pathname)?.[1];
return `https://learn.microsoft.com/api/profiles/transcript/share/${
id ?? ''
}`;
};
function createPostMsUsername(app) {
const { MsUsername } = app.models;
@@ -129,8 +140,7 @@ function createPostMsUsername(app) {
});
}
const msTranscriptId = msTranscriptUrl.split('/').pop();
const msTranscriptApiUrl = `https://learn.microsoft.com/api/profiles/transcript/share/${msTranscriptId}`;
const msTranscriptApiUrl = getMsTranscriptApiUrl(msTranscriptUrl);
try {
const msApiRes = await fetch(msTranscriptApiUrl);