Open
安全编码修改 #4
安全编码修改 #4
Open
easy_ghfAdd on Jul 23
Total: 6 files changed+94-90
@@ -83,25 +83,21 @@ struct EditFile {
83 let documentSaveOptions = new picker.DocumentSaveOptions();83 let documentSaveOptions = new picker.DocumentSaveOptions();
84 documentSaveOptions.newFileNames = ['MyDocument_01.txt'];84 documentSaveOptions.newFileNames = ['MyDocument_01.txt'];
85 let documentPicker = new picker.DocumentViewPicker();85 let documentPicker = new picker.DocumentViewPicker();
86- documentPicker.save(documentSaveOptions).then((documentSaveResult) => {86+ let documentSaveResult = await documentPicker.save(documentSaveOptions);
87- if (!documentSaveResult) {87+ if (!documentSaveResult) {
88- Logger.info(TAG, 'DocumentViewPicker.save failed.');88+ Logger.info(TAG, 'DocumentViewPicker.save failed.');
89- return;89+ return;
90- }90+ }
91- let saveAsUri = documentSaveResult[0];91+ let saveAsUri = documentSaveResult[0];
92- this.mediaFileUri.writeFileContent(saveAsUri, this.myFileContent);92+ this.mediaFileUri.writeFileContent(saveAsUri, this.myFileContent);
93- this.myFileName = decodeURI((saveAsUri.split('/').pop()) as string);93+ this.myFileName = decodeURI((saveAsUri.split('/').pop()) as string);
94- 94+ this.myFileSize = this.mediaFileUri.myGetFileSize(saveAsUri, fileIo.OpenMode.READ_ONLY);
95- this.myFileSize = this.mediaFileUri.myGetFileSize(saveAsUri, fileIo.OpenMode.READ_ONLY);95+ this.myUri = saveAsUri;
96- this.myUri = saveAsUri;96+ Logger.info(TAG, `save callFilePickerSaveFile file succeed.`);
97- Logger.info(TAG, `save callFilePickerSaveFile file succeed.`);
98- }).catch((err: BusinessError) => {
99- Logger.error(TAG,
100- `DocumentViewPicker.save failed with err, ErrorCode: ${err.code}, Message: ${err.message}`);
101- });
102 } catch (err) {97 } catch (err) {
103 Logger.error(TAG,98 Logger.error(TAG,
104- `DocumentViewPicker failed with err, ErrorCode: ${(err as BusinessError).code}, Message: ${(err as BusinessError).message}`);99+ `DocumentViewPicker.save failed with err, ErrorCode: ${(err as BusinessError).code}, Message: ${(err as
100+ BusinessError).message}`);
105 }101 }
106 }102 }
107 103 
@@ -42,9 +42,9 @@ export struct PickerComponent {
42 @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0;42 @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0;
43 @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0;43 @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0;
44 @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM;44 @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM;
45- @StorageLink(CommonConstants.AS_KEY_FILE_NAME_LIST) fileNameList: Array<string> = [];45+ @StorageLink(CommonConstants.AS_KEY_FILE_NAME_LIST) fileNameList: string[] = [];
46- @StorageLink(CommonConstants.AS_KEY_FILE_SIZE_LIST) fileSizeList: Array<number> = [];46+ @StorageLink(CommonConstants.AS_KEY_FILE_SIZE_LIST) fileSizeList: number[] = [];
47- @StorageLink(CommonConstants.AS_KEY_FILE_URI_LIST) fileUriList: Array<string> = [];47+ @StorageLink(CommonConstants.AS_KEY_FILE_URI_LIST) fileUriList: string[] = [];
48 @Provide(CommonConstants.AS_KEY_PATH_STACK) pathStack: NavPathStack = new NavPathStack();48 @Provide(CommonConstants.AS_KEY_PATH_STACK) pathStack: NavPathStack = new NavPathStack();
49 mediaFileUri: MediaFileUri = new MediaFileUri();49 mediaFileUri: MediaFileUri = new MediaFileUri();
50 scroller: Scroller = new Scroller();50 scroller: Scroller = new Scroller();
@@ -55,20 +55,18 @@ export struct PickerComponent {
55 let documentSelectOptions = new picker.DocumentSelectOptions();55 let documentSelectOptions = new picker.DocumentSelectOptions();
56 documentSelectOptions.maxSelectNumber = 1;56 documentSelectOptions.maxSelectNumber = 1;
57 let documentPicker = new picker.DocumentViewPicker();57 let documentPicker = new picker.DocumentViewPicker();
58- documentPicker.select(documentSelectOptions).then((documentSelectResult) => {58+ let documentSelectResult = await documentPicker.select(documentSelectOptions);
59- if (!documentSelectResult) {59+ if (!documentSelectResult) {
60- Logger.error(TAG, 'DocumentViewPicker.select failed');60+ Logger.error(TAG, 'DocumentViewPicker.select failed');
61- return;61+ return;
62- }62+ }
63- Logger.info(TAG, 'DocumentViewPicker.select successfully');63+ Logger.info(TAG, 'DocumentViewPicker.select successfully');
64- this.uri = documentSelectResult[0];64+ this.uri = documentSelectResult[0];
65- this.getFilenameByUri(this.uri, false);65+ this.getFilenameByUri(this.uri, false);
66- }).catch((err: BusinessError) => {
67- Logger.error(TAG,
68- `DocumentViewPicker.select failed with err, ErrorCode: ${err.code}, Message: ${err.message}`);
69- });
70 } catch (err) {66 } catch (err) {
71- Logger.error(TAG, 'DocumentViewPicker failed.');67+ Logger.error(TAG,
68+ `DocumentViewPicker.select failed with err, ErrorCode: ${(err as BusinessError).code}, Message: ${(err as
69+ BusinessError).message}`);
72 }70 }
73 }71 }
74 72 
@@ -78,69 +76,62 @@ export struct PickerComponent {
78 let documentSaveOptions = new picker.DocumentSaveOptions();76 let documentSaveOptions = new picker.DocumentSaveOptions();
79 documentSaveOptions.newFileNames = ['MyDocument_01.txt'];77 documentSaveOptions.newFileNames = ['MyDocument_01.txt'];
80 let documentPicker = new picker.DocumentViewPicker();78 let documentPicker = new picker.DocumentViewPicker();
81- documentPicker.save(documentSaveOptions).then((documentSaveResult) => {79+ let documentSaveResult = await documentPicker.save(documentSaveOptions);
82- if (!documentSaveResult) {80+ if (!documentSaveResult) {
83- Logger.error(TAG, 'DocumentViewPicker.save failed.');81+ Logger.error(TAG, 'DocumentViewPicker.save failed.');
84- return;82+ return;
85- }83+ }
86- Logger.info(TAG, 'DocumentViewPicker.save successfully.');84+ Logger.info(TAG, 'DocumentViewPicker.save successfully.');
87- this.uri = documentSaveResult[0];85+ this.uri = documentSaveResult[0];
88- this.getFilenameByUri(this.uri, true);86+ this.getFilenameByUri(this.uri, true);
89- }).catch((err: BusinessError) => {
90- Logger.error(TAG, `DocumentViewPicker.save failed, ErrorCode: ${err.code}, Message: ${err.message}`);
91- });
92 } catch (err) {87 } catch (err) {
93- Logger.error(TAG, 'DocumentViewPicker failed.');88+ Logger.error(TAG, `DocumentViewPicker.save failed, ErrorCode: ${(err as BusinessError).code}, Message: ${(err as
89+ BusinessError).message}`);
94 }90 }
95 }91 }
96 92 
97- async getFilenameByUriForMedia(myUris: string[]) {93+ getFilenameByUriForMedia(myUris: string[]) {
98 const params: UrisParam = {94 const params: UrisParam = {
99 uris: myUris95 uris: myUris
100 }96 }
101- this.pathStack.pushPathByName('ViewMedia', params)97+ this.pathStack.pushPathByName('ViewMedia', params);
102 }98 }
103 99 
104- async getFilenameByUri(myUri: string, created: boolean): Promise<void> {100+ getFilenameByUri(myUri: string, created: boolean): void {
105 this.filename = decodeURI((myUri.split('/').pop()) as string);101 this.filename = decodeURI((myUri.split('/').pop()) as string);
106 const params: FileParam = {102 const params: FileParam = {
107 fileName: this.filename,103 fileName: this.filename,
108 myUri: myUri,104 myUri: myUri,
109 isCreate: created105 isCreate: created
110 }106 }
111- this.pathStack.pushPathByName('EditFile', params)107+ this.pathStack.pushPathByName('EditFile', params);
112 }108 }
113 109 
114 // Pull up the picker to select images/videos.110 // Pull up the picker to select images/videos.
115 async callFilePickerSelectImage(): Promise<void> {111 async callFilePickerSelectImage(): Promise<void> {
116- let array: string[];112+ let array: string[] = [];
117 try {113 try {
118 let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();114 let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
119 photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE;115 photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE;
120 photoSelectOptions.maxSelectNumber = MAX_SELECT_NUM;116 photoSelectOptions.maxSelectNumber = MAX_SELECT_NUM;
121 let mediaFlag = false;117 let mediaFlag = false;
122- // Create a PhotoViewPicker object.
123 let photoPicker = new photoAccessHelper.PhotoViewPicker();118 let photoPicker = new photoAccessHelper.PhotoViewPicker();
124- photoPicker.select(photoSelectOptions).then((photoSelectResult) => {119+ let photoSelectResult = await photoPicker.select(photoSelectOptions);
125- Logger.info(TAG,120+ Logger.info(TAG, 'PhotoViewPicker.select successfully.');
126- 'PhotoViewPicker.select successfully.');121+ if (photoSelectResult !== null && photoSelectResult !== undefined) {
127- if (photoSelectResult !== null && photoSelectResult !== undefined) {122+ array = photoSelectResult.photoUris;
128- // Declare variable array, whose value is the array in PhotoSelectResult.123+ array.forEach((value) => {
129- array = photoSelectResult.photoUris;124+ this.uri = value;
130- array.forEach((value) => {125+ mediaFlag = true;
131- this.uri = value;126+ Logger.info(TAG, `select image/video succeed.`);
132- mediaFlag = true;127+ })
133- Logger.info(TAG, `select image/video succeed.`);128+ }
134- })129+ if (mediaFlag) {
135- }130+ this.getFilenameByUriForMedia(array);
136- if (mediaFlag) {131+ }
137- this.getFilenameByUriForMedia(array);
138- }
139- }).catch((err: BusinessError) => {
140- Logger.error(TAG, `PhotoViewPicker.select failed, ErrorCode: ${err.code}, Message: ${err.message}`);
141- });
142 } catch (err) {132 } catch (err) {
143- Logger.error(TAG, 'PhotoViewPicker failed.');133+ Logger.error(TAG, `PhotoViewPicker.select failed, ErrorCode: ${(err as BusinessError).code}, Message: ${(err as
134+ BusinessError).message}`);
144 }135 }
145 }136 }
146 137 
@@ -32,17 +32,17 @@ struct ViewMedia {
32 @State myFileSizes: number[] = [];32 @State myFileSizes: number[] = [];
33 @State myFileNames: string[] = [];33 @State myFileNames: string[] = [];
34 @State myFileTypes: number[] = [];34 @State myFileTypes: number[] = [];
35- @State controls: Array<boolean> = [];35+ @State controls: boolean[] = [];
36 @State myUris: string[] = [];36 @State myUris: string[] = [];
37 @StorageLink(CommonConstants.AS_KEY_MY_FILE_NAME) myFileName: string = '';37 @StorageLink(CommonConstants.AS_KEY_MY_FILE_NAME) myFileName: string = '';
38 @StorageLink(CommonConstants.AS_KEY_MY_FILE_SIZE) myFileSize: number = 0;38 @StorageLink(CommonConstants.AS_KEY_MY_FILE_SIZE) myFileSize: number = 0;
39- @StorageLink('showPauses') showPauses: Array<number> = [];39+ @StorageLink('showPauses') showPauses: number[] = [];
40 @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0;40 @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0;
41 @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0;41 @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0;
42 @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM;42 @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM;
43 mediaFileUri: MediaFileUri = new MediaFileUri();43 mediaFileUri: MediaFileUri = new MediaFileUri();
44 scroller: Scroller = new Scroller();44 scroller: Scroller = new Scroller();
45- controllers: Array<VideoController> = [];45+ controllers: VideoController[] = [];
46 @Consume(CommonConstants.AS_KEY_PATH_STACK) pageStack: NavPathStack;46 @Consume(CommonConstants.AS_KEY_PATH_STACK) pageStack: NavPathStack;
47 47 
48 aboutToAppear(): void {48 aboutToAppear(): void {
@@ -59,7 +59,7 @@ struct ViewMedia {
59 AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize);59 AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize);
60 }60 }
61 61 
62- async getMediaNameByUri(myUri: string, index: number) {62+ getMediaNameByUri(myUri: string, index: number) {
63 Logger.info(TAG, 'getMediaNameByUri getFilenameByUriForMedia begin');63 Logger.info(TAG, 'getMediaNameByUri getFilenameByUriForMedia begin');
64 this.myFileName = (myUri.split('/').pop()) as string;64 this.myFileName = (myUri.split('/').pop()) as string;
65 this.myFileNames[index] = this.myFileName;65 this.myFileNames[index] = this.myFileName;
@@ -24,13 +24,13 @@ const TAG = 'MediaFileUri';
24const BUFFER_SIZE = 4096;24const BUFFER_SIZE = 4096;
25 25 
26export default class MediaFileUri {26export default class MediaFileUri {
27- private fileSizeList: Array<number> = [];27+ private fileSizeList: number[] = [];
28- private fileNameList: Array<string> = [];28+ private fileNameList: string[] = [];
29- private fileUriList: Array<string> = [];29+ private fileUriList: string[] = [];
30 30 
31 readFileContent(uri: string): string {31 readFileContent(uri: string): string {
32 let content = '';32 let content = '';
33- let file: fileIo.File = null!;33+ let file: fileIo.File | null = null;
34 try {34 try {
35 file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY);35 file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY);
36 let buffer = new ArrayBuffer(BUFFER_SIZE);36 let buffer = new ArrayBuffer(BUFFER_SIZE);
@@ -52,7 +52,7 @@ export default class MediaFileUri {
52 }52 }
53 53 
54 myGetFileSize(uri: string, mode: number): number {54 myGetFileSize(uri: string, mode: number): number {
55- let file: fileIo.File = null!;55+ let file: fileIo.File | null = null;
56 try {56 try {
57 file = fileIo.openSync(uri, mode);57 file = fileIo.openSync(uri, mode);
58 let stat = fileIo.statSync(file.fd);58 let stat = fileIo.statSync(file.fd);
@@ -73,7 +73,7 @@ export default class MediaFileUri {
73 73 
74 writeFileContent(uri: string, content: string): void {74 writeFileContent(uri: string, content: string): void {
75 Logger.info(TAG, 'writeFileContent begin');75 Logger.info(TAG, 'writeFileContent begin');
76- let file: fileIo.File = null!;76+ let file: fileIo.File | null = null;
77 try {77 try {
78 file = fileIo.openSync(uri, fileIo.OpenMode.READ_WRITE);78 file = fileIo.openSync(uri, fileIo.OpenMode.READ_WRITE);
79 fileIo.writeSync(file.fd, content);79 fileIo.writeSync(file.fd, content);
@@ -89,7 +89,7 @@ export default class MediaFileUri {
89 }89 }
90 }90 }
91 91 
92- async getAllFiles(): Promise<void> {92+ getAllFiles(): void {
93 Logger.info(TAG, 'getAllFiles begin');93 Logger.info(TAG, 'getAllFiles begin');
94 AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_NAME_LIST, this.fileNameList);94 AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_NAME_LIST, this.fileNameList);
95 AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_SIZE_LIST, this.fileSizeList);95 AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_SIZE_LIST, this.fileSizeList);
Mpickerlibrary/src/main/ets/utils/StringUtils.ets+16-5File content is under review, please try again later
@@ -52,10 +52,16 @@ export class WindowUtil {
52 private static registerBreakPoint() {52 private static registerBreakPoint() {
53 BreakpointSystem.getInstance().updateWidthBp(WindowUtil.windowClass);53 BreakpointSystem.getInstance().updateWidthBp(WindowUtil.windowClass);
54 WindowUtil.updateAvoidArea(WindowUtil.windowClass);54 WindowUtil.updateAvoidArea(WindowUtil.windowClass);
55- WindowUtil.windowClass.on('windowSizeChange',55+ try {
56- () => BreakpointSystem.getInstance().onWindowSizeChange(WindowUtil.windowClass));56+ WindowUtil.windowClass.on('windowSizeChange',
57- WindowUtil.windowClass.on('avoidAreaChange',57+ () => BreakpointSystem.getInstance().onWindowSizeChange(WindowUtil.windowClass));
58- (avoidAreaOption) => WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area));58+ WindowUtil.windowClass.on('avoidAreaChange',
59+ (avoidAreaOption) => WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area));
60+ } catch (error) {
61+ const err: BusinessError = error as BusinessError;
62+ Logger.error(TAG,
63+ `Failed to register windowSizeChange or avoidAreaChange. code: ${err.code}, message: ${err.message}`);
64+ }
59 }65 }
60 66 
61 public static unRegisterBreakPoint() {67 public static unRegisterBreakPoint() {