AIS images
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import {BASE} from '@/services/api.ts';
|
||||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||
|
||||
const BASE_SPEED_UNITS = {
|
||||
@@ -241,7 +242,7 @@ const navball = computed(() => {
|
||||
|
||||
<!-- Photo -->
|
||||
<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>
|
||||
|
||||
<!-- Body -->
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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-image/:mmsi', asyncHandler(async (req, res) => {
|
||||
const blob = await getAISImage(req.params.mmsi);
|
||||
if (!blob) return res.status(404).send('No image found');
|
||||
const buffer = Buffer.from(await blob.arrayBuffer());
|
||||
res.contentType(blob.type).send(buffer);
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user