From 45c392a552b503c85ea5114b4074e245c767bbe0 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Mon, 16 Jun 2025 15:37:15 +0800 Subject: [PATCH] add dataUriUtils Signed-off-by: zhangzezhong --- .../ets/@ohos.app.ability.dataUriUtils.ets | 77 +++++++++++++++++++ frameworks/ets/ets/BUILD.gn | 17 ++++ 2 files changed, 94 insertions(+) create mode 100644 frameworks/ets/ets/@ohos.app.ability.dataUriUtils.ets diff --git a/frameworks/ets/ets/@ohos.app.ability.dataUriUtils.ets b/frameworks/ets/ets/@ohos.app.ability.dataUriUtils.ets new file mode 100644 index 00000000000..92d50f8f544 --- /dev/null +++ b/frameworks/ets/ets/@ohos.app.ability.dataUriUtils.ets @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +let domainID = 0xD001320; +let TAG = 'ETSENV'; + +const URI_SPLIT = '/'; + +namespace dataUriUtils { + export function getId(uri: string): number { + hilog.debug(domainID, TAG, 'DataUriUtils getId called.'); + if (typeof uri !== 'string') { + return -1; + } + let index = uri.lastIndexOf(URI_SPLIT); + if (index === -1) { + return -1; + } + let ret = uri.substring(index + 1); + if (ret === '' || isNaN(Number(ret))) { + return -1; + } + return Number(ret); + } + + export function attachId(uri: string, id: number): string { + hilog.debug(domainID, TAG, 'DataUriUtils attachId called.'); + if (typeof uri !== 'string' || typeof id !== 'number') { + return uri; + } + return uri + URI_SPLIT + id; + } + + export function deleteId(uri: string): string { + hilog.debug(domainID, TAG, 'DataUriUtils deleteId called.'); + if (typeof uri !== 'string') { + return uri; + } + let index = uri.lastIndexOf(URI_SPLIT); + if (index === -1) { + return uri; + } + let id = uri.substring(index + 1); + if (id === '' || isNaN(Number(id))) { + return uri; + } + return uri.substring(0, index); + } + + export function updateId(uri: string, id: number): string { + hilog.debug(domainID, TAG, 'DataUriUtils updateId called.'); + if (typeof uri !== 'string' || typeof id !== 'number') { + return uri; + } + let ret = dataUriUtils.deleteId(uri); + if (ret === uri) { + return uri; + } + return ret + URI_SPLIT + id; + } +} + +export default dataUriUtils; \ No newline at end of file diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index cf3a702bf83..1902e816ddb 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -261,6 +261,22 @@ ohos_prebuilt_etc("ability_runtime_ability_context_constant_abc_etc") { deps = [ ":ability_runtime_ability_context_constant_abc" ] } +generate_static_abc("ability_runtime_data_uri_utils_abc") { + base_url = "./" + files = [ "./@ohos.app.ability.dataUriUtils.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_data_uri_utils_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_data_uri_utils_abc_etc") { + source = "$target_out_dir/ability_runtime_data_uri_utils_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_data_uri_utils_abc" ] +} + generate_static_abc("ability_runtime_ui_ability_abc") { base_url = "./" files = [ "./@ohos.app.ability.UIAbility.ets" ] @@ -911,6 +927,7 @@ group("ets_packages") { ":ability_runtime_configuration_abc_etc", ":ability_runtime_configuration_constant_abc_etc", ":ability_runtime_context_abc_etc", + ":ability_runtime_data_uri_utils_abc_etc", ":ability_runtime_environment_callback_abc_etc", ":ability_runtime_event_hub_abc_etc", ":ability_runtime_extension_context_abc_etc", -- Gitee