mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-10 03:03:43 +08:00
feat: delete the old avatar image file when update the user profile
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
||||
"chatplus/utils"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LocalStorageService struct {
|
||||
@@ -20,8 +22,8 @@ func NewLocalStorageService(config *types.AppConfig) LocalStorageService {
|
||||
}
|
||||
}
|
||||
|
||||
func (s LocalStorageService) PutFile(ctx *gin.Context) (string, error) {
|
||||
file, err := ctx.FormFile("file")
|
||||
func (s LocalStorageService) PutFile(ctx *gin.Context, name string) (string, error) {
|
||||
file, err := ctx.FormFile(name)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error with get form: %v", err)
|
||||
}
|
||||
@@ -54,4 +56,9 @@ func (s LocalStorageService) PutImg(imageURL string) (string, error) {
|
||||
return utils.GenUploadUrl(s.config.BasePath, s.config.BaseURL, filePath), nil
|
||||
}
|
||||
|
||||
func (s LocalStorageService) Delete(fileURL string) error {
|
||||
filePath := strings.Replace(fileURL, s.config.BaseURL, s.config.BasePath, 1)
|
||||
return os.Remove(filePath)
|
||||
}
|
||||
|
||||
var _ Uploader = LocalStorageService{}
|
||||
|
||||
Reference in New Issue
Block a user