Skip to content

Commit

Permalink
feat: add haha,cya,pwm
Browse files Browse the repository at this point in the history
  • Loading branch information
mohantakeo committed Aug 26, 2022
1 parent fb1e540 commit 795ea82
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Type: `object`
Type: `string`

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

##### timeout

Expand All @@ -68,6 +68,9 @@ Url shortner supports the following providers.
| rb.gy | ✔️ |
| 4h.net | ✔️ |
| vurl.com | ✔️ |
| pwn.se | ✔️ |
| haha.se | ✔️ |
| cya.se | ✔️ |

## Contributing

Expand Down
37 changes: 31 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios, { AxiosError } from 'axios';
import axios from 'axios';



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

/**
*
Expand Down Expand Up @@ -46,7 +46,7 @@ interface IProviders {
* @param {string} longUrl
* @return {*} {IResponse}
*/
function responseMap(response: Record<any, any>, longUrl: string): IResponse {
function responseMap(response: Record<any, any>, longUrl: string,provider: providers): IResponse {
const responseType = response.headers['content-type'].split(';')[0];
if (!['text/plain', 'text/html'].includes(responseType)) {
if (response.data?.url) {
Expand All @@ -62,7 +62,19 @@ function responseMap(response: Record<any, any>, longUrl: string): IResponse {
}
}

return { longUrl, shortUrl: response.data };
if(['haha','pwm','cya'].includes(provider)){


return { longUrl, shortUrl: `https://${provider}.se/${response.data}` };

}


return { longUrl, shortUrl: response.data };




}


Expand Down Expand Up @@ -97,13 +109,26 @@ const ValidProviders: Record<string, IProviders> = {
url: 'https://v.gd/create.php?format=simple&url=',
method: 'get',
},
haha: {
url: 'https://www.haha.se/lank.php?dataLank=',
method: 'get',
},

cya: {
url: 'https://www.haha.se/lank.php?dataLank=',
method: 'get',
},

pwm: {
url: 'https://www.haha.se/lank.php?dataLank=',
method: 'get',
},

'4hnet': {
url: 'https://4h.net/api/?url=',
method: 'get',
},


vurl: {
url: 'https://vurl.com/api.php?url=',
method: 'get',
Expand Down Expand Up @@ -145,7 +170,7 @@ export default async (
longUrl,
option,
);
return responseMap(response, longUrl);
return responseMap(response, longUrl, option.provider);
} catch (error) {
throw error;
}
Expand Down
17 changes: 17 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,21 @@ describe('should get a shortened url', () => {
const response = await minify(url, { provider: 'vurl' });
expect(response.shortUrl).toMatch(/^https:\/\/vurl.com\//);
});


it('should get shortened url with haha.se', async () => {
const response = await minify(url, { provider: 'haha' });
expect(response.shortUrl).toMatch(/^https:\/\/haha.se\//);
});

it('should get shortened url with pwm.se', async () => {
const response = await minify(url, { provider: 'pwm' });
expect(response.shortUrl).toMatch(/^https:\/\/pwm.se\//);
});


it('should get shortened url with cya.se', async () => {
const response = await minify(url, { provider: 'cya' });
expect(response.shortUrl).toMatch(/^https:\/\/cya.se\//);
});
});

0 comments on commit 795ea82

Please sign in to comment.