// lib/metadata/metadata_service.dart import 'metadata_model.dart'; import 'metadata_cache.dart'; class MetadataService { static final MetadataService _instance = MetadataService._internal(); factory MetadataService() => _instance; MetadataService._internal(); final MetadataCache _cache = MetadataCache(); /// 临时版本:不进行实际文件读取,只返回基于文件名的 fallback Future getMetadata({ required String url, required String fileName, required String fileId, bool forceRefresh = false, }) async { // 1. 检查缓存(如果有) if (!forceRefresh) { final cached = await _cache.get(fileId); if (cached != null && cached.isNotEmpty) { return cached; } } // 2. 暂时不读取文件,直接 fallback final fallback = _fallbackFromFileName(fileName); // 3. 缓存结果(即使 fallback 也缓存,避免频繁调用) if (fallback.isNotEmpty) { await _cache.put(fileId, fallback); } return fallback; } FinalMetadata _fallbackFromFileName(String fileName) { final dotIndex = fileName.lastIndexOf('.'); final title = dotIndex > 0 ? fileName.substring(0, dotIndex) : fileName; return FinalMetadata( title: title, artist: '未知艺术家', source: 'filename', ); } }