|
@@ -3,6 +3,7 @@ package cn.rankin.resourceservice.service;
|
|
|
import cn.rankin.common.utils.api.model.APICode;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
|
+import cn.rankin.common.utils.constant.ResourceType;
|
|
|
import cn.rankin.common.utils.dto.resource.ResourceSearchDTO;
|
|
|
import cn.rankin.resourceservice.dto.ResourceDetail;
|
|
|
import cn.rankin.resourceservice.dto.ResourceRemote;
|
|
@@ -13,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -29,8 +31,11 @@ public class ResourceService {
|
|
|
@Autowired
|
|
|
private RemoteResourceProxy resourceProxy;
|
|
|
|
|
|
- @Value("${resource.url.domain}")
|
|
|
- private String domain;
|
|
|
+ @Value("${resource.img.domain}")
|
|
|
+ private String imgDomain;
|
|
|
+
|
|
|
+ @Value("${resource.video.domain}")
|
|
|
+ private String videoDomain;
|
|
|
|
|
|
public boolean exists(String code) {
|
|
|
Long count = resourceRepository.countByCode(code);
|
|
@@ -136,18 +141,30 @@ public class ResourceService {
|
|
|
}
|
|
|
|
|
|
public void initResourceUrl(Resource resource) {
|
|
|
- if (resource == null || domain == null) {
|
|
|
- log.error("domain is null");
|
|
|
+ if (resource == null) {
|
|
|
return;
|
|
|
}else if (resource.getPath() == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
String path = resource.getPath();
|
|
|
- if (path.startsWith("/")) {
|
|
|
- resource.setUrl(domain + path);
|
|
|
+ if (ResourceType.AUDIO == resource.getType()) {
|
|
|
+ resource.setUrl(concatUrl(videoDomain, path));
|
|
|
+ }else if (ResourceType.IMG == resource.getType()) {
|
|
|
+ resource.setUrl(concatUrl(imgDomain, path));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String concatUrl(String domain, String path) {
|
|
|
+ if (StringUtils.isEmpty(domain) || StringUtils.isEmpty(path)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (path.startsWith("/") && domain.endsWith("/")) {
|
|
|
+ return domain.substring(0, domain.length()) + path;
|
|
|
+ }else if(path.startsWith("/") || domain.endsWith("/")){
|
|
|
+ return domain + path;
|
|
|
}else {
|
|
|
- resource.setUrl(domain + '/' + path);
|
|
|
+ return domain + "/" + path;
|
|
|
}
|
|
|
}
|
|
|
}
|