Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
86128f7573
|
|
@ -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
|
||||
|
|
@ -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([]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
@ -18,6 +19,10 @@ const getProvider = (): ShortLinking => {
|
|||
return new Kutt();
|
||||
}
|
||||
|
||||
if (process.env.LINK_DRIP_API_KEY) {
|
||||
return new LinkDrip();
|
||||
}
|
||||
|
||||
return new Empty();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue