From d5697c4e20dd6538951c4932820bee7c39c81bb8 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 4 Jul 2026 22:28:05 -0400 Subject: [PATCH] AIS images --- server/src/ais.mjs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/src/ais.mjs b/server/src/ais.mjs index 26211f6..571c410 100644 --- a/server/src/ais.mjs +++ b/server/src/ais.mjs @@ -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' } }) const html = await res.text() - const match = html.match(/]+src=["']([^"']+)["']/) - if (!match) throw new Error('No image found') + const match = html.match(/]+class=["'][^"']*main-photo[^"']*["'][^>]*>/) + if (!match) throw new Error('No main-photo image found') - let imgUrl = match[1] - if(imgUrl.startsWith('/')) imgUrl = `https://www.vesselfinder.com${imgUrl}` + const srcMatch = match[0].match(/src=["']([^"']+)["']/) + 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, { 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()) }