Compare commits

...
Author SHA1 Message Date
sharevb 9d3337ff60 feat(new tool): UTM URL Generator
UTM Url Generator
Fix #935
2024-04-03 22:52:39 +02:00
sharevbandCorentin THOMASSET d3b32cc14e feat(new tool): Outlook Safelink Decoder (#911)
* feat(new tool): Outlook Safelink Decoder

Fix #897

* Use native URL parsing

Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>

* Update src/tools/safelink-decoder/index.ts

---------

Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
2024-03-11 10:19:32 +00:00
7 changed files with 235 additions and 1 deletions

No files matched your search

+4 -1
View File
@@ -5,7 +5,8 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as utmUrlGenerator } from './utm-url-generator';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -115,6 +116,7 @@ export const toolsByCategory: ToolCategory[] = [
urlEncoder,
htmlEntities,
urlParser,
utmUrlGenerator,
deviceInformation,
basicAuthGenerator,
metaTagGenerator,
@@ -127,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
userAgentParser,
httpStatusCodes,
jsonDiff,
safelinkDecoder,
],
},
{
+12
View File
@@ -0,0 +1,12 @@
import { Mailbox } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Outlook Safelink decoder',
path: '/safelink-decoder',
description: 'Decode Outlook SafeLink links',
keywords: ['outlook', 'safelink', 'decoder'],
component: () => import('./safelink-decoder.vue'),
icon: Mailbox,
createdAt: new Date('2024-03-11'),
});
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest';
import { decodeSafeLinksURL } from './safelink-decoder.service';
describe('safelink-decoder', () => {
describe('decodeSafeLinksURL', () => {
describe('decode outlook safelink urls', () => {
it('should decode basic safelink urls', () => {
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0'))
.toBe('https://www.google.com/search?q=safelink&rlz=1');
});
it('should decode encoded safelink urls', () => {
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&amp;data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&amp;sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&amp;reserved=0'))
.toBe('https://www.google.com/search?q=safelink&rlz=1');
});
it('throw on not outlook safelink urls', () => {
expect(() => decodeSafeLinksURL('https://google.com'))
.toThrow('Invalid SafeLinks URL provided');
});
});
});
});
@@ -0,0 +1,7 @@
export function decodeSafeLinksURL(safeLinksUrl: string) {
if (!safeLinksUrl.match(/\.safelinks\.protection\.outlook\.com/)) {
throw new Error('Invalid SafeLinks URL provided');
}
return new URL(safeLinksUrl).searchParams.get('url');
}
@@ -0,0 +1,32 @@
<script setup lang="ts">
import { decodeSafeLinksURL } from './safelink-decoder.service';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const inputSafeLinkUrl = ref('');
const outputDecodedUrl = computed(() => {
try {
return decodeSafeLinksURL(inputSafeLinkUrl.value);
}
catch (e: any) {
return e.toString();
}
});
</script>
<template>
<div>
<c-input-text
v-model:value="inputSafeLinkUrl"
raw-text
placeholder="Your input Outlook SafeLink Url..."
autofocus
label="Your input Outlook SafeLink Url:"
/>
<n-divider />
<n-form-item label="Output decoded URL:">
<TextareaCopyable :value="outputDecodedUrl" :word-wrap="true" />
</n-form-item>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
import { Ad } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'UTM Url Generator',
path: '/utm-url-generator',
description: 'Generate an URL with utm_ parameters',
keywords: ['utm', 'url', 'generator'],
component: () => import('./utm-url-generator.vue'),
icon: Ad,
createdAt: new Date('2024-03-15'),
});
@@ -0,0 +1,147 @@
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { useValidation } from '@/composable/validation';
const url = useStorage('utm-generator:url', '');
const utmSource = useStorage('utm-generator:source', '');
const utmMedium = useStorage('utm-generator:medium', '');
const utmCampaign = useStorage('utm-generator:campaign', '');
const utmContent = useStorage('utm-generator:content', '');
const utmTerm = useStorage('utm-generator:term', '');
const utmifiedUrl = computed(() => {
try {
const utmUrl = new URL(url.value);
utmUrl.searchParams.set('utm_source', utmSource.value);
utmUrl.searchParams.set('utm_medium', utmMedium.value);
utmUrl.searchParams.set('utm_campaign', utmCampaign.value);
if (utmContent.value) {
utmUrl.searchParams.set('utm_content', utmContent.value);
}
if (utmContent.value) {
utmUrl.searchParams.set('utm_term', utmTerm.value);
}
return utmUrl.href;
}
catch {
return '# invalid inputs';
}
});
const urlValidation = useValidation({
source: url,
rules: [
{
message: 'Invalid url string',
validator: (value) => {
try {
const _ = (new URL(value));
return true;
}
catch {
return false;
}
},
},
],
});
const utmMediumValidation = useValidation({
source: utmMedium,
rules: [
{
message: 'UTM Medium is required',
validator: value => value !== '',
},
],
});
const utmSourceValidation = useValidation({
source: utmSource,
rules: [
{
message: 'UTM Source is required',
validator: value => value !== '',
},
],
});
const utmCampaignValidation = useValidation({
source: utmCampaign,
rules: [
{
message: 'UTM Campaign is required',
validator: value => value !== '',
},
],
});
const { copy } = useCopy({ source: utmifiedUrl, text: 'UTMified url copied.' });
</script>
<template>
<div>
<n-p>
For more info about UTM, see <n-a href="https://en.wikipedia.org/wiki/UTM_parameters" target="_blank" rel="noopener noreferrer">
UTM Parameters
</n-a>
</n-p>
<c-input-text
v-model:value="url"
label="Website url"
placeholder="Put your website url here..."
clearable
mb-2
:validation="urlValidation"
/>
<c-input-text
v-model:value="utmSource"
label="UTM Source (Identifies which site sent the traffic)"
placeholder="Put your UTM Source here..."
clearable
mb-2
:validation="utmSourceValidation"
/>
<c-input-text
v-model:value="utmMedium"
label="UTM Medium (Identifies what type of link was used)"
placeholder="Put your UTM Medium here..."
clearable
mb-2
:validation="utmMediumValidation"
/>
<c-input-text
v-model:value="utmCampaign"
label="UTM Campaign (Identifies a specific product promotion or strategic campaign)"
placeholder="Put your UTM Campaign here..."
clearable
mb-2
:validation="utmCampaignValidation"
/>
<c-input-text
v-model:value="utmContent"
label="UTM Content (Identifies search terms)"
placeholder="Put your UTM Content here..."
clearable
mb-2
/>
<c-input-text
v-model:value="utmTerm"
label="UTM Term (Identifies what specifically was clicked to bring the user to the site)"
placeholder="Put your UTM Term here..."
clearable
mb-2
/>
<div v-if="utmifiedUrl">
<div mb-2>
Your url with UTM parameters added
</div>
<c-card>
{{ utmifiedUrl }}
</c-card>
<div mt-3 flex justify-center>
<c-button autofocus @click="copy()">
Copy url
</c-button>
</div>
</div>
</div>
</template>