• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #define MLOG_TAG "Media_Cloud_Service"
17 
18 #include "cloud_media_data_service_processor.h"
19 
20 #include "cloud_media_sync_utils.h"
21 #include "cloud_media_file_utils.h"
22 #include "photos_po.h"
23 #include "photos_dto.h"
24 #include "media_log.h"
25 
26 namespace OHOS::Media::CloudSync {
GetPhotosDto(const std::vector<PhotosPo> & photosPos,std::vector<PhotosDto> & photosDtos)27 void CloudMediaDataServiceProcessor::GetPhotosDto(
28     const std::vector<PhotosPo> &photosPos, std::vector<PhotosDto> &photosDtos)
29 {
30     std::string path;
31     std::string filePath;
32     std::string fileName;
33     bool ret = false;
34     for (auto &photo : photosPos) {
35         PhotosDto photosDto;
36         path = photo.data.value_or("");
37         if (path.empty()) {
38             MEDIA_ERR_LOG("photo data is empty, Photos: %{public}s", photo.ToString().c_str());
39             continue;
40         }
41         ret = CloudMediaFileUtils::GetParentPathAndFilename(path, filePath, fileName);
42         CHECK_AND_CONTINUE_ERR_LOG(ret, "GetParentPathAndFilename failed, path: %{public}s", path.c_str());
43         photosDto.fileId = photo.fileId.value_or(0);
44         photosDto.cloudId = photo.cloudId.value_or("");
45         photosDto.data = filePath;
46         photosDto.mediaType = photo.mediaType.value_or(1);
47         photosDto.size = photo.size.value_or(0);
48         photosDto.path = path;
49         photosDto.modifiedTime = photo.editTime.value_or(0);
50         photosDto.fileName = fileName;
51         photosDto.originalCloudId = photo.originalAssetCloudId.value_or("");
52         photosDtos.push_back(photosDto);
53     }
54     return;
55 }
56 
GetPhotosDtoOfVideoCache(const std::vector<PhotosPo> & photosPos,std::vector<PhotosDto> & photosDtos)57 void CloudMediaDataServiceProcessor::GetPhotosDtoOfVideoCache(
58     const std::vector<PhotosPo> &photosPos, std::vector<PhotosDto> &photosDtos)
59 {
60     std::string filePath;
61     std::string fileName;
62     std::string path;
63     for (const auto &photoPos : photosPos) {
64         path = photoPos.data.value_or("");
65         PhotosDto photosDto;
66         CHECK_AND_CONTINUE_ERR_LOG(CloudMediaFileUtils::GetParentPathAndFilename(path, filePath, fileName),
67             "GetParentPathAndFilename failed, path: %{public}s",
68             path.c_str());
69         photosDto.fileId = photoPos.fileId.value_or(0);
70         photosDto.cloudId = photoPos.cloudId.value_or("");
71         photosDto.data = filePath;
72         photosDto.mediaType = photoPos.mediaType.value_or(0);
73         photosDto.size = photoPos.size.value_or(0);
74         photosDto.path = photoPos.data.value_or("");
75         photosDto.modifiedTime = photoPos.editTime.value_or(0);
76         photosDto.fileName = fileName;
77         photosDto.originalCloudId = photoPos.originalAssetCloudId.value_or("");
78         photosDtos.push_back(photosDto);
79     }
80     return;
81 }
82 }  // namespace OHOS::Media::CloudSync