package utils

import (
	"io"
	"mime"
	"path/filepath"
)

func GetContentType(filePath string, body []byte) (string, error) {

	contentType := ""
	if len(filePath) > 0 {
		ext := filepath.Ext(filePath)
		// 根据扩展名获取 MIME 类型
		contentType = mime.TypeByExtension(ext)
	}

	//if contentType == "" {
	//
	//	contentType = http.DetectContentType(body)
	//}

	return contentType, nil
}

func GetContentTypeForIoRead(filePath string, body io.Reader) (string, error) {

	//buffer := make([]byte, 512) // 读取文件的前 512 字节用于检测内容类型
	//_, err := body.Read(buffer)
	//if err != nil {
	//	return "", err
	//}
	return GetContentType(filePath, nil)
}

// 获取存储类型
func GetStoreType(key string) (storeType string) {
	switch key {
	case "0":
		storeType = "oss"
	case "1":
		storeType = "cos"
	case "2":
		storeType = "asw"
	case "3":
		storeType = "local"
	}

	return storeType
}