AIS images

This commit is contained in:
2026-07-04 22:23:16 -04:00
parent be40d845bd
commit 7e8ea62f64
3 changed files with 16 additions and 4 deletions

View File

@@ -88,7 +88,17 @@ export async function getAIS() {
return aisCache;
}
export function getAISImage(mmsi) {
return fetch(`https://www.marinetraffic.com/getAssetDefaultPhoto/?photo_size=800&asset_type_id=0&asset_id=${mmsi}`,
{headers: {'User-Agent': 'Mozilla/5.0', 'Referer': 'https://www.marinetraffic.com/'}}).then(resp => resp.blob());
export async function getAISImage(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[^>]+src=["']([^"']+)["']/)
if (!match) throw new Error('No image found')
let imgUrl = match[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());
}