package com.qmth.boot.core.fss.utils;

import com.qmth.boot.core.fss.config.FileStoreProperty;
import com.qmth.boot.core.fss.store.FileStore;
import com.qmth.boot.core.fss.store.impl.DiskStore;
import com.qmth.boot.core.fss.store.impl.OssStore;
import org.apache.commons.lang3.StringUtils;

public class FileStoreBuilder {

    public static FileStore buildFileStore(FileStoreProperty fileStoreProperty) {
        String server = StringUtils.trimToEmpty(fileStoreProperty.getServer());
        if (!server.endsWith(FssUtils.FILE_PATH_SEPARATOR)) {
            server = server.concat(FssUtils.FILE_PATH_SEPARATOR);
        }
        String config = fileStoreProperty.getConfig();
        if (config.startsWith("oss://")) {
            return new OssStore(server, config);
        } else {
            return new DiskStore(server, config, System.getProperty("java.io.tmpdir"));
        }
    }
}
