| | |
| | | if (storageBlob == null || !StringUtils.hasText(storageBlob.getUidFilename())) { |
| | | throw new IllegalArgumentException("文件信息不完整"); |
| | | } |
| | | String domain = StringUtils.trimTrailingCharacter(properties.getDomain(), '/'); |
| | | String prefix = properties.getUrlPrefix().startsWith("/") ? properties.getUrlPrefix() : "/" + properties.getUrlPrefix(); |
| | | String normalizedActionPath = StringUtils.hasText(actionPath) ? actionPath : "/preview/"; |
| | | if (!normalizedActionPath.startsWith("/")) { |
| | | normalizedActionPath = "/" + normalizedActionPath; |
| | | } |
| | | if (!normalizedActionPath.endsWith("/")) { |
| | | normalizedActionPath = normalizedActionPath + "/"; |
| | | } |
| | | String baseUrl = domain + prefix + normalizedActionPath + storageBlob.getUidFilename(); |
| | | |
| | | // -1 表示永久有效,不生成 token,改为 publicKey 组合校验 |
| | | if (expired != null && BigDecimal.valueOf(-1L).compareTo(expired) == 0) { |
| | | if (!StringUtils.hasText(storageBlob.getResourceKey())) { |
| | | throw new IllegalArgumentException("公开链接缺少publicKey"); |
| | | } |
| | | return baseUrl + "?publicKey=" + storageBlob.getResourceKey(); |
| | | } |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | long expiredMillis = expired.multiply(new BigDecimal("60000")).longValue(); |
| | | BigDecimal expiredValue = expired == null ? new BigDecimal("120") : expired; |
| | | long expiredMillis = expiredValue.multiply(new BigDecimal("60000")).longValue(); |
| | | if (expiredMillis <= 0L) { |
| | | expiredMillis = 2L * 60L * 60L * 1000L; |
| | | } |
| | |
| | | .signWith(key) // 重点:传入上面生成的 key 对象,而不是 String |
| | | .compact(); |
| | | cacheTokenUsage(token, expiredMillis); |
| | | String domain = StringUtils.trimTrailingCharacter(properties.getDomain(), '/'); |
| | | String prefix = properties.getUrlPrefix().startsWith("/") ? properties.getUrlPrefix() : "/" + properties.getUrlPrefix(); |
| | | String normalizedActionPath = StringUtils.hasText(actionPath) ? actionPath : "/preview/"; |
| | | if (!normalizedActionPath.startsWith("/")) { |
| | | normalizedActionPath = "/" + normalizedActionPath; |
| | | } |
| | | if (!normalizedActionPath.endsWith("/")) { |
| | | normalizedActionPath = normalizedActionPath + "/"; |
| | | } |
| | | return domain + prefix + normalizedActionPath + storageBlob.getUidFilename() + "?token=" + token; |
| | | return baseUrl + "?token=" + token; |
| | | } |
| | | |
| | | private void cacheTokenUsage(String token, long expiredMillis) { |