1 /* 2 * Copyright (C) 2024 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 16 #include "cloud_thumbnail_observer.h" 17 #include "medialibrary_rdb_utils.h" 18 19 using namespace std; 20 using namespace OHOS::DistributedKv; 21 using namespace OHOS::NativeRdb; 22 23 namespace OHOS { 24 namespace Media { 25 isFileIdValid(const std::string & fileId)26static inline bool isFileIdValid(const std::string& fileId) 27 { 28 for (char const& ch : fileId) { 29 if (std::isdigit(ch) == 0) { 30 return false; 31 } 32 } 33 return true; 34 } 35 OnChange(const ChangeInfo & changeInfo)36void CloudThumbnailObserver::OnChange(const ChangeInfo &changeInfo) 37 { 38 MediaLibraryRdbUtils::SetNeedRefreshAlbum(true); 39 if (changeInfo.changeType_ != ChangeType::INSERT) { 40 MEDIA_DEBUG_LOG("change type is %{public}d, not insert", changeInfo.changeType_); 41 return; 42 } 43 for (auto &uri : changeInfo.uris_) { 44 string uriString = uri.ToString(); 45 auto pos = uriString.find_last_of('/'); 46 if (pos == std::string::npos) { 47 continue; 48 } 49 string idString = uriString.substr(pos + 1); 50 if (idString.empty() || !isFileIdValid(idString)) { 51 MEDIA_DEBUG_LOG("cloud observer get no valid fileId and uri : %{public}s", uriString.c_str()); 52 continue; 53 } 54 ThumbnailService::GetInstance()->CreateAstcFromFileId(idString); 55 } 56 } 57 } // namespace Media 58 } // namespace OHOS