xiatian hace 5 años
padre
commit
259320e730

+ 2 - 2
src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorage.java

@@ -25,13 +25,13 @@ public interface FileStorage {
 	public YunPathInfo saveFile(String siteId,FileStoragePathEnvInfo env,File file,String md5);
 	
 	/**获取可直接访问的文件地址
-	 * @param path 全路径,包含根目录,含协议名
+	 * @param path 全路径,包含根目录,含协议名
 	 * @return 返回可直接访问的地址
 	 */
 	public String realPath(String path);
 	
 	/**获取可直接访问的文件地址(备用域名地址)
-	 * @param path 全路径,包含根目录,含协议名
+	 * @param path 全路径,包含根目录,含协议名
 	 * @return 返回可直接访问的地址,如果没有配置备用地址,则返回主域名地址
 	 */
 	public String realPathBackup(String path);

+ 32 - 3
src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageUtil.java

@@ -123,6 +123,9 @@ public class FileStorageUtil {
 	 * @return 可直接访问的文件地址
 	 */
 	public static String realPath(String path) {
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 
 		if (StringUtils.isBlank(path)) {
 			throw new StatusException("3001", "文件路径是空");
@@ -149,6 +152,7 @@ public class FileStorageUtil {
 	 * @return 转换之后的路径
 	 */
 	public static String transPath(String path, FileStorageType transFsType) {
+		
 		File file = null;
 		if (StringUtils.isBlank(path)) {
 			throw new StatusException("4001", "文件路径是空");
@@ -203,6 +207,9 @@ public class FileStorageUtil {
 	 * @return 处理后的路径。补全路径头。
 	 */
 	private static String diposeOldPath(String path) {
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 		// 如果是全路径直接返回
 		if (path.startsWith("http") || path.startsWith("https")) {
 			return path;
@@ -219,8 +226,13 @@ public class FileStorageUtil {
 	}
 
 
-
 	public static String getUrl(String domain, String path) {
+		if(StringUtils.isBlank(domain)) {
+			return null;
+		}
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 		if (path.startsWith("/")) {
 			path = path.substring(1);
 		}
@@ -295,11 +307,14 @@ public class FileStorageUtil {
 	 * @return 处理之后的路径
 	 */
 	public static String getIntactPath(String prefixPath,String sourcePath) {
+		if(StringUtils.isBlank(sourcePath)) {
+			return null;
+		}
 		// 如果是全路径直接返回
 		if (sourcePath.startsWith("http") || sourcePath.startsWith("https")) {
 			return sourcePath;
 		}
-		// 如果是半路径,转换成又拍云类型
+		// 如果是半路径则拼接
 		if (sourcePath.indexOf(":") == -1) {
 			if (sourcePath.startsWith("/")) {
 				sourcePath = sourcePath.substring(1);
@@ -318,6 +333,9 @@ public class FileStorageUtil {
 	 * @param path 全路径,包含根目录,含协议名
 	 */
 	public static void deleteFile(String path) {
+		if(StringUtils.isBlank(path)) {
+			return;
+		}
 		path=diposeOldPath(path);
 		// 如果是全路径直接返回
 		if (path.startsWith("http") || path.startsWith("https")) {
@@ -334,7 +352,9 @@ public class FileStorageUtil {
 	 * @return 可直接访问的文件地址,如果没有配置备用地址,则返回主域名地址
 	 */
 	public static String realPathBackup(String path) {
-
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 		if (StringUtils.isBlank(path)) {
 			throw new StatusException("6001", "文件路径是空");
 		}
@@ -352,6 +372,9 @@ public class FileStorageUtil {
 	}
 	
 	public static String getYunId(String path) {
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 		if(path.indexOf(connector)==-1) {
 			throw new StatusException("7001", "文件路径格式错误:"+path);
 		}
@@ -367,6 +390,9 @@ public class FileStorageUtil {
 	}
 
 	public static String getHead(String path) {
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 		if(path.indexOf(connector)==-1) {
 			throw new StatusException("8001", "文件路径格式错误:"+path);
 		}
@@ -382,6 +408,9 @@ public class FileStorageUtil {
 	}
 
 	public static String getPath(String path) {
+		if(StringUtils.isBlank(path)) {
+			return null;
+		}
 		if(path.indexOf(connector)==-1) {
 			throw new StatusException("9001", "文件路径格式错误:"+path);
 		}

+ 6 - 1
src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/UpyunFileStorageImpl.java

@@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.web.filestorage.FileStorage;
 import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
 import cn.com.qmth.examcloud.web.filestorage.FileStorageType;
@@ -27,7 +29,7 @@ import cn.com.qmth.examcloud.web.upyun.UpyunSiteManager;
 
 @Service(value = "upyunFileStorage")
 public class UpyunFileStorageImpl implements FileStorage {
-	
+	protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
 	@Autowired
 	private UpyunService upyunService;
 
@@ -41,8 +43,11 @@ public class UpyunFileStorageImpl implements FileStorage {
 
 	@Override
 	public String realPath(String path) {
+		log.error("path:"+path);
 		String upyunId=FileStorageUtil.getYunId(path);
+		log.error("upyunId:"+upyunId);
 		String urlpath=FileStorageUtil.getPath(path);
+		log.error("urlpath:"+urlpath);
 		UpYunClient c=UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
 		return FileStorageUtil.getUrl(c.getDomain(), urlpath);
 	}