Skip to content

Commit 795ea82

Browse files
committed
feat: add haha,cya,pwm
1 parent fb1e540 commit 795ea82

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Type: `object`
4747
Type: `string`
4848

4949
Service to use for shortening links. Defaults to `isgd`
50-
Available providers: `'isgd'| 'cdpt'| 'vgd'| 'tinube'| '4hnet'`
50+
Available providers: `''isgd' | 'cdpt' | 'vgd' | '4hnet' | 'tinube' | 'rbgy' | 'vurl' | 'haha' | 'pwm' | 'cya'`
5151

5252
##### timeout
5353

@@ -68,6 +68,9 @@ Url shortner supports the following providers.
6868
| rb.gy | ✔️ |
6969
| 4h.net | ✔️ |
7070
| vurl.com | ✔️ |
71+
| pwn.se | ✔️ |
72+
| haha.se | ✔️ |
73+
| cya.se | ✔️ |
7174

7275
## Contributing
7376

src/index.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import axios, { AxiosError } from 'axios';
1+
import axios from 'axios';
22

33

44

5-
type providers = 'isgd' | 'cdpt' | 'vgd' | '4hnet' | 'tinube' | 'rbgy' | 'vurl';
5+
type providers = 'isgd' | 'cdpt' | 'vgd' | '4hnet' | 'tinube' | 'rbgy' | 'vurl' | 'haha' | 'pwm' | 'cya';
66

77
/**
88
*
@@ -46,7 +46,7 @@ interface IProviders {
4646
* @param {string} longUrl
4747
* @return {*} {IResponse}
4848
*/
49-
function responseMap(response: Record<any, any>, longUrl: string): IResponse {
49+
function responseMap(response: Record<any, any>, longUrl: string,provider: providers): IResponse {
5050
const responseType = response.headers['content-type'].split(';')[0];
5151
if (!['text/plain', 'text/html'].includes(responseType)) {
5252
if (response.data?.url) {
@@ -62,7 +62,19 @@ function responseMap(response: Record<any, any>, longUrl: string): IResponse {
6262
}
6363
}
6464

65-
return { longUrl, shortUrl: response.data };
65+
if(['haha','pwm','cya'].includes(provider)){
66+
67+
68+
return { longUrl, shortUrl: `https://${provider}.se/${response.data}` };
69+
70+
}
71+
72+
73+
return { longUrl, shortUrl: response.data };
74+
75+
76+
77+
6678
}
6779

6880

@@ -97,13 +109,26 @@ const ValidProviders: Record<string, IProviders> = {
97109
url: 'https://v.gd/create.php?format=simple&url=',
98110
method: 'get',
99111
},
112+
haha: {
113+
url: 'https://www.haha.se/lank.php?dataLank=',
114+
method: 'get',
115+
},
116+
117+
cya: {
118+
url: 'https://www.haha.se/lank.php?dataLank=',
119+
method: 'get',
120+
},
121+
122+
pwm: {
123+
url: 'https://www.haha.se/lank.php?dataLank=',
124+
method: 'get',
125+
},
100126

101127
'4hnet': {
102128
url: 'https://4h.net/api/?url=',
103129
method: 'get',
104130
},
105131

106-
107132
vurl: {
108133
url: 'https://vurl.com/api.php?url=',
109134
method: 'get',
@@ -145,7 +170,7 @@ export default async (
145170
longUrl,
146171
option,
147172
);
148-
return responseMap(response, longUrl);
173+
return responseMap(response, longUrl, option.provider);
149174
} catch (error) {
150175
throw error;
151176
}

test/index.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,21 @@ describe('should get a shortened url', () => {
3737
const response = await minify(url, { provider: 'vurl' });
3838
expect(response.shortUrl).toMatch(/^https:\/\/vurl.com\//);
3939
});
40+
41+
42+
it('should get shortened url with haha.se', async () => {
43+
const response = await minify(url, { provider: 'haha' });
44+
expect(response.shortUrl).toMatch(/^https:\/\/haha.se\//);
45+
});
46+
47+
it('should get shortened url with pwm.se', async () => {
48+
const response = await minify(url, { provider: 'pwm' });
49+
expect(response.shortUrl).toMatch(/^https:\/\/pwm.se\//);
50+
});
51+
52+
53+
it('should get shortened url with cya.se', async () => {
54+
const response = await minify(url, { provider: 'cya' });
55+
expect(response.shortUrl).toMatch(/^https:\/\/cya.se\//);
56+
});
4057
});

0 commit comments

Comments
 (0)