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

import cn.hutool.core.util.ObjectUtil;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.houqin.constant.GlobalConstants;
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 (StringUtils.isNotEmpty(fileUrl)){
            if (fileUrl.startsWith(GlobalConstants.HTTP_PROTOCOL)) {
                return fileUrl;
            } else {
                return endpoint + "/" + fileUrl;
            }
        } else {
            return "";
        }
    }
}
