mirror of
https://github.com/penxio/penx.git
synced 2026-04-19 03:03:06 -04:00
27 lines
639 B
TypeScript
27 lines
639 B
TypeScript
import axios from 'axios'
|
|
import { ContentHandler } from '../content-handler'
|
|
|
|
export class TDotCoHandler extends ContentHandler {
|
|
constructor() {
|
|
super()
|
|
this.name = 't.co'
|
|
}
|
|
|
|
shouldResolve(url: string): boolean {
|
|
const T_DOT_CO_URL_MATCH = /^https:\/\/(?:www\.)?t\.co\/.*$/
|
|
return T_DOT_CO_URL_MATCH.test(url)
|
|
}
|
|
|
|
async resolve(url: string) {
|
|
return axios
|
|
.get(url, { maxRedirects: 0, validateStatus: null })
|
|
.then((res) => {
|
|
return new URL(res.headers.location).href
|
|
})
|
|
.catch((err) => {
|
|
console.warn('err with t.co url', err)
|
|
return undefined
|
|
})
|
|
}
|
|
}
|