1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import MediaLib from '@ohos.multimedia.mediaLibrary'; 17import { Log } from '../utils/Log'; 18import mediaModel from '../model/MediaModel'; 19import { PeerDataItem } from '../data/PeerDataItem'; 20 21const TAG = "DistributedDataImpl" 22 23export class DistributedDataImpl { 24 async reloadAlbumItemData(): Promise<PeerDataItem[]> { 25 let peerDataItems = []; 26 let peers: MediaLib.PeerInfo[] = await mediaModel.getActivePeers(); 27 Log.info(TAG, `peers: ${JSON.stringify(peers)}`); 28 for (let i = 0;i < peers.length; i++) { 29 let selections: string = `${MediaLib.FileKey.MEDIA_TYPE} = ? or ${MediaLib.FileKey.MEDIA_TYPE} = ?`; 30 let selectionArgs: string[] = [MediaLib.MediaType.IMAGE.toString(), MediaLib.MediaType.VIDEO.toString()]; 31 let fetchOption: MediaLib.MediaFetchOptions = { 32 selections: selections, 33 selectionArgs: selectionArgs, 34 networkId: peers[i].networkId, 35 order: `date_added DESC` 36 }; 37 let item = await mediaModel.getAllCommonMediaItem(fetchOption, false); 38 if (item.counts == 0) { 39 continue; 40 } 41 peerDataItems.push(new PeerDataItem(item.counts, peers[i], item.fileAsset)); 42 } 43 44 return peerDataItems; 45 } 46}