zepengdev
2025-06-14 6e0a83c55db4bae4d23a4c281946bda1d610f678
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
    }
 
}