1 /* 2 * Copyright (C) 2023-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 #ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_FILE_URI_H_ 17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_FILE_URI_H_ 18 19 #include <string> 20 #include <unordered_map> 21 22 #include "medialibrary_db_const.h" 23 #include "uri.h" 24 #include "userfile_manager_types.h" 25 26 namespace OHOS { 27 namespace Media { 28 #define EXPORT __attribute__ ((visibility ("default"))) 29 enum { 30 API10_PHOTO_URI, 31 API10_PHOTOALBUM_URI, 32 API10_AUDIO_URI, 33 API9_URI, 34 API10_ANALYSISALBUM_URI, 35 }; 36 37 const std::string MEDIA_FILE_URI_EMPTY = "empty"; 38 class MediaFileUri : public OHOS::Uri { 39 std::string networkId_ { MEDIA_FILE_URI_EMPTY }; 40 std::string fileId_ { MEDIA_FILE_URI_EMPTY }; 41 std::unordered_map<std::string, std::string> queryMap_; 42 std::string MediaFileUriConstruct(MediaType mediaType, const std::string &networkId, const std::string &fileId, 43 const int32_t &apiVersion, const std::string &extrUri); 44 int uriType_ {0}; 45 void ParseUri(const std::string& uri); 46 public: MediaFileUri(const std::string & uriStr)47 EXPORT explicit MediaFileUri(const std::string &uriStr) : Uri(uriStr) {ParseUri(uriStr);} 48 EXPORT explicit MediaFileUri(MediaType mediaType, 49 const std::string &fileId, 50 const std::string &networkId = "", 51 const int32_t &apiVersion = MEDIA_API_VERSION_V9, 52 const std::string &extrUri = "") : Uri( 53 MediaFileUriConstruct(mediaType, fileId, networkId, apiVersion, extrUri)) {} 54 EXPORT ~MediaFileUri() = default; 55 56 EXPORT std::string GetNetworkId(); 57 EXPORT std::string GetFileId(); 58 EXPORT std::string GetFilePath(); 59 EXPORT std::unordered_map<std::string, std::string> &GetQueryKeys(); 60 EXPORT std::string GetTableName(); 61 EXPORT bool IsValid(); 62 EXPORT bool IsApi10(); 63 EXPORT int GetUriType(); 64 EXPORT static MediaType GetMediaTypeFromUri(const std::string &uri); 65 EXPORT static std::string GetPathFirstDentry(Uri &uri); 66 EXPORT static std::string GetPathSecondDentry(Uri &uri); 67 EXPORT static void RemoveAllFragment(std::string &uri); 68 EXPORT static std::string GetMediaTypeUri(MediaType mediaType, const int32_t &apiVersion); 69 EXPORT static std::string GetPhotoId(const std::string &uri); 70 EXPORT static void GetTimeIdFromUri(const std::vector<std::string> &uriBatch, 71 std::vector<std::string> &timeIdBatch); 72 EXPORT static void GetTimeIdFromUri(const std::vector<std::string> &uriBatch, 73 std::vector<std::string> &timeIdBatch, int32_t &start, int32_t &count); 74 EXPORT static int32_t CreateAssetBucket(int32_t fileId, int32_t &bucketNum); 75 EXPORT static std::string GetPathFromUri(const std::string &uri, bool isPhoto); 76 }; 77 } // namespace Media 78 } // namespace OHOS 79 80 #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_FILE_URI_H_ 81