package cn.com.capcloud.api.action.service.util;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author LiaoJiaHui
 * @Create 2026/4/29
 */
public class ResponseUtil {

    public static void setContentType(HttpServletResponse response, String suffix) {
        if (suffix == null) {
            return;
        }
        String contentType;
        switch (suffix.toLowerCase()) {
            case "png":
                contentType = "image/png";
                break;
            case "bmp":
                contentType = "image/bmp";
                break;
            case "gif":
                contentType = "image/gif";
                break;
            case "jpeg":
                contentType = "image/jpeg";
                break;
            case "tiff":
                contentType = "image/tiff";
                break;
            case "txt":
                contentType = "text/plain";
                break;
            case "pdf":
                contentType = "application/pdf";
                break;
            case "doc":
            case "docx":
                contentType = "application/msword";
                break;
            case "xls":
            case "xlsx":
                contentType = "application/vnd.ms-excel";
                break;
            default:
                return;
        }
        response.setContentType(contentType);
    }
}
