mirror of
https://github.com/openharmony/multimedia_medialibrary_standard.git
synced 2026-07-01 00:17:55 -04:00
Add uris to recoverAssets
Signed-off-by: zhang-daiyue <zhangdaiyue1@huawei.com> Change-Id: Ibc35772716f7bff49e0412d33b1ef7f93c18fb50
This commit is contained in:
@@ -252,7 +252,7 @@ int32_t MediaLibraryNotify::Notify(const string &uri, const NotifyType notifyTyp
|
||||
uri.c_str(), notifyType, albumId);
|
||||
shared_ptr<MediaLibraryAsyncTask> notifyAsyncTask = make_shared<MediaLibraryAsyncTask>(AddNfListMap, taskData);
|
||||
if (notifyAsyncTask != nullptr) {
|
||||
asyncWorker->AddTask(notifyAsyncTask, false);
|
||||
asyncWorker->AddTask(notifyAsyncTask, true);
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ int32_t MediaLibraryRdbStore::DeleteFromDisk(const AbsRdbPredicates &predicates,
|
||||
if (filePath.empty()) {
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
if (!MediaFileUtils::DeleteFile(filePath) && (errno != -ENOENT)) {
|
||||
if (!MediaFileUtils::DeleteFile(filePath) && (errno != ENOENT)) {
|
||||
MEDIA_ERR_LOG("Failed to delete file, errno: %{public}d, path: %{private}s", errno, filePath.c_str());
|
||||
return E_HAS_FS_ERROR;
|
||||
}
|
||||
|
||||
@@ -906,6 +906,90 @@ bool NapiScopeHandler::IsValid()
|
||||
return isValid_;
|
||||
}
|
||||
|
||||
napi_value MediaLibraryNapiUtils::GetNapiValueArray(napi_env env, napi_value arg, vector<napi_value> &values)
|
||||
{
|
||||
bool isArray = false;
|
||||
CHECK_ARGS(env, napi_is_array(env, arg, &isArray), JS_ERR_PARAMETER_INVALID);
|
||||
if (!isArray) {
|
||||
NapiError::ThrowError(env, JS_ERR_PARAMETER_INVALID, "Failed to check array type");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t len = 0;
|
||||
CHECK_ARGS(env, napi_get_array_length(env, arg, &len), JS_INNER_FAIL);
|
||||
if (len < 0) {
|
||||
NAPI_ERR_LOG("Failed to check array length: %{public}u", len);
|
||||
NapiError::ThrowError(env, JS_ERR_PARAMETER_INVALID, "Failed to check array length");
|
||||
return nullptr;
|
||||
}
|
||||
if (len == 0) {
|
||||
napi_value result = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &result), JS_INNER_FAIL);
|
||||
return result;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
napi_value value = nullptr;
|
||||
CHECK_ARGS(env, napi_get_element(env, arg, i, &value), JS_INNER_FAIL);
|
||||
if (value == nullptr) {
|
||||
NapiError::ThrowError(env, JS_ERR_PARAMETER_INVALID, "Failed to get asset element");
|
||||
return nullptr;
|
||||
}
|
||||
values.push_back(value);
|
||||
}
|
||||
|
||||
napi_value result = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &result), JS_INNER_FAIL);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value MediaLibraryNapiUtils::GetStringArray(napi_env env, vector<napi_value> &napiValues, vector<string> &values)
|
||||
{
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
unique_ptr<char[]> buffer = make_unique<char[]>(PATH_MAX);
|
||||
for (const auto &napiValue : napiValues) {
|
||||
CHECK_ARGS(env, napi_typeof(env, napiValue, &valueType), JS_ERR_PARAMETER_INVALID);
|
||||
CHECK_COND(env, valueType == napi_string, JS_ERR_PARAMETER_INVALID);
|
||||
|
||||
size_t res = 0;
|
||||
CHECK_ARGS(
|
||||
env, napi_get_value_string_utf8(env, napiValue, buffer.get(), PATH_MAX, &res), JS_ERR_PARAMETER_INVALID);
|
||||
values.emplace_back(buffer.get());
|
||||
}
|
||||
napi_value ret = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &ret), JS_INNER_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetUriFromAsset(const FileAssetNapi *obj)
|
||||
{
|
||||
string displayName = obj->GetFileDisplayName();
|
||||
string filePath = obj->GetFilePath();
|
||||
return MediaFileUtils::GetUriByExtrConditions(PhotoColumn::PHOTO_URI_PREFIX, to_string(obj->GetFileId()),
|
||||
MediaFileUtils::GetExtraUri(displayName, filePath));
|
||||
}
|
||||
|
||||
napi_value MediaLibraryNapiUtils::GetUriArrayFromAssets(
|
||||
napi_env env, vector<napi_value> &napiValues, vector<string> &values)
|
||||
{
|
||||
FileAssetNapi *obj = nullptr;
|
||||
for (const auto &napiValue : napiValues) {
|
||||
CHECK_ARGS(env, napi_unwrap(env, napiValue, reinterpret_cast<void **>(&obj)), JS_INNER_FAIL);
|
||||
if (obj == nullptr) {
|
||||
NapiError::ThrowError(env, JS_ERR_PARAMETER_INVALID, "Failed to get asset napi object");
|
||||
return nullptr;
|
||||
}
|
||||
if ((obj->GetMediaType() != MEDIA_TYPE_IMAGE && obj->GetMediaType() != MEDIA_TYPE_VIDEO)) {
|
||||
NAPI_INFO_LOG("Skip invalid asset, mediaType: %{public}d", obj->GetMediaType());
|
||||
continue;
|
||||
}
|
||||
values.push_back(GetUriFromAsset(obj));
|
||||
}
|
||||
napi_value ret = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &ret), JS_INNER_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template bool MediaLibraryNapiUtils::HandleSpecialPredicate<unique_ptr<MediaLibraryAsyncContext>>(
|
||||
unique_ptr<MediaLibraryAsyncContext> &context, shared_ptr<DataShareAbsPredicates> &predicate,
|
||||
const FetchOptionType &fetchOptType);
|
||||
|
||||
@@ -916,6 +916,8 @@ static napi_value TrashAlbumParseArgs(napi_env env, napi_callback_info info,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value result = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &result), JS_INNER_FAIL);
|
||||
constexpr size_t minArgs = ARGS_ONE;
|
||||
constexpr size_t maxArgs = ARGS_TWO;
|
||||
CHECK_ARGS(env, MediaLibraryNapiUtils::AsyncContextSetObjectInfo(env, info, context, minArgs, maxArgs),
|
||||
@@ -927,17 +929,28 @@ static napi_value TrashAlbumParseArgs(napi_env env, napi_callback_info info,
|
||||
}
|
||||
|
||||
/* Parse the first argument */
|
||||
vector<string> assetsArray;
|
||||
CHECK_NULLPTR_RET(GetAssetsIdArray(env, context->argv[PARAM0], assetsArray));
|
||||
if (assetsArray.empty()) {
|
||||
napi_value result = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &result), JS_INNER_FAIL);
|
||||
vector<napi_value> napiValues;
|
||||
CHECK_NULLPTR_RET(MediaLibraryNapiUtils::GetNapiValueArray(env, context->argv[PARAM0], napiValues));
|
||||
if (napiValues.empty()) {
|
||||
return result;
|
||||
}
|
||||
context->predicates.In(MediaColumn::MEDIA_ID, assetsArray);
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
vector<string> uris;
|
||||
CHECK_ARGS(env, napi_typeof(env, napiValues.front(), &valueType), JS_ERR_PARAMETER_INVALID);
|
||||
if (valueType == napi_string) {
|
||||
// The input should be an array of asset uri.
|
||||
CHECK_NULLPTR_RET(MediaLibraryNapiUtils::GetStringArray(env, napiValues, uris));
|
||||
} else if (valueType == napi_object) {
|
||||
// The input should be an array of asset object.
|
||||
CHECK_NULLPTR_RET(MediaLibraryNapiUtils::GetUriArrayFromAssets(env, napiValues, uris));
|
||||
}
|
||||
if (uris.empty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
context->predicates.In(MediaColumn::MEDIA_ID, uris);
|
||||
context->valuesBucket.Put(MediaColumn::MEDIA_DATE_TRASHED, 0);
|
||||
|
||||
napi_value result = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &result), JS_INNER_FAIL);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,6 @@ void MediaLibraryAsyncWorker::StartWorker(int num)
|
||||
fgTask->executor_(fgTask->data_);
|
||||
fgTask = nullptr;
|
||||
doneTotal_++;
|
||||
SleepFgWork();
|
||||
}
|
||||
} else if (!IsBgQueueEmpty()) {
|
||||
shared_ptr<MediaLibraryAsyncTask> bgTask = GetBgTask();
|
||||
|
||||
@@ -493,6 +493,13 @@ public:
|
||||
static bool IsSystemApp();
|
||||
static std::string GetStringFetchProperty(napi_env env, napi_value arg, bool &err, bool &present,
|
||||
const std::string &propertyName);
|
||||
|
||||
static napi_value GetNapiValueArray(napi_env env, napi_value arg, std::vector<napi_value> &values);
|
||||
static napi_value GetUriArrayFromAssets(
|
||||
napi_env env, std::vector<napi_value> &napiValues, std::vector<std::string> &values);
|
||||
static napi_value GetStringArray(
|
||||
napi_env env, std::vector<napi_value> &napiValues, std::vector<std::string> &values);
|
||||
|
||||
private:
|
||||
static napi_status hasFetchOpt(napi_env env, const napi_value arg, bool &hasFetchOpt);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user