• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifndef OHOS_FILEMGMT_CLOUD_FILE_CACHE_NAPI_H
17 #define OHOS_FILEMGMT_CLOUD_FILE_CACHE_NAPI_H
18 
19 #include <mutex>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "download_callback_middle_napi.h"
24 #include "download_progress_napi.h"
25 #include "filemgmt_libn.h"
26 
27 namespace OHOS::FileManagement::CloudSync {
28 const std::string PROGRESS = "progress";
29 const std::string MULTI_PROGRESS = "batchDownload";
30 class CloudFileCacheNapi final : public LibN::NExporter {
31 public:
CloudFileCacheNapi(napi_env env,napi_value exports)32     CloudFileCacheNapi(napi_env env, napi_value exports) : NExporter(env, exports) {}
33     ~CloudFileCacheNapi() = default;
34 
35     bool Export() override;
36     bool ToExport(std::vector<napi_property_descriptor> props);
37     std::string GetClassName() override;
38     static napi_value Constructor(napi_env env, napi_callback_info info);
39     static napi_value StartFileCache(napi_env env, napi_callback_info info);
40     static napi_value StartBatchFileCache(napi_env env, napi_callback_info info);
41     static napi_value StopFileCache(napi_env env, napi_callback_info info);
42     static napi_value StopBatchFileCache(napi_env env, napi_callback_info info);
43     static napi_value On(napi_env env, napi_callback_info info);
44     static napi_value Off(napi_env env, napi_callback_info info);
45     static napi_value CleanCloudFileCache(napi_env env, napi_callback_info info);
46     static napi_value CleanFileCache(napi_env env, napi_callback_info info);
47 
48 private:
49     inline static std::string className_ = "CloudFileCache";
50 };
51 
52 class CloudFileCacheCallbackImplNapi : public CloudDlCallbackMiddleNapi {
53 public:
CloudFileCacheCallbackImplNapi(napi_env env)54     explicit CloudFileCacheCallbackImplNapi(napi_env env) : CloudDlCallbackMiddleNapi(env) {}
55     int32_t StartDownloadInner(const std::string &uri, int32_t fieldKey);
56     int32_t StartDownloadInner(const std::vector<std::string> &uriList, int64_t &downloadId, int32_t fieldKey);
57     int32_t StopDownloadInner(const std::string &uri, bool needClean);
58     int32_t StopDownloadInner(int64_t downloadId, bool needClean);
59 };
60 
61 struct FileCacheEntity {
62     std::unordered_map<std::string, std::shared_ptr<CloudFileCacheCallbackImplNapi>> registerMap;
63 };
64 } // namespace OHOS::FileManagement::CloudSync
65 #endif // OHOS_FILEMGMT_CLOUD_FILE_CACHE_NAPI_H