This commit is contained in:
12600k-rog-d4
2025-12-09 20:33:57 +08:00
parent 144ed3cbdf
commit 8f4d399cfd
1498 changed files with 3778 additions and 3654 deletions

View File

@@ -0,0 +1,37 @@
package uploader
import (
"bbs-go/internal/pkg/config"
"mime"
"time"
"github.com/go-resty/resty/v2"
"github.com/mlogclub/simple/common/dates"
"github.com/mlogclub/simple/common/digests"
"github.com/mlogclub/simple/common/strs"
)
// generateKey 生成图片Key
func generateImageKey(data []byte, contentType string) string {
md5 := digests.MD5Bytes(data)
ext := ""
if strs.IsNotBlank(contentType) {
exts, err := mime.ExtensionsByType(contentType)
if err == nil || len(exts) > 0 {
ext = exts[0]
}
}
if config.Instance.IsProd() {
return "images/" + dates.Format(time.Now(), "2006/01/02/") + md5 + ext
} else {
return "test/images/" + dates.Format(time.Now(), "2006/01/02/") + md5 + ext
}
}
func download(url string) ([]byte, string, error) {
rsp, err := resty.New().R().Get(url)
if err != nil {
return nil, "", err
}
return rsp.Body(), rsp.Header().Get("Content-Type"), nil
}