- Updated the API base URLs in app.js to point to local development server for testing. - Enhanced SVG icons with gradient fills for improved visual appeal across various components. - Refactored the avatar upload functionality in avatar-nickname.js and profile-edit.js to utilize a new upload utility for better code maintainability. - Improved the layout and styling of the my page and super article editor for a more user-friendly interface. This update aims to streamline development processes and enhance the overall user experience in the application.
34 lines
980 B
Go
34 lines
980 B
Go
package handler
|
||
|
||
import (
|
||
"bytes"
|
||
"fmt"
|
||
"io"
|
||
"mime/multipart"
|
||
"path/filepath"
|
||
|
||
alioss "github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||
|
||
soulOss "soul-api/internal/oss"
|
||
)
|
||
|
||
// ossUploadFile / ossUploadBytes 统一走 internal/oss.Upload(与 POST …/upload 同源:system_config.oss_config + ObjectPublicURL)。
|
||
|
||
func ossUploadFile(file multipart.File, folder, filename string) (string, error) {
|
||
data, err := io.ReadAll(file)
|
||
if err != nil {
|
||
return "", fmt.Errorf("读取文件失败: %w", err)
|
||
}
|
||
objectKey := filepath.ToSlash(filepath.Join("uploads", folder, filename))
|
||
return soulOss.Upload(objectKey, bytes.NewReader(data))
|
||
}
|
||
|
||
func ossUploadBytes(data []byte, folder, filename, contentType string) (string, error) {
|
||
objectKey := filepath.ToSlash(filepath.Join("uploads", folder, filename))
|
||
var opts []alioss.Option
|
||
if contentType != "" {
|
||
opts = append(opts, alioss.ContentType(contentType))
|
||
}
|
||
return soulOss.Upload(objectKey, bytes.NewReader(data), opts...)
|
||
}
|