package com.oying.modules.pc.utils;
|
|
import com.oying.domain.BucketStorage;
|
import com.oying.exception.EntityNotFoundException;
|
import com.oying.service.BucketStorageService;
|
import com.oying.utils.ObsProperties;
|
import com.oying.utils.ObsUtils;
|
import com.oying.utils.SpringBeanHolder;
|
|
import java.util.Optional;
|
|
public class ImageUtils {
|
|
private final static ObsProperties properties = SpringBeanHolder.getBean(ObsProperties.class);
|
private final static BucketStorageService bucketStorageService = SpringBeanHolder.getBean(BucketStorageService.class);
|
|
public static String getPublicObjectUrl(String path) {
|
return ObsUtils.getPublicObjectUrl(properties, path);
|
}
|
|
public static String getPublicObjectUrl(Long storageId) {
|
return Optional.ofNullable(storageId).map(v -> {
|
BucketStorage bucketStorage = bucketStorageService.getById(storageId);
|
String path = Optional.ofNullable(bucketStorage)
|
.map(BucketStorage::getPath)
|
.orElseThrow(() -> new EntityNotFoundException(BucketStorage.class, "bucketStorageId", storageId.toString()));
|
return getPublicObjectUrl(path);
|
}).orElse(null);
|
}
|
|
}
|