package com.zhongshu.card.server.core.util.oss;

import org.springframework.util.Assert;

import java.util.Collection;

/**
 * 校验路径的合法性
 */
public class PathAssert {
    private final static String Regex = "^[^\\/:*?\"\"<>|\\\\]+$";


    /**
     * 校验文件路径
     *
     * @param paths
     */
    public static void validate(String... paths) {
        for (String path : paths) {
            Assert.state(isValidPath(path), "文件名不合法");
        }
    }

    /**
     * 校验文件路径
     *
     * @param paths
     */
    public static void validate(Collection<String[]> paths) {
        for (String[] path : paths) {
            validate(path);
        }
    }


    private static boolean isValidPath(String path) {
        return path.matches(Regex);
    }


}
