浏览代码

脚本上传下载

dengsixing 2 年之前
父节点
当前提交
5601add002

+ 7 - 8
4dkankan-utils-fyun-local/src/main/java/com/fdkankan/fyun/local/LocalFileService.java

@@ -5,17 +5,16 @@ import com.fdkankan.fyun.constant.FYunConstants;
 import com.fdkankan.fyun.constant.FYunTypeEnum;
 import com.fdkankan.fyun.face.AbstractFYunFileService;
 import com.fdkankan.fyun.local.constant.LocalConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.stereotype.Component;
-import org.springframework.util.ObjectUtils;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
 
 @Component
 @ConditionalOnProperty(name = "fyun.type", havingValue = "local")
@@ -48,7 +47,7 @@ public class LocalFileService extends AbstractFYunFileService {
     public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
         try {
             String optType = new File(filePath).isDirectory() ? "folder" : "file";
-            String command = String.format(FYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.LOCAL.code(), optType);
+            String command = String.format(fYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.LOCAL.code(), optType);
             log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
             callshell(command);
         } catch (Exception e) {
@@ -62,7 +61,7 @@ public class LocalFileService extends AbstractFYunFileService {
     public void downloadFileByCommand(String bucket, String filePath, String remoteFilePath) {
         try {
             String optType = new File(filePath).isDirectory() ? "folder" : "file";
-            String command = String.format(FYunConstants.DOWNLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.LOCAL.code(), optType);
+            String command = String.format(fYunConstants.DOWNLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.LOCAL.code(), optType);
             log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
             callshell(command);
         } catch (Exception e) {

+ 2 - 2
4dkankan-utils-fyun-oss/src/main/java/com/fdkankan/fyun/oss/OssFileService.java

@@ -79,7 +79,7 @@ public class OssFileService extends AbstractFYunFileService {
     public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
         try {
             String optType = new File(filePath).isDirectory() ? "folder" : "file";
-            String command = String.format(FYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.OSS.code(), optType);
+            String command = String.format(fYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.OSS.code(), optType);
             log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
             callshell(command);
         } catch (Exception e) {
@@ -93,7 +93,7 @@ public class OssFileService extends AbstractFYunFileService {
     public void downloadFileByCommand(String bucket, String filePath, String remoteFilePath) {
         try {
             String optType = new File(filePath).isDirectory() ? "folder" : "file";
-            String command = String.format(FYunConstants.DOWNLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.OSS.code(), optType);
+            String command = String.format(fYunConstants.DOWNLOAD_SH, bucket, remoteFilePath, filePath, FYunTypeEnum.OSS.code(), optType);
             log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
             callshell(command);
         } catch (Exception e) {

+ 11 - 7
4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/constant/FYunConstants.java

@@ -1,11 +1,14 @@
 package com.fdkankan.fyun.constant;
 
+import javax.annotation.PostConstruct;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
 
+@Component
 public class FYunConstants {
 
-
-    public static String shellPath;
+    @Value("${fyun.shell.path:/opt/ossutil}")
+    public String shellPath;
 
     /**
      * oss文件上传命令 bash /opt/ossutil/fyun-upload.sh {bucket} {srcPath} {destPath} {fyunType} {opType}
@@ -13,11 +16,12 @@ public class FYunConstants {
      * 参考:http://showdoc.4dage.com/web/#/45?page_id=784
      * 例:下载目录:bash /opt/ossutil/fyun-download.sh 4dkankan /home/XXX /mnt/XXX oss folder
      */
-    public static final String UPLOAD_SH = "sudo bash ".concat(shellPath).concat("/fyun-upload.sh %s %s /%s %s %s");
-    public static final String DOWNLOAD_SH = "sudo bash ".concat(shellPath).concat("/fyun-upload.sh %s /%s %s %s %s");
+    public String UPLOAD_SH;
+    public String DOWNLOAD_SH;
 
-    @Value("${fyun.shell.path:/opt/ossutil}")
-    public void setShellPath(String path){
-        FYunConstants.shellPath = path;
+    @PostConstruct
+    public void initSh(){
+        this.UPLOAD_SH = "sudo bash ".concat(shellPath).concat("/fyun-upload.sh %s %s /%s %s %s");
+        this.DOWNLOAD_SH = "sudo bash ".concat(shellPath).concat("/fyun-download.sh %s /%s %s %s %s");
     }
 }

+ 3 - 0
4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/face/AbstractFYunFileService.java

@@ -1,6 +1,7 @@
 package com.fdkankan.fyun.face;
 
 import com.fdkankan.fyun.config.FYunFileConfig;
+import com.fdkankan.fyun.constant.FYunConstants;
 import com.fdkankan.fyun.model.StreamGobbler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -18,6 +19,8 @@ public abstract class AbstractFYunFileService implements FYunFileServiceInterfac
 
     @Autowired
     public FYunFileConfig fYunFileConfig;
+    @Autowired
+    public FYunConstants fYunConstants;
 
     public String getFyunType(){
         return fYunFileConfig.getFyunType();

+ 2 - 2
4dkankan-utils-fyun-s3/src/main/java/com/fdkankan/fyun/s3/S3FileService.java

@@ -89,7 +89,7 @@ public class S3FileService extends AbstractFYunFileService {
     public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath){
         try {
             String optType = new File(filePath).isDirectory() ? "folder" : "file";
-            String command = String.format(FYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.AWS.code(), optType);
+            String command = String.format(fYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.AWS.code(), optType);
             log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
             callshell(command);
         } catch (Exception e) {
@@ -103,7 +103,7 @@ public class S3FileService extends AbstractFYunFileService {
     public void downloadFileByCommand(String bucket, String filePath, String remoteFilePath) {
         try {
             String optType = new File(filePath).isDirectory() ? "folder" : "file";
-            String command = String.format(FYunConstants.DOWNLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.AWS.code(), optType);
+            String command = String.format(fYunConstants.DOWNLOAD_SH, bucket, remoteFilePath, filePath, FYunTypeEnum.AWS.code(), optType);
             log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
             callshell(command);
         } catch (Exception e) {