• 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 #ifndef COLLABORATION_EDIT_CLOUD_DB_H
17 #define COLLABORATION_EDIT_CLOUD_DB_H
18 
19 #include <string>
20 #include <vector>
21 #include "napi_error_utils.h"
22 #include "napi/native_node_api.h"
23 #include "rd_type.h"
24 
25 namespace OHOS::CollaborationEdit {
26 
27 struct CloudParamsAdapterT {
28     int64_t cursor = 0;
29     uint64_t timestamp = 0;
30     std::string id;
31     std::vector<uint8_t> record;
32 };
33 
34 struct QueryConditionT {
35     Predicate predicate;
36     std::string fieldName;
37     std::string fieldValue_str;
38     int64_t fieldValue_num;
39 };
40 
41 struct AssetOpConfig {
42     std::string inputPath;
43 };
44 
45 class NapiCloudDb {
46 public:
47     NapiCloudDb();
48     ~NapiCloudDb();
49     int32_t BatchInsert(const std::vector<CloudParamsAdapterT> &cloudParamsAdapter);
50     int32_t Query(const std::vector<QueryConditionT> &queryConditions, std::vector<CloudParamsAdapterT> &extends);
51     int32_t DownloadAsset(const std::string equipId, const std::string path);
52     int32_t UploadAsset(const std::string path);
53     int32_t DeleteAsset(const std::string path);
54     int32_t DeleteLocalAsset(const std::string path);
55 
56     static void BatchInsertInner(napi_env env, napi_value js_cb, void *context, void *data);
57     static void QueryInner(napi_env env, napi_value js_cb, void *context, void *data);
58     static void DownloadAssetInner(napi_env env, napi_value js_cb, void *context, void *data);
59     static void UploadAssetInner(napi_env env, napi_value js_cb, void *context, void *data);
60     static void DeleteAssetInner(napi_env env, napi_value js_cb, void *context, void *data);
61     static void DeleteLocalAssetInner(napi_env env, napi_value js_cb, void *context, void *data);
62 
63     static napi_value BatchInsertResolvedCallback(napi_env env, napi_callback_info info);
64     static napi_value BatchInsertRejectedCallback(napi_env env, napi_callback_info info);
65     static napi_value HandleAssetResolvedCallback(napi_env env, napi_callback_info info);
66     static napi_value HandleAssetRejectedCallback(napi_env env, napi_callback_info info);
67     static napi_value HandleAssetAsyncResolvedCallback(napi_env env, napi_callback_info info);
68     static napi_value HandleAssetAsyncRejectedCallback(napi_env env, napi_callback_info info);
69     static napi_value QueryResolvedCallback(napi_env env, napi_callback_info info);
70     static napi_value QueryRejectedCallback(napi_env env, napi_callback_info info);
71 
72     napi_threadsafe_function batchInsertInnerFunc_ = nullptr;
73     napi_threadsafe_function queryInnerFunc_ = nullptr;
74     napi_threadsafe_function downloadAssetInnerFunc_ = nullptr;
75     napi_threadsafe_function uploadAssetInnerFunc_ = nullptr;
76     napi_threadsafe_function deleteAssetInnerFunc_ = nullptr;
77     napi_threadsafe_function deleteLocalAssetInnerFunc_ = nullptr;
78 
79 private:
80     static void GetCloudParamsVector(napi_env env, void *data, napi_value &arrayParams);
81     static void GetJsQueryParams(napi_env env, std::vector<QueryConditionT> conditions, napi_value &arrayParams);
82     static void HandleAssetInner(napi_env env, napi_value jsCb, void *context, void *data);
83     static void HandleAssetAsyncInner(napi_env env, napi_value jsCb, void *context, void *data);
84     static void ClearLastException(const napi_env& env);
85 };
86 } // namespace OHOS::CollaborationEdit
87 #endif // COLLABORATION_EDIT_CLOUD_DB_H
88