mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
Use native URL parsing
Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
This commit is contained in:
parent
73deeb30e4
commit
ec6785e362
1 changed files with 1 additions and 26 deletions
|
@ -1,28 +1,3 @@
|
||||||
export function decodeSafeLinksURL(safeLinksUrl: string) {
|
export function decodeSafeLinksURL(safeLinksUrl: string) {
|
||||||
// Decode the ATP SafeLinks URL
|
return new URL(safeLinksUrl).searchParams.get('url')
|
||||||
let originalURL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Decode the URL
|
|
||||||
originalURL = decodeURIComponent(safeLinksUrl);
|
|
||||||
|
|
||||||
// Check if it matches the SafeLinks pattern
|
|
||||||
if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) {
|
|
||||||
// Extract the original URL
|
|
||||||
originalURL = originalURL.split('?url=')[1].split('&data=')[0];
|
|
||||||
}
|
|
||||||
else if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) {
|
|
||||||
// Handle the case where "&" is encoded as "&"
|
|
||||||
originalURL = originalURL.split('?url=')[1].split('&data=')[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('Invalid SafeLinks URL provided');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error: any) {
|
|
||||||
// Handle errors
|
|
||||||
throw new Error(`Failed to decode SafeLinks URL: ${error}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return originalURL;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue