!201 上传接口修改

Merge pull request !201 from ann_lesley/master
This commit is contained in:
openharmony_ci 2022-08-25 11:31:12 +00:00 committed by Gitee
commit 4887c289ab
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 51 additions and 26 deletions

View File

@ -52,7 +52,6 @@ public:
UPLOAD_API virtual bool Remove();
UPLOAD_API virtual void On(Type type, void *callback);
UPLOAD_API virtual void Off(Type type, void *callback);
UPLOAD_API virtual void Off(Type type);
UPLOAD_API void ExecuteTask();
static void Run(void *arg);
virtual void OnRun();

View File

@ -64,13 +64,6 @@ void UploadTask::On(Type type, void *callback)
SetCallback(type, callback);
}
void UploadTask::Off(Type type)
{
UPLOAD_HILOGD(UPLOAD_MODULE_FRAMEWORK, "Off. In.");
std::lock_guard<std::mutex> guard(mutex_);
SetCallback(type, nullptr);
}
void UploadTask::Off(Type type, void *callback)
{
UPLOAD_HILOGD(UPLOAD_MODULE_FRAMEWORK, "Off. In.");
@ -82,8 +75,6 @@ void UploadTask::Off(Type type, void *callback)
if (type == TYPE_PROGRESS_CALLBACK && progressCallback_ != nullptr) {
((IProgressCallback*)callback)->Progress(uploadedSize_, totalSize_);
} else {
UPLOAD_HILOGD(UPLOAD_MODULE_FRAMEWORK, "Off. type[%{public}d] not match.", type);
}
SetCallback(type, nullptr);
}

View File

@ -342,10 +342,9 @@ declare namespace request {
*/
title?: string;
/**
* Whether to display the background.
* Allow download background task notifications.
*
* @since 9
* @permission N/A
*/
background?: boolean;
}
@ -829,7 +828,7 @@ declare namespace request {
* @permission ohos.permission.INTERNET
* @return -
*/
off(type:'complete' | 'fail'): void;
off(type:'complete' | 'fail', callback?: Callback<Array<TaskState>>): void;
/**
* Deletes a upload session.

View File

@ -117,6 +117,7 @@ private:
size_t argc, napi_value *argv, napi_value self, napi_value *result);
static napi_status OffFail(napi_env env, size_t argc, napi_value *argv, napi_value self, napi_value *result);
static napi_status OffComplete(napi_env env, size_t argc, napi_value *argv, napi_value self, napi_value *result);
static napi_status CheckOffCompleteParam(napi_env env, size_t argc, napi_value *argv, napi_value self);
std::shared_ptr<Upload::IProgressCallback> onProgress_ = nullptr;
std::shared_ptr<Upload::IHeaderReceiveCallback> onHeaderReceive_ = nullptr;

View File

@ -295,30 +295,65 @@ napi_status UploadTaskNapi::OffHeaderReceive(napi_env env,
return napi_ok;
}
napi_status UploadTaskNapi::OffFail(napi_env env, size_t argc, napi_value *argv, napi_value self, napi_value *result)
napi_status UploadTaskNapi::CheckOffCompleteParam(napi_env env, size_t argc, napi_value *argv, napi_value self)
{
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffFail.");
NAPI_ASSERT_BASE(env, argc == 0, "argc should be 0", napi_invalid_arg);
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, "argc should be 0 or 1", napi_invalid_arg);
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
UploadTaskNapi *proxy = nullptr;
NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast<void **>(&proxy)), napi_invalid_arg);
NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no native upload task", napi_invalid_arg);
proxy->napiUploadTask_->Off(TYPE_FAIL_CALLBACK);
if (argc == 1) {
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Input. argc == 1.");
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT_BASE(env, valueType == napi_function, "callback is not a function", napi_invalid_arg);
}
return napi_ok;
}
napi_status UploadTaskNapi::OffComplete(napi_env env, size_t argc, napi_value *argv,
napi_value self, napi_value *result)
napi_status UploadTaskNapi::OffFail(napi_env env,
size_t argc, napi_value *argv, napi_value self, napi_value *result)
{
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffComplete.");
NAPI_ASSERT_BASE(env, argc == 0, "argc should be 0", napi_invalid_arg);
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffFail.");
napi_status status = CheckOffCompleteParam(env, argc, argv, self);
if (status != napi_ok) {
return status;
}
UploadTaskNapi *proxy = nullptr;
NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast<void **>(&proxy)), napi_invalid_arg);
NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no native upload task", napi_invalid_arg);
proxy->napiUploadTask_->Off(TYPE_COMPLETE_CALLBACK);
if (proxy->onFail_ == nullptr) {
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Fail. proxy->onFail_ == nullptr.");
return napi_generic_failure;
} else {
std::shared_ptr<IFailCallback> callback = std::make_shared<FailCallback>(proxy, env, argv[0]);
proxy->napiUploadTask_->Off(TYPE_FAIL_CALLBACK, callback.get());
proxy->onFail_ = nullptr;
}
return napi_ok;
}
napi_status UploadTaskNapi::OffComplete(napi_env env,
size_t argc, napi_value *argv, napi_value self, napi_value *result)
{
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffComplete.");
napi_status status = CheckOffCompleteParam(env, argc, argv, self);
if (status != napi_ok) {
return status;
}
UploadTaskNapi *proxy = nullptr;
NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast<void **>(&proxy)), napi_invalid_arg);
NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no native upload task", napi_invalid_arg);
if (proxy->onComplete_ == nullptr) {
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "CompleteCallback. proxy->OffComplete_ == nullptr.");
return napi_generic_failure;
} else {
std::shared_ptr<ICompleteCallback> callback = std::make_shared<CompleteCallback>(proxy, env, argv[0]);
proxy->napiUploadTask_->Off(TYPE_COMPLETE_CALLBACK, callback.get());
proxy->onComplete_ = nullptr;
}
return napi_ok;
}