package com.bonus.canteen.core.common.utils;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
@Component
public class FileUrlUtil {
    @Value("${system.sysfile.bucket}")
    private String prefixBucket;
    @Value("${system.sysfile.prefixOnline}")
    private String prefEndpoint;

    private static String endpoint;
    private static String bucket;

    @PostConstruct
    public void init() {
        endpoint = this.prefEndpoint;
        bucket = this.prefixBucket;
    }

    public static String getFileUrl(String fileUrl) {
        if (ObjectUtil.isEmpty(fileUrl)){
            throw new ServiceException("照片路径为空");
        }
        return endpoint + "/" + fileUrl;
    }
}
