diff --git a/README.md b/README.md index 5fd593a..af41e1d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -68,6 +68,9 @@ Url shortner supports the following providers. | rb.gy | ✔️ | | 4h.net | ✔️ | | vurl.com | ✔️ | +| pwn.se | ✔️ | +| haha.se | ✔️ | +| cya.se | ✔️ | ## Contributing diff --git a/src/index.ts b/src/index.ts index e93cfd5..651f051 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; /** * @@ -46,7 +46,7 @@ interface IProviders { * @param {string} longUrl * @return {*} {IResponse} */ -function responseMap(response: Record, longUrl: string): IResponse { +function responseMap(response: Record, longUrl: string,provider: providers): IResponse { const responseType = response.headers['content-type'].split(';')[0]; if (!['text/plain', 'text/html'].includes(responseType)) { if (response.data?.url) { @@ -62,7 +62,19 @@ function responseMap(response: Record, 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 }; + + + + } @@ -97,13 +109,26 @@ const ValidProviders: Record = { 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', @@ -145,7 +170,7 @@ export default async ( longUrl, option, ); - return responseMap(response, longUrl); + return responseMap(response, longUrl, option.provider); } catch (error) { throw error; } diff --git a/test/index.test.ts b/test/index.test.ts index fd667d3..0ee2282 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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\//); + }); });