Files
penx/apps/extension/lib/content-handler/websites/t-dot-co-handler.ts
2025-05-16 18:30:02 +08:00

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
})
}
}