mirror of
https://gitee.com/openharmony/filemanagement_user_file_service
synced 2024-11-23 07:20:41 +00:00
commit
f74bf3f9e0
@ -572,8 +572,8 @@ static int ReadFileFilterResults(MessageParcel &reply, SharedMemoryInfo &memInfo
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
|
||||
SharedMemoryInfo &memInfo)
|
||||
int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset,
|
||||
const FileFilter &filter, SharedMemoryInfo &memInfo)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("ListFile");
|
||||
|
@ -21,7 +21,7 @@ const PhotoViewMIMETypes = {
|
||||
VIDEO_TYPE: 'video/*',
|
||||
IMAGE_VIDEO_TYPE: '*/*',
|
||||
INVALID_TYPE: ''
|
||||
}
|
||||
};
|
||||
|
||||
const DocumentSelectMode = {
|
||||
FILE: 0,
|
||||
@ -50,7 +50,7 @@ const ErrCode = {
|
||||
RESULT_ERROR: 13900042,
|
||||
NAME_TOO_LONG: 13900030,
|
||||
CONTEXT_NO_EXIST: 16000011,
|
||||
}
|
||||
};
|
||||
|
||||
const ERRCODE_MAP = new Map([
|
||||
[ErrCode.INVALID_ARGS, 'Invalid argument'],
|
||||
@ -70,7 +70,7 @@ const ACTION = {
|
||||
SELECT_ACTION_MODAL: 'ohos.want.action.OPEN_FILE_SERVICE',
|
||||
SAVE_ACTION: 'ohos.want.action.CREATE_FILE',
|
||||
SAVE_ACTION_MODAL: 'ohos.want.action.CREATE_FILE_SERVICE',
|
||||
}
|
||||
};
|
||||
|
||||
const CREATE_FILE_NAME_LENGTH_LIMIT = 256;
|
||||
const ARGS_ZERO = 0;
|
||||
@ -78,6 +78,7 @@ const ARGS_ONE = 1;
|
||||
const ARGS_TWO = 2;
|
||||
const RESULT_CODE_ERROR = -1;
|
||||
const RESULT_CODE_OK = 0;
|
||||
const FILENAME_LENGTH = 3;
|
||||
|
||||
/*
|
||||
* UTF-8字符编码数值对应的存储长度:
|
||||
@ -109,7 +110,6 @@ function strSizeUTF8(str) {
|
||||
|
||||
function checkArguments(args) {
|
||||
let checkArgumentsResult = undefined;
|
||||
|
||||
if (args.length === ARGS_TWO && typeof args[ARGS_ONE] !== 'function') {
|
||||
checkArgumentsResult = getErr(ErrCode.INVALID_ARGS);
|
||||
}
|
||||
@ -122,13 +122,15 @@ function checkArguments(args) {
|
||||
}
|
||||
}
|
||||
|
||||
if (option.newFileNames !== undefined && option.newFileNames.length > 0) {
|
||||
for (let i = 0; i < option.newFileNames.length; i++) {
|
||||
let value = option.newFileNames[i];
|
||||
if (strSizeUTF8(value) >= CREATE_FILE_NAME_LENGTH_LIMIT) {
|
||||
console.log('[picker] checkArguments Invalid name: ' + value);
|
||||
checkArgumentsResult = getErr(ErrCode.NAME_TOO_LONG);
|
||||
}
|
||||
if (option.newFileNames === undefined || option.newFileNames.length <= 0) {
|
||||
return checkArgumentsResult;
|
||||
}
|
||||
|
||||
for (let i = 0; i < option.newFileNames.length; i++) {
|
||||
let value = option.newFileNames[i];
|
||||
if (strSizeUTF8(value) >= CREATE_FILE_NAME_LENGTH_LIMIT) {
|
||||
console.log('[picker] checkArguments Invalid name: ' + value);
|
||||
checkArgumentsResult = getErr(ErrCode.NAME_TOO_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,6 +167,32 @@ function parsePhotoPickerSelectOption(args) {
|
||||
return config;
|
||||
}
|
||||
|
||||
function anonymousPathArray(geturi) {
|
||||
let anonymousPathArrays = [];
|
||||
let anonymousPath = '';
|
||||
if (geturi === undefined) {
|
||||
return anonymousPathArrays;
|
||||
}
|
||||
for (let i = 0; i < geturi.length; ++i) {
|
||||
let lastSlashIndex = geturi[i].lastIndexOf('/');
|
||||
if (lastSlashIndex === -1) {
|
||||
anonymousPathArrays.push(geturi[i]);
|
||||
} else {
|
||||
let dirPath = geturi[i].substring(0, lastSlashIndex + 1);
|
||||
let fileName = geturi[i].substring(lastSlashIndex + 1);
|
||||
if (fileName.length <= 0) {
|
||||
anonymousPath = '******';
|
||||
} else {
|
||||
let lastLetter = fileName.slice(-1);
|
||||
let maskedName = '******' + lastLetter;
|
||||
anonymousPath = dirPath + maskedName;
|
||||
}
|
||||
anonymousPathArrays.push(anonymousPath);
|
||||
}
|
||||
}
|
||||
return anonymousPathArrays;
|
||||
}
|
||||
|
||||
function getPhotoPickerSelectResult(args) {
|
||||
let selectResult = {
|
||||
error: undefined,
|
||||
@ -227,7 +255,7 @@ async function photoPickerSelect(...args) {
|
||||
} else {
|
||||
reject(photoSelectResult.error);
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[picker] photo select error: ' + error);
|
||||
}
|
||||
@ -303,7 +331,9 @@ function getDocumentPickerSelectResult(args) {
|
||||
selectResult.data = [];
|
||||
selectResult.error = args.resultCode;
|
||||
}
|
||||
console.log('[picker] document select selectResult: ' + JSON.stringify(selectResult));
|
||||
|
||||
console.log('[picker] document select selectResult: : errorcode is = ' + selectResult.error +
|
||||
', selecturi is = ' + anonymousPathArray(selectResult.data));
|
||||
return selectResult;
|
||||
}
|
||||
|
||||
@ -340,7 +370,6 @@ async function documentPickerSelect(...args) {
|
||||
} catch (paramError) {
|
||||
console.error('[picker] DocumentSelect paramError: ' + JSON.stringify(paramError));
|
||||
}
|
||||
console.log('[picker] DocumentSelect result: ' + JSON.stringify(documentSelectResult));
|
||||
selectResult = getDocumentPickerSelectResult(documentSelectResult);
|
||||
return sendResult(args, selectResult);
|
||||
}
|
||||
@ -394,12 +423,17 @@ function getAudioPickerSelectResult(args) {
|
||||
if (args.uriArr) {
|
||||
selectResult.data = args.uriArr;
|
||||
selectResult.error = args.resultCode;
|
||||
} else {
|
||||
selectResult.data = [];
|
||||
selectResult.error = args.resultCode;
|
||||
}
|
||||
} else if (args.resultCode === RESULT_CODE_ERROR) {
|
||||
selectResult.data = [];
|
||||
selectResult.error = args.resultCode;
|
||||
}
|
||||
console.log('[picker] getAudioPickerSelectResult selectResult: ' + JSON.stringify(selectResult));
|
||||
|
||||
console.log('[picker] getAudioPickerSelectResult selectResult: errorcode is = ' + selectResult.error +
|
||||
', selecturi is = ' + anonymousPathArray(selectResult.data));
|
||||
return selectResult;
|
||||
}
|
||||
|
||||
@ -427,7 +461,9 @@ function getDocumentPickerSaveResult(args) {
|
||||
saveResult.data = [];
|
||||
saveResult.error = args.resultCode;
|
||||
}
|
||||
console.log('[picker] getDocumentPickerSaveResult saveResult: ' + JSON.stringify(saveResult));
|
||||
|
||||
console.log('[picker] getDocumentPickerSaveResult saveResult: errorcode is = ' + saveResult.error +
|
||||
', selecturi is = ' + anonymousPathArray(saveResult.data) + ', usersavesuffix = ' + saveResult.suffix);
|
||||
return saveResult;
|
||||
}
|
||||
|
||||
@ -491,7 +527,6 @@ async function documentPickerSave(...args) {
|
||||
documentSaveResult = await modalPicker(args, documentSaveContext, documentSaveConfig);
|
||||
saveResult = getDocumentPickerSaveResult(documentSaveResult);
|
||||
this.suffixIndex = saveResult.suffix;
|
||||
console.log('[picker] download save result: ' + JSON.stringify(saveResult));
|
||||
return sendResult(args, saveResult);
|
||||
}
|
||||
|
||||
@ -502,6 +537,7 @@ function getSelectedSuffixIndex() {
|
||||
console.log('[picker] Get Selected Suffix Index end: ' + index);
|
||||
return index;
|
||||
}
|
||||
|
||||
async function sendResult(args, result) {
|
||||
try {
|
||||
if (result === undefined) {
|
||||
@ -641,4 +677,4 @@ export default {
|
||||
PhotoViewPicker : PhotoViewPicker,
|
||||
DocumentViewPicker: DocumentViewPicker,
|
||||
AudioViewPicker : AudioViewPicker,
|
||||
}
|
||||
};
|
||||
|
@ -46,8 +46,7 @@ void ModalUICallback::OnError(int32_t code, const std::string& name, const std::
|
||||
|
||||
void ModalUICallback::OnResultForModal(int32_t resultCode, const OHOS::AAFwk::Want &result)
|
||||
{
|
||||
HILOG_INFO("modal picker: OnResultForModal enter. resultCode is %{public}d, %{public}s",
|
||||
resultCode, result.ToString().c_str());
|
||||
HILOG_INFO("modal picker: OnResultForModal enter. resultCode is %{public}d,", resultCode);
|
||||
pickerCallBack_->resultCode = resultCode;
|
||||
pickerCallBack_->want = result;
|
||||
pickerCallBack_->ready = true;
|
||||
|
@ -106,8 +106,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr<Pic
|
||||
napi_create_object(env, &result);
|
||||
|
||||
const int32_t resCode = pickerCallBack->resultCode;
|
||||
HILOG_INFO("modal picker: resCode is %{public}d. want is %{public}s.",
|
||||
resCode, pickerCallBack->want.ToString().c_str());
|
||||
HILOG_INFO("modal picker: resCode is %{public}d.", resCode);
|
||||
napi_value resultCode = nullptr;
|
||||
napi_create_int32(env, resCode, &resultCode);
|
||||
status = napi_set_named_property(env, result, "resultCode", resultCode);
|
||||
|
Loading…
Reference in New Issue
Block a user