Ver Fonte

路径补全

xiatian há 5 anos atrás
pai
commit
0a0d42f577

+ 23 - 1
src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageUtil.java

@@ -239,5 +239,27 @@ public class FileStorageUtil {
 		return fileStorageType;
 	}
 	
-	
+	/**获取完整的不带域名的路径
+	 * @param prefixPath 路径前缀
+	 * @param sourcePath 数据库存储的路径
+	 * @return 处理之后的路径
+	 */
+	public static String getIntactPath(String prefixPath,String sourcePath) {
+		// 如果是全路径直接返回
+		if (sourcePath.startsWith("http") || sourcePath.startsWith("https")) {
+			return sourcePath;
+		}
+		// 如果是半路径,转换成又拍云类型
+		if (sourcePath.indexOf(":") == -1) {
+			if (sourcePath.startsWith("/")) {
+				sourcePath = sourcePath.substring(1);
+			}
+			if (prefixPath.endsWith("/")) {
+				prefixPath = prefixPath.substring(0,prefixPath.length());
+			}
+			return prefixPath+"/"+sourcePath;
+		}
+		// 新协议无需处理
+		return sourcePath;
+	}
 }