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

@@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import {BASE} from '@/services/api.ts';
import { ref, computed, watch, onMounted, onUnmounted } from 'vue' import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
const BASE_SPEED_UNITS = { const BASE_SPEED_UNITS = {
@@ -241,7 +242,7 @@ const navball = computed(() => {
<!-- Photo --> <!-- Photo -->
<div v-if="photoUrl" class="ap-photo-wrap"> <div v-if="photoUrl" class="ap-photo-wrap">
<img class="ap-photo" :class="{ 'ap-photo--sil': isSil }" :src="'/api/adsb-image/' + plane.icao" :alt="callsign" /> <img class="ap-photo" :class="{ 'ap-photo--sil': isSil }" :src="BASE + '/api/adsb-image/' + plane.icao" :alt="callsign" />
</div> </div>
<!-- Body --> <!-- Body -->

View File

@@ -88,7 +88,17 @@ export async function getAIS() {
return aisCache; return aisCache;
} }
export function getAISImage(mmsi) { export async function getAISImage(mmsi) {
return fetch(`https://www.marinetraffic.com/getAssetDefaultPhoto/?photo_size=800&asset_type_id=0&asset_id=${mmsi}`, const res = await fetch(`https://www.vesselfinder.com/vessels/details/${mmsi}`, {
{headers: {'User-Agent': 'Mozilla/5.0', 'Referer': 'https://www.marinetraffic.com/'}}).then(resp => resp.blob()); 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());
} }

View File

@@ -165,6 +165,7 @@ app.get('/api/adsb/:icao', asyncHandler(async (req, res) => res.json(await getAD
app.get('/api/ais', asyncHandler(async (req, res) => res.json(await getAIS()))); app.get('/api/ais', asyncHandler(async (req, res) => res.json(await getAIS())));
app.get('/api/ais-image/:mmsi', asyncHandler(async (req, res) => { app.get('/api/ais-image/:mmsi', asyncHandler(async (req, res) => {
const blob = await getAISImage(req.params.mmsi); const blob = await getAISImage(req.params.mmsi);
if (!blob) return res.status(404).send('No image found');
const buffer = Buffer.from(await blob.arrayBuffer()); const buffer = Buffer.from(await blob.arrayBuffer());
res.contentType(blob.type).send(buffer); res.contentType(blob.type).send(buffer);
})); }));