1 /* 2 * Copyright (C) 2023 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 enum { 29 API10_PHOTO_URI, 30 API10_PHOTOALBUM_URI, 31 API10_AUDIO_URI, 32 API9_URI, 33 }; 34 35 const std::string MEDIA_FILE_URI_EMPTY = "empty"; 36 class MediaFileUri : public OHOS::Uri { 37 std::string networkId_ { MEDIA_FILE_URI_EMPTY }; 38 std::string fileId_ { MEDIA_FILE_URI_EMPTY }; 39 std::unordered_map<std::string, std::string> queryMap_; 40 std::string MediaFileUriConstruct(MediaType mediaType, const std::string &networkId, const std::string &fileId, 41 const int32_t &apiVersion, const std::string &extrUri); 42 int uriType_; 43 void ParseUri(const std::string& uri); 44 public: MediaFileUri(const std::string & uriStr)45 explicit MediaFileUri(const std::string &uriStr) : Uri(uriStr) {ParseUri(uriStr);} 46 explicit MediaFileUri(MediaType mediaType, 47 const std::string &fileId, 48 const std::string &networkId = "", 49 const int32_t &apiVersion = MEDIA_API_VERSION_V9, Uri(MediaFileUriConstruct (mediaType,fileId,networkId,apiVersion,extrUri))50 const std::string &extrUri = "") : Uri( 51 MediaFileUriConstruct(mediaType, fileId, networkId, apiVersion, extrUri)) {} 52 ~MediaFileUri() = default; 53 54 std::string GetNetworkId(); 55 std::string GetFileId(); 56 std::string GetFilePath(); 57 std::unordered_map<std::string, std::string> &GetQueryKeys(); 58 std::string GetTableName(); 59 bool IsValid(); 60 bool IsApi10(); 61 int GetUriType(); 62 static MediaType GetMediaTypeFromUri(const std::string &uri); 63 static std::string GetPathFirstDentry(Uri &uri); 64 static std::string GetPathSecondDentry(Uri &uri); 65 static void RemoveAllFragment(std::string &uri); 66 static std::string GetMediaTypeUri(MediaType mediaType, const int32_t &apiVersion); 67 static std::string GetPhotoId(const std::string &uri); 68 }; 69 } // namespace Media 70 } // namespace OHOS 71 72 #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_FILE_URI_H_ 73