AIS images

This commit is contained in:
2026-07-04 22:28:05 -04:00
parent 7e8ea62f64
commit d5697c4e20

View File

@@ -93,12 +93,15 @@ export async function getAISImage(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' } 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 html = await res.text()
const match = html.match(/<img[^>]+src=["']([^"']+)["']/) const match = html.match(/<img[^>]+class=["'][^"']*main-photo[^"']*["'][^>]*>/)
if (!match) throw new Error('No image found') if (!match) throw new Error('No main-photo image found')
let imgUrl = match[1] const srcMatch = match[0].match(/src=["']([^"']+)["']/)
if(imgUrl.startsWith('/')) imgUrl = `https://www.vesselfinder.com${imgUrl}` if (!srcMatch) throw new Error('No src found on main-photo image')
let imgUrl = srcMatch[1]
if (imgUrl.startsWith('/')) imgUrl = `https://www.vesselfinder.com${imgUrl}`
return fetch(imgUrl, { return fetch(imgUrl, {
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' } 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' }
}).then(resp => resp.blob()); }).then(resp => resp.blob())
} }