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 42ffb96b5192324ac3b8b0685896bb1817172e6a..4461c96ea9464261190debd4413e901a783c1d22 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 24974f044ac5591b0df5e702eac2ac01e0502608..d8b9188d6ae23fc888471d7c04b61dbdf2ccdea8 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 88bcc647ace97252e63f383b686da0ca83863e21..7b38013d4dc49082fcb55df89e66db5e74eb0db7 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 608c8245554ce2a92a1475ea457e8332b925893b..2b6c4d66aa14b4c0741bec817a4b884b5588c68b 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 b4508258de1908fddcee1a5fcd32bee93a27a2ba..e59823a6bc542edbb37efc487328d13b39bc86cb 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 0639a66dcaa9d5fe52490db4860795e1f327136e..06887735d65df808d5097d53f6880e0e1d477cc6 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); }