Browse Source

影像二开下载测试2

turborao 2 days ago
parent
commit
97c83bc59e

+ 58 - 0
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/form/ViewImageByDownloadFilePlugin.java

@@ -2,11 +2,16 @@ package nckd.jimin.jyyy.fi.plugin.form;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import kd.bos.context.RequestContext;
 import kd.bos.dataentity.utils.StringUtils;
+import kd.bos.fileservice.path.DecodeFileFactory;
 import kd.bos.form.control.events.ItemClickEvent;
 import kd.bos.form.plugin.AbstractFormPlugin;
 import kd.bos.logging.Log;
 import kd.bos.logging.LogFactory;
+import kd.bos.session.SessionDAO;
+import kd.bos.session.SessionDAOFactory;
+import kd.bos.url.UrlService;
 import kd.imc.bds.common.utils.UrlServiceUtils;
 import kd.imc.bds.common.utils.ViewUtil;
 import kd.sdk.plugin.Plugin;
@@ -81,4 +86,57 @@ public class ViewImageByDownloadFilePlugin extends AbstractFormPlugin implements
         }
     }
 
+    public static String getDownloadUrl(String path) {
+        if (StringUtils.isNotEmpty(path)) {
+            if (path.startsWith("http")) {
+                return getCsPath(path);
+            } else {
+                String arfterDecodePath = DecodeFileFactory.getDecodeService().getDecodeFilePath(path);
+                logger.info("ViewImages arfterDecodePath: " + arfterDecodePath);
+                if (arfterDecodePath.startsWith("http")) {
+                    return getCsPath(arfterDecodePath);
+                } else {
+                    String previewUrl = UrlService.getAttachmentFullUrl(arfterDecodePath);
+                    logger.info("ViewImages previewUrl: " + previewUrl);
+                    return getCsPath(previewUrl);
+                }
+            }
+        } else {
+            return path;
+        }
+    }
+
+    public static String getCsPath(String path) {
+        if (StringUtils.isNotEmpty(path) && !path.contains("kd_cs_ticket")) {
+            String csTicketSuffix = getCsTicketSuffix();
+            if (path.contains("?")) {
+                path = path + "&" + csTicketSuffix;
+            } else {
+                path = path + "?" + csTicketSuffix;
+            }
+            logger.info("ViewImages path1: " + path);
+            return path;
+        } else {
+            logger.info("ViewImages path2: " + path);
+            return path;
+        }
+    }
+    public static String getCsTicketSuffix() {
+        String kdCsTicket = getCsrfToken(RequestContext.get().getGlobalSessionId());
+        String kdCsTicketSuffix = "kd_cs_ticket=" + kdCsTicket;
+        return kdCsTicketSuffix;
+    }
+    public static String getCsrfToken(String sessionId) {
+        String returnValue = "";
+        if (StringUtils.isNotEmpty(sessionId)) {
+            SessionDAO sessionDAO = SessionDAOFactory.getSessionDAO(sessionId);
+            Map<String, String> sessionInfo = sessionDAO.getAttributesAsMap(new String[]{"kdCsrfToken"});
+            if (sessionInfo != null && sessionInfo.size() > 0) {
+                returnValue = (String)sessionInfo.get("kdCsrfToken");
+            }
+        }
+
+        return returnValue;
+    }
+
 }