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 
16 #ifndef OHOS_FILEMGMT_CLOUD_SYNC_ASSET_MANAGER_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_ASSET_MANAGER_H
18 
19 #include <functional>
20 #include <string>
21 
22 namespace OHOS::FileManagement::CloudSync {
23 struct AssetInfo {
24     std::string uri;
25     std::string recordType;
26     std::string recordId;
27     std::string fieldKey;
28     std::string assetName;
29 };
30 
31 class CloudSyncAssetManager {
32 public:
33     using ResultCallback = std::function<void(const std::string &, int32_t)>;
34     static CloudSyncAssetManager &GetInstance();
35     /**
36      * @brief 接口触发文件上传
37      *
38      * @param userId 用户Id
39      * @param request 请求
40      * @param result 结果
41      * @return int32_t 同步返回执行结果
42      */
43     virtual int32_t UploadAsset(const int32_t userId, const std::string &request, std::string &result) = 0;
44     /**
45      * @brief 接口触发文件下载
46      *
47      * @param userId 用户Id
48      * @param bundleName 应用包名
49      * @param assetInfo 下载文件信息
50      * @return int32_t 同步返回执行结果
51      */
52     virtual int32_t DownloadFile(const int32_t userId, const std::string &bundleName, AssetInfo &assetInfo) = 0;
53     /**
54      * @brief 接口触发文件下载
55      *
56      * @param userId 用户Id
57      * @param bundleName 应用包名
58      * @param assetInfo 下载文件信息
59      * @return int32_t 同步返回执行结果
60      */
61     virtual int32_t DownloadFile(const int32_t userId,
62                                  const std::string &bundleName,
63                                  const std::string &networkId,
64                                  AssetInfo &assetInfo,
65                                  ResultCallback resultCallback) = 0;
66     /**
67      * @brief 接口触发批量文件下载
68      *
69      * @param userId 用户Id
70      * @param bundleName 应用包名
71      * @param assetInfo 下载批量文件信息
72      * @param assetResultMap 同步返回执行结果
73      * @return int32_t 同步返回执行总结果
74      */
75     virtual int32_t DownloadFiles(const int32_t userId,
76                                   const std::string &bundleName,
77                                   const std::vector<AssetInfo> &assetInfo,
78                                   std::vector<bool> &assetResultMap) = 0;
79     /**
80      * @brief 接口触发附件删除
81      *
82      * @param userId 用户Id
83      * @param uri 用户uri
84      * @return int32_t 同步返回执行结果
85      */
86     virtual int32_t DeleteAsset(const int32_t userId, const std::string &uri) = 0;
87 };
88 } // namespace OHOS::FileManagement::CloudSync
89 
90 #endif // OHOS_FILEMGMT_CLOUD_SYNC_ASSET_MANAGER_H
91