AIS images

This commit is contained in:
2026-07-04 22:36:19 -04:00
parent a1c714847d
commit 43848c4b35

View File

@@ -89,15 +89,15 @@ export async function getAIS() {
}
export async function getAISImage(mmsi) {
console.log(`https://www.vesselfinder.com/vessels/details/${mmsi}`)
const res = await fetch(`https://www.vesselfinder.com/vessels/details/${mmsi}`, {
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36' }
})
const html = await res.text()
const match = html.match(/<img.+main-photo.+>/)
if (!match) throw new Error('No main-photo image found')
if(!match) return null;
const srcMatch = match[0].match(/src="(.+?)"/)
if (!srcMatch) throw new Error('No src found on main-photo image')
if (!srcMatch) return null;
let imgUrl = srcMatch[1]
if (imgUrl.startsWith('/')) imgUrl = `https://www.vesselfinder.com${imgUrl}`