package com.ms.biz.paas;

import com.ms.biz.common.Ret;
import com.ms.biz.tool.TosTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 对象存储服务
 * 这边是火山引擎的TOS服务
 */
@Slf4j
@Component
public class StorageService {

    @Autowired
    private TosTemplate tosTemplate;

    public Ret getContent(String ossPath) {
        return tosTemplate.download2Mem(ossPath);
    }

    public Ret uploadContent(String ossPath, String content) {
        return tosTemplate.upload(ossPath,content);
    }

    public Ret uploadContent(String ossPath, byte[] newImageData) {
        return tosTemplate.upload(ossPath,newImageData);
    }

    public String getPubOssUrlByOssPath(String ossPath) {
        // 云内环境的domain要根据实际情况替换
        return tosTemplate.getDomain() + ossPath;
    }

    public Ret delete(String ossPath) {
        return tosTemplate.delete(ossPath);
    }
}
