Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ POSTIZ_OAUTH_CLIENT_SECRET=""

# KUTT_API_KEY="" # Your Kutt.it API key
# KUTT_API_ENDPOINT="https://kutt.it/api/v2" # Your self-hosted Kutt API endpoint
# KUTT_SHORT_LINK_DOMAIN="kutt.it" # Your self-hosted Kutt domain
# KUTT_SHORT_LINK_DOMAIN="kutt.it" # Your self-hosted Kutt domain

# LINK_DRIP_API_KEY="" # Your LinkDrip API key
# LINK_DRIP_API_ENDPOINT="https://api.linkdrip.com/v1/" # Your self-hosted LinkDrip API endpoint
# LINK_DRIP_SHORT_LINK_DOMAIN="dripl.ink" # Your self-hosted LinkDrip domain
56 changes: 56 additions & 0 deletions libraries/nestjs-libraries/src/short-linking/providers/linkdrip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ShortLinking } from '@gitroom/nestjs-libraries/short-linking/short-linking.interface';

const LINK_DRIP_API_ENDPOINT =
process.env.LINK_DRIP_API_ENDPOINT || 'https://api.linkdrip.com/v1/';
const LINK_DRIP_SHORT_LINK_DOMAIN =
process.env.LINK_DRIP_SHORT_LINK_DOMAIN || 'dripl.ink';

const getOptions = () => ({
headers: {
Authorization: `Bearer ${process.env.LINK_DRIP_API_KEY}`,
'Content-Type': 'application/json',
},
});

export class LinkDrip implements ShortLinking {
shortLinkDomain = LINK_DRIP_SHORT_LINK_DOMAIN;

async linksStatistics(links: string[]) {
return Promise.resolve([]);
}

async convertLinkToShortLink(id: string, link: string) {
try {
const response = await fetch(`${LINK_DRIP_API_ENDPOINT}/create`, {
...getOptions(),
method: 'POST',
body: JSON.stringify({
target_url: link,
custom_domain: this.shortLinkDomain,
}),
});

if (!response.ok) {
throw new Error(
`Failed to create LinkDrip API short link with status: ${response.status}`
);
}

const data = await response.json();
return data.link;
} catch (error) {
throw new Error(`Failed to create LinkDrip short link: ${error}`);
}
}

async convertShortLinkToLink(shortLink: string) {
return '';
}

getAllLinksStatistics(
id: string,
page: number
): Promise<{ short: string; original: string; clicks: string }[]> {
return Promise.resolve([]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ShortLinking } from '@gitroom/nestjs-libraries/short-linking/short-link
import { Injectable } from '@nestjs/common';
import { ShortIo } from './providers/short.io';
import { Kutt } from './providers/kutt';
import { LinkDrip } from './providers/linkdrip';

const getProvider = (): ShortLinking => {
if (process.env.DUB_TOKEN) {
Expand All @@ -18,6 +19,10 @@ const getProvider = (): ShortLinking => {
return new Kutt();
}

if (process.env.LINK_DRIP_API_KEY) {
return new LinkDrip();
}

return new Empty();
};

Expand Down