• 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
16import Constants from '../../common/constant';
17import { EncryptSharingShowCodeEnum } from '../../common/enum/EncryptSharingShowCodeEnum';
18
19export default class EncryptSharingHelper {
20  private static readonly ERROR_SHOW_MAP = new Map<number, Resource | string>([
21    [EncryptSharingShowCodeEnum.SUCCESS, $r('app.string.Share_File_Encrypted_Success')],
22    [EncryptSharingShowCodeEnum.COUNT_ERROR,
23      $r('app.string.Share_File_Count_Error', Constants.SHARE_MAX_SUPPORT_NUMBER)],
24    [EncryptSharingShowCodeEnum.FILE_ENCRYPTED_ERROR, $r('app.string.Share_File_has_been_Encrypted')],
25    [EncryptSharingShowCodeEnum.SINGLE_SIZE_ERROR_DOC_MB,
26      $r('app.string.Share_File_Single_Size_Limit_MB_Error', Constants.SHARE_MAX_SUPPORT_SIZE_DOC_MB)],
27    [EncryptSharingShowCodeEnum.SINGLE_SIZE_ERROR_IMAGE_VIDEO_MB,
28      $r('app.string.Share_File_Single_Size_Limit_MB_Error', Constants.SHARE_MAX_SUPPORT_SIZE_IMAGE_VIDEO_MB)],
29    [EncryptSharingShowCodeEnum.NETWORK_ERROR, $r('app.string.network_invalid')],
30    [EncryptSharingShowCodeEnum.FILE_NAME_TOO_LONG, $r('app.string.Share_File_Name_Too_Long')],
31    [EncryptSharingShowCodeEnum.PHONE_NUMBER_ERROR, $r('app.string.Share_Enter_Mobile_Number')],
32    [EncryptSharingShowCodeEnum.VALID_PHONE_FORMAT_TIP, $r('app.string.Share_Tips_Phone_Format')],
33    [EncryptSharingShowCodeEnum.FILE_PATH_ERROR, $r('app.string.Share_File_Path_Error')],
34    [EncryptSharingShowCodeEnum.ENCRYPT_FAIL_ERROR, $r('app.string.Share_File_Encrypted_Failed')],
35  ]);
36  private static readonly ERROR_MSG_MAP = new Map<number, string>([
37    [EncryptSharingShowCodeEnum.COUNT_ERROR,
38      `The total file count exceeds the limit of ${Constants.SHARE_MAX_SUPPORT_NUMBER} files.`],
39    [EncryptSharingShowCodeEnum.FILE_ENCRYPTED_ERROR, 'The file has been encrypted.'],
40    [EncryptSharingShowCodeEnum.SUPPORTED_TYPE_ERROR, 'Not support the file type.'],
41    [EncryptSharingShowCodeEnum.SINGLE_SIZE_ERROR_DOC_MB,
42      `The single file size exceeds the limit of ${Constants.SHARE_MAX_SUPPORT_SIZE_DOC_MB} MB.`],
43    [EncryptSharingShowCodeEnum.SINGLE_SIZE_ERROR_IMAGE_VIDEO_MB,
44      `The single file size exceeds the limit of ${Constants.SHARE_MAX_SUPPORT_SIZE_IMAGE_VIDEO_MB} MB.`],
45    [EncryptSharingShowCodeEnum.FILE_NAME_TOO_LONG, 'The file name is too long.'],
46    [EncryptSharingShowCodeEnum.FILE_PATH_ERROR, 'The file path is invalid.']
47  ]);
48
49  public static getShowErr(errorCode: number): Resource | string {
50    return EncryptSharingHelper.ERROR_SHOW_MAP.get(errorCode) ?? '';
51  }
52
53  public static getErrorMsg(errorCode: number): string {
54    return EncryptSharingHelper.ERROR_MSG_MAP.get(errorCode) ?? '';
55  }
56}