/** 
 | 
 * Copyright (c) 2018 人人开源 All rights reserved. 
 | 
 * 
 | 
 * https://www.renren.io 
 | 
 * 
 | 
 * 版权所有,侵权必究! 
 | 
 */ 
 | 
  
 | 
package com.zt.modules.oss.cloud; 
 | 
  
 | 
import cn.hutool.core.date.DateUtil; 
 | 
import com.zt.modules.oss.model.SysOss; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
  
 | 
import java.io.InputStream; 
 | 
import java.util.Date; 
 | 
import java.util.UUID; 
 | 
  
 | 
/** 
 | 
 * 云存储 
 | 
 * 
 | 
 * @author Mark sunlightcs@gmail.com 
 | 
 */ 
 | 
public abstract class AbstractStorageService { 
 | 
    /** 
 | 
     * 云存储配置信息 
 | 
     */ 
 | 
    StorageConfig config; 
 | 
  
 | 
    QdStorageConfig qdConfig; 
 | 
  
 | 
    /** 
 | 
     * 文件路径 
 | 
     * 
 | 
     * @param prefix 前缀 
 | 
     * @param suffix 后缀 
 | 
     * @return 返回上传路径 
 | 
     */ 
 | 
    public String getPath(String prefix, String suffix) { 
 | 
        // 生成uuid 
 | 
        String uuid = UUID.randomUUID().toString().replaceAll("-", ""); 
 | 
        // 文件路径 
 | 
        String path = DateUtil.format(new Date(), "yyyyMMdd") + "/" + uuid; 
 | 
  
 | 
        if (StringUtils.isNotBlank(prefix)) { 
 | 
            path = prefix + "/" + path; 
 | 
        } 
 | 
  
 | 
        return path + "." + suffix; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 文件上传 
 | 
     * 
 | 
     * @param data 
 | 
     *            文件字节数组 
 | 
     * @param path 
 | 
     *            文件路径,包含文件名 
 | 
     * @return 返回http地址 
 | 
     */ 
 | 
    public abstract SysOss upload(byte[] data, String path); 
 | 
  
 | 
    /** 
 | 
     * 文件上传 
 | 
     * 
 | 
     * @param data 
 | 
     *            文件字节数组 
 | 
     * @param suffix 
 | 
     *            后缀 
 | 
     * @return 返回http地址 
 | 
     */ 
 | 
    public abstract SysOss uploadSuffix(byte[] data, String suffix); 
 | 
  
 | 
    /** 
 | 
     * 文件上传 
 | 
     * 
 | 
     * @param inputStream 
 | 
     *            字节流 
 | 
     * @param path 
 | 
     *            文件路径,包含文件名 
 | 
     * @return 返回http地址 
 | 
     */ 
 | 
    public abstract SysOss upload(InputStream inputStream, String path); 
 | 
  
 | 
    /** 
 | 
     * 文件上传 
 | 
     * 
 | 
     * @param inputStream 
 | 
     *            字节流 
 | 
     * @param suffix 
 | 
     *            后缀 
 | 
     * @return 返回http地址 
 | 
     */ 
 | 
    public abstract SysOss uploadSuffix(InputStream inputStream, String suffix); 
 | 
  
 | 
    public abstract void delete(SysOss oss); 
 | 
  
 | 
    public StorageConfig getConfig() { 
 | 
        return config; 
 | 
    } 
 | 
  
 | 
    public QdStorageConfig getQdConfig() { 
 | 
        return qdConfig; 
 | 
    } 
 | 
} 
 |