|
|
@@ -80,8 +80,9 @@ import { ringtone } from '@kit.RingtoneKit';
|
|
|
import { BreakpointType, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
|
|
|
import { resourceManager } from '@kit.LocalizationKit';
|
|
|
import { deviceInfo } from '@kit.BasicServicesKit';
|
|
|
-import { ensureSmbFileCached } from '../common/network/SmbFileCache';
|
|
|
-import { ensureFtpFileCached } from '../common/network/FtpFileCache';
|
|
|
+import { RemoteCacheManager } from '../common/network/RemoteCacheManager';
|
|
|
+import '../common/network/RemoteCacheRegistry';
|
|
|
+import { RemoteCacheType } from '../common/network/RemoteSongCache';
|
|
|
import { findWebDavCacheIfExists, triggerWebDavCacheDownload } from '../common/network/WebDavFileCache';
|
|
|
import { navidromeApi } from '../common/network/NavidromeApi';
|
|
|
|
|
|
@@ -521,7 +522,10 @@ async function setVideoUrlForSong(song: VideoItem, options?: MetadataExtractionO
|
|
|
throw new Error('SMB账号不可用');
|
|
|
}
|
|
|
const relativePath = extractSmbRelativePath(song, account.smbShare);
|
|
|
- const cachedPath = await ensureSmbFileCached(account, relativePath);
|
|
|
+ const cachedPath = await RemoteCacheManager.ensureCached(RemoteCacheType.SMB, {
|
|
|
+ account,
|
|
|
+ remotePath: relativePath
|
|
|
+ });
|
|
|
Logger.info(TAG, `SMB 缓存路径: ${cachedPath}`);
|
|
|
scheduleMetadataExtractionFromCache(song, cachedPath, metadataOptions);
|
|
|
return cachedPath;
|
|
|
@@ -540,7 +544,10 @@ async function setVideoUrlForSong(song: VideoItem, options?: MetadataExtractionO
|
|
|
throw new Error('FTP账号不可用');
|
|
|
}
|
|
|
const relativePath = extractFtpRelativePath(song);
|
|
|
- const cachedPath = await ensureFtpFileCached(account, relativePath);
|
|
|
+ const cachedPath = await RemoteCacheManager.ensureCached(RemoteCacheType.FTP, {
|
|
|
+ account,
|
|
|
+ remotePath: relativePath
|
|
|
+ });
|
|
|
Logger.info(TAG, `FTP 缓存路径: ${cachedPath}`);
|
|
|
scheduleMetadataExtractionFromCache(song, cachedPath, metadataOptions);
|
|
|
return cachedPath;
|
|
|
@@ -1504,27 +1511,34 @@ export struct LocalMusic {
|
|
|
|
|
|
private applyMetadataToCollections(filePath: string, payload: WorkerMetadataPayload): void {
|
|
|
const targets: Array<VideoItem> = [];
|
|
|
+ let mainListUpdated = false;
|
|
|
+ let playlistUpdated = false;
|
|
|
if (this.currentSong && this.currentSong.filePath === filePath) {
|
|
|
targets.push(this.currentSong);
|
|
|
}
|
|
|
- const collectFromList = (list?: Array<VideoItem>) => {
|
|
|
+ const collectFromList = (list?: Array<VideoItem>, markUpdated?: () => void) => {
|
|
|
if (!list || list.length === 0) {
|
|
|
return;
|
|
|
}
|
|
|
const found = Utility.getItemByFilePath(list, filePath);
|
|
|
if (found) {
|
|
|
+ markUpdated?.();
|
|
|
targets.push(found);
|
|
|
}
|
|
|
};
|
|
|
- collectFromList(this.songList);
|
|
|
- collectFromList(this.videoLocalList);
|
|
|
+ collectFromList(this.videoLocalList, () => {
|
|
|
+ mainListUpdated = true;
|
|
|
+ });
|
|
|
+ collectFromList(this.songList, () => {
|
|
|
+ playlistUpdated = true;
|
|
|
+ });
|
|
|
collectFromList(this.historyList);
|
|
|
collectFromList(this.favList);
|
|
|
const remoteManager = RemoteDriveManager.getInstance();
|
|
|
collectFromList(remoteManager.webDavSongs);
|
|
|
|
|
|
const updated = new Set<VideoItem>();
|
|
|
- const webDavUpdates: Map<string, WebDavMetadataUpdatePayload> = new Map();
|
|
|
+ const remoteMetadataUpdates: Map<string, WebDavMetadataUpdatePayload> = new Map();
|
|
|
for (let i = 0; i < targets.length; i++) {
|
|
|
const target = targets[i];
|
|
|
if (!target || updated.has(target)) {
|
|
|
@@ -1532,8 +1546,8 @@ export struct LocalMusic {
|
|
|
}
|
|
|
updated.add(target);
|
|
|
this.mergeVideoItemWithPayload(target, payload);
|
|
|
- if (target.type === CommonConstants.TYPE_WEBDAV && StrUtil.isNotEmpty(target.filePath)) {
|
|
|
- webDavUpdates.set(target.filePath, {
|
|
|
+ if (isRemoteCloudType(target.type) && StrUtil.isNotEmpty(target.filePath)) {
|
|
|
+ remoteMetadataUpdates.set(target.filePath, {
|
|
|
filePath: target.filePath,
|
|
|
pixelMapPath: target.pixelMapPath,
|
|
|
name: target.name,
|
|
|
@@ -1567,10 +1581,12 @@ export struct LocalMusic {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (webDavUpdates.size > 0) {
|
|
|
+ if (remoteMetadataUpdates.size > 0) {
|
|
|
const eventUpdate: emitter.InnerEvent = { eventId: EventConstants.EVENT_WEBDAV_METADATA_UPDATED };
|
|
|
- emitter.emit(eventUpdate, { data: Array.from(webDavUpdates.values()) });
|
|
|
+ emitter.emit(eventUpdate, { data: Array.from(remoteMetadataUpdates.values()) });
|
|
|
}
|
|
|
+
|
|
|
+ this.refreshLazyListViews(mainListUpdated, playlistUpdated);
|
|
|
}
|
|
|
|
|
|
private handleEditMusicResult(result: WorkerEditMusicResult): void {
|
|
|
@@ -1779,15 +1795,32 @@ export struct LocalMusic {
|
|
|
return path.substring(0, lastSlash);
|
|
|
}
|
|
|
|
|
|
+ private resolveRemoteStoragePath(target: VideoItem): string | null {
|
|
|
+ if (!target || !isRemoteCloudType(target.type)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (isWebDavType(target.type)) {
|
|
|
+ const storagePath = target.remote_rel_path || WebDavUrlUtil.toStoragePath(target.filePath);
|
|
|
+ if (storagePath) {
|
|
|
+ target.remote_rel_path = storagePath;
|
|
|
+ return storagePath;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (target.remote_rel_path && target.remote_rel_path.length > 0) {
|
|
|
+ return target.remote_rel_path;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private async persistRemoteMetadataToDb(target: VideoItem): Promise<void> {
|
|
|
- if (!this.context || !target || !isWebDavType(target.type)) {
|
|
|
+ if (!this.context || !target || !isRemoteCloudType(target.type)) {
|
|
|
return;
|
|
|
}
|
|
|
- const storagePath = target.remote_rel_path || WebDavUrlUtil.toStoragePath(target.filePath);
|
|
|
+ const storagePath = this.resolveRemoteStoragePath(target);
|
|
|
if (!storagePath) {
|
|
|
return;
|
|
|
}
|
|
|
- target.remote_rel_path = target.remote_rel_path || storagePath;
|
|
|
const table = new MediaTable(this.context);
|
|
|
await new Promise<void>((resolve) => {
|
|
|
table.getRdbStore(this.context as Context, () => resolve());
|
|
|
@@ -8040,6 +8073,19 @@ export struct LocalMusic {
|
|
|
this.listRefreshKey++
|
|
|
}
|
|
|
|
|
|
+ private refreshLazyListViews(mainListUpdated: boolean, playlistUpdated: boolean): void {
|
|
|
+ if (!mainListUpdated && !playlistUpdated) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.listRefreshKey++;
|
|
|
+ if (mainListUpdated) {
|
|
|
+ this.dataSource.notifyDataReload();
|
|
|
+ }
|
|
|
+ if (playlistUpdated) {
|
|
|
+ this.sonDataSource.notifyDataReload();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Builder
|
|
|
detailSheet(item:VideoItem) {
|
|
|
Scroll() {
|