Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发图片语音时文件已存在则跳过保存 #208

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions server/uploadpic.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ func UploadBase64ImageHandler(rateLimiter *RateLimiter) gin.HandlerFunc {
return
}

err = os.WriteFile(savePath, imageBytes, 0644)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error saving file"})
return
//如果文件存在则跳过
if _, err := os.Stat(savePath); os.IsNotExist(err) {
err = os.WriteFile(savePath, imageBytes, 0644)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error saving file"})
return
}
} else {
mylog.Println("File already exists, skipping save.")
}

var serverPort string
serverAddress := config.GetServer_dir()
frpport := config.GetFrpPort()
Expand Down Expand Up @@ -146,11 +152,16 @@ func UploadBase64RecordHandler(rateLimiter *RateLimiter) gin.HandlerFunc {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error creating directory"})
return
}

err = os.WriteFile(savePath, RecordBytes, 0644)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error saving file"})
return

//如果文件存在则跳过
if _, err := os.Stat(savePath); os.IsNotExist(err) {
err = os.WriteFile(savePath, RecordBytes, 0644)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error saving file"})
return
}
} else {
mylog.Println("File already exists, skipping save.")
}

serverAddress := config.GetServer_dir()
Expand Down
Loading