9dfa06ffee
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Signed-off-by: cls_宁波本机 <908705107@qq.com>
117 lines
2.7 KiB
Dart
117 lines
2.7 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
enum MessageMediaKind { image, video }
|
|
|
|
@immutable
|
|
class ImetaEntry {
|
|
final String url;
|
|
final String? mimeType;
|
|
final String? dimensions;
|
|
final String? thumb;
|
|
final String? image;
|
|
final String? alt;
|
|
|
|
const ImetaEntry({
|
|
required this.url,
|
|
this.mimeType,
|
|
this.dimensions,
|
|
this.thumb,
|
|
this.image,
|
|
this.alt,
|
|
});
|
|
|
|
bool get isVideo => mimeType?.startsWith('video/') == true;
|
|
|
|
String? get posterUrl => image ?? thumb;
|
|
|
|
double? get aspectRatio {
|
|
final parts = dimensions?.split('x');
|
|
if (parts == null || parts.length != 2) return null;
|
|
final width = double.tryParse(parts[0]);
|
|
final height = double.tryParse(parts[1]);
|
|
if (width == null || height == null || width <= 0 || height <= 0) {
|
|
return null;
|
|
}
|
|
return width / height;
|
|
}
|
|
}
|
|
|
|
Map<String, ImetaEntry> parseImetaTags(List<List<String>> tags) {
|
|
final byUrl = <String, ImetaEntry>{};
|
|
for (final tag in tags) {
|
|
if (tag.isEmpty || tag.first != 'imeta') continue;
|
|
|
|
String? url;
|
|
String? mimeType;
|
|
String? dimensions;
|
|
String? thumb;
|
|
String? image;
|
|
String? alt;
|
|
|
|
for (final part in tag.skip(1)) {
|
|
final separator = part.indexOf(' ');
|
|
if (separator <= 0) continue;
|
|
final key = part.substring(0, separator);
|
|
final value = part.substring(separator + 1);
|
|
switch (key) {
|
|
case 'url':
|
|
url = value;
|
|
case 'm':
|
|
mimeType = value;
|
|
case 'dim':
|
|
dimensions = value;
|
|
case 'thumb':
|
|
thumb = value;
|
|
case 'image':
|
|
image = value;
|
|
case 'alt':
|
|
alt = value;
|
|
}
|
|
}
|
|
|
|
if (url == null || url.isEmpty) continue;
|
|
byUrl[url] = ImetaEntry(
|
|
url: url,
|
|
mimeType: mimeType,
|
|
dimensions: dimensions,
|
|
thumb: thumb,
|
|
image: image,
|
|
alt: alt,
|
|
);
|
|
}
|
|
return byUrl;
|
|
}
|
|
|
|
MessageMediaKind? classifyMediaUrl(String url, {ImetaEntry? imeta}) {
|
|
final mimeType = imeta?.mimeType;
|
|
if (mimeType != null) {
|
|
// An imeta MIME type is authoritative. The native video player chooses
|
|
// whether the device can decode the specific codec/container; rejecting
|
|
// every non-MP4 video here prevents it from even trying.
|
|
if (mimeType.startsWith('video/')) return MessageMediaKind.video;
|
|
if (mimeType.startsWith('image/')) return MessageMediaKind.image;
|
|
}
|
|
|
|
final path = (Uri.tryParse(url)?.path ?? url).toLowerCase();
|
|
if (path.endsWith(_mp4Extension)) {
|
|
return MessageMediaKind.video;
|
|
}
|
|
if (_imageExtensions.any(path.endsWith)) {
|
|
return MessageMediaKind.image;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
const _imageExtensions = {
|
|
'.jpg',
|
|
'.jpeg',
|
|
'.png',
|
|
'.webp',
|
|
'.bmp',
|
|
'.heic',
|
|
'.heif',
|
|
'.avif',
|
|
};
|
|
|
|
const _mp4Extension = '.mp4';
|