From b144acdbd14e35d6aa032c4875f84ebb764d1eb3 Mon Sep 17 00:00:00 2001 From: Eason Date: Tue, 22 Jun 2021 20:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=20=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../andserver/controller/TestController.java | 3 +- .../andserver/provider/ListProvider.java | 1 + .../yanzhenjie/andserver/util/FileUtils.java | 40 +++++++++++++++---- .../resources/rawfile/web/js/jquery-form.js | 8 ++-- .../rawfile/web/scripts/bitcandies.upload5.js | 2 +- .../resources/rawfile/web/scripts/transfer.js | 15 ++----- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/entry/src/main/java/com/yanzhenjie/andserver/controller/TestController.java b/entry/src/main/java/com/yanzhenjie/andserver/controller/TestController.java index 42ffb96..4461c96 100644 --- a/entry/src/main/java/com/yanzhenjie/andserver/controller/TestController.java +++ b/entry/src/main/java/com/yanzhenjie/andserver/controller/TestController.java @@ -92,10 +92,9 @@ class TestController { String upload(@RequestParam(name = "avatar") MultipartFile file) throws IOException { File localFile = FileUtils.createRandomFile(file); file.transferTo(localFile); - System.out.println("jk---->upload: upload successful---" + file.getFilename() + "-----" + localFile.getAbsolutePath()); EventBus.getDefault().post(new MessageEvent()); new ToastDialog(MyApplication.getInstance().getContext()).setText("上传成功,请刷新网页端").show(); - return localFile.getAbsolutePath(); + return localFile.getCanonicalPath(); } @PostMapping(path = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) diff --git a/entry/src/main/java/com/yanzhenjie/andserver/provider/ListProvider.java b/entry/src/main/java/com/yanzhenjie/andserver/provider/ListProvider.java index 24974f0..d8b9188 100644 --- a/entry/src/main/java/com/yanzhenjie/andserver/provider/ListProvider.java +++ b/entry/src/main/java/com/yanzhenjie/andserver/provider/ListProvider.java @@ -7,6 +7,7 @@ import com.yanzhenjie.hos.ResourceTable; import com.yanzhenjie.swipelayout.SwipeLayout; import ohos.aafwk.content.Intent; import ohos.agp.components.*; +import ohos.agp.window.dialog.ToastDialog; import ohos.app.Context; import java.io.File; diff --git a/entry/src/main/java/com/yanzhenjie/andserver/util/FileUtils.java b/entry/src/main/java/com/yanzhenjie/andserver/util/FileUtils.java index 88bcc64..7b38013 100644 --- a/entry/src/main/java/com/yanzhenjie/andserver/util/FileUtils.java +++ b/entry/src/main/java/com/yanzhenjie/andserver/util/FileUtils.java @@ -59,7 +59,12 @@ public class FileUtils { if (sdDir == null) { return false; } - File sd = new File(sdDir.getAbsolutePath()); + File sd = null; + try { + sd = new File(sdDir.getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } return sd.canWrite(); } @@ -84,7 +89,8 @@ public class FileUtils { public static void mkDir(String dir_path) { File myFolderPath = new File(dir_path); try { - if (!myFolderPath.exists()) { + boolean isPath = myFolderPath.exists(); + if (!isPath) { myFolderPath.mkdir(); } } catch (Exception e) { @@ -125,13 +131,15 @@ public class FileUtils { * @throws IOException IOException */ public static void deleteDir(File dir) throws IOException { - if (dir.isFile()) + boolean isDir = dir.isFile(); + if (isDir) throw new IOException("IOException -> BadInputException: not a directory."); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; - if (file.isFile()) { + boolean isFile = file.isFile(); + if (isFile) { file.delete(); } else { deleteDir(file); @@ -239,9 +247,17 @@ public class FileUtils { String fileName = files[i].getName(); if (files[i].isDirectory()) { - getFileList(files[i].getAbsolutePath()); //遍历子文件夹里面的东西 + try { + getFileList(files[i].getCanonicalPath()); //遍历子文件夹里面的东西 + } catch (IOException e) { + e.printStackTrace(); + } } else if (fileName.endsWith("exe")) { // 以***结尾的文件 - String strFileName = files[i].getAbsolutePath(); + try { + String strFileName = files[i].getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } filelist.add(files[i]); } else { filelist.add(files[i]); @@ -268,9 +284,17 @@ public class FileUtils { String fileName = files[i].getName(); System.out.println("pathss--" + fileName); if (files[i].isDirectory()) { - getFileList(files[i].getAbsolutePath()); //遍历子文件夹里面的东西 + try { + getFileList(files[i].getCanonicalPath()); //遍历子文件夹里面的东西 + } catch (IOException e) { + e.printStackTrace(); + } } else if (fileName.endsWith("exe")) { // 以***结尾的文件 - String strFileName = files[i].getAbsolutePath(); + try { + String strFileName = files[i].getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } filelist.add(files[i]); } else { filelist.add(files[i]); diff --git a/entry/src/main/resources/rawfile/web/js/jquery-form.js b/entry/src/main/resources/rawfile/web/js/jquery-form.js index 608c824..2b6c4d6 100644 --- a/entry/src/main/resources/rawfile/web/js/jquery-form.js +++ b/entry/src/main/resources/rawfile/web/js/jquery-form.js @@ -558,9 +558,9 @@ $.fn.ajaxSubmit = function(options) { try { if (s.extraData) { for (var n in s.extraData) { - if (s.extraData.hasOwnProperty(n)) { + if (Object.prototype.hasOwnProperty.call(s.extraData,n)) { // if using the $.param format that allows for multiple values with the same name - if($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) { + if($.isPlainObject(s.extraData[n]) && Object.prototype.hasOwnProperty.call(s.extraData[n],'name') && Object.prototype.hasOwnProperty.call(s.extraData[n],'value')) { extraInputs.push( $('').val(s.extraData[n].value) .appendTo(form)[0]); @@ -665,9 +665,7 @@ $.fn.ajaxSubmit = function(options) { setTimeout(cb, 250); return; } - // let this fall through because server response could be an empty document - //log('Could not access iframe DOM after mutiple tries.'); - //throw 'DOMException: not available'; + } //log('response detected'); diff --git a/entry/src/main/resources/rawfile/web/scripts/bitcandies.upload5.js b/entry/src/main/resources/rawfile/web/scripts/bitcandies.upload5.js index b450825..e59823a 100644 --- a/entry/src/main/resources/rawfile/web/scripts/bitcandies.upload5.js +++ b/entry/src/main/resources/rawfile/web/scripts/bitcandies.upload5.js @@ -148,7 +148,7 @@ bitcandies.FileUploader.prototype = { for (var key in item.params) { formData.append(key, item.params[key]); } -// formData.append("fileName",encodeURI(item.file.name)); + formData.append(this.options.fieldname, item.file); xhr.send(formData); diff --git a/entry/src/main/resources/rawfile/web/scripts/transfer.js b/entry/src/main/resources/rawfile/web/scripts/transfer.js index 0639a66..0688773 100644 --- a/entry/src/main/resources/rawfile/web/scripts/transfer.js +++ b/entry/src/main/resources/rawfile/web/scripts/transfer.js @@ -52,14 +52,7 @@ $(function() { } function loadFileList() { - // var now = new Date(); - // var url = "files?"; - // $.getJSON(url + now.getTime(), function(data) { - // files = data; - // fillFilesContainer(); - // //$(".download").click(downloadBook); - // //$(".trash").click(deleteBook); - // }); + $.ajax({ type: 'post', url:'/user/listBody', @@ -184,7 +177,7 @@ $(function() { function checkFileName(fileName) { if (!fileName || !fileName.toLowerCase().match('(apk)$')) { - //return STRINGS.UNSUPPORTED_FILE_TYPE; + } var arr = fileName.split("\\"); @@ -238,7 +231,7 @@ $(function() { return; } var fileName = $(this).val(); - //alert(fileName); + var msg = checkFileName(fileName); if (msg) { @@ -294,7 +287,7 @@ $(function() { var uploader = getHtml5Uploader(); var fileName = $(this).parent().find('.filename').attr('filename'); if (fileName) { - item = items[fileName]; + var item = items[fileName]; if (item) { uploader.abort(item); } -- Gitee