Commit ab43dfa 1 parent 0479069 commit ab43dfa Copy full SHA for ab43dfa
File tree 1 file changed +17
-7
lines changed
1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change 7
7
8
8
"github.com/gin-gonic/gin"
9
9
"github.com/kevinanielsen/go-fast-cdn/src/database"
10
+ "github.com/kevinanielsen/go-fast-cdn/src/models"
10
11
"github.com/kevinanielsen/go-fast-cdn/src/util"
11
12
)
12
13
@@ -65,14 +66,23 @@ func HandleDocUpload(c *gin.Context) {
65
66
return
66
67
}
67
68
68
- savedFileName , alreadyExists := database .AddDoc (filename , fileHashBuffer [:])
69
+ doc := models.Doc {
70
+ FileName : filename ,
71
+ Checksum : fileHashBuffer [:],
72
+ }
73
+
74
+ docInDatabase := database .GetDocByCheckSum (fileHashBuffer [:])
75
+ if len (docInDatabase .Checksum ) > 0 {
76
+ c .JSON (http .StatusConflict , "File already exists" )
77
+ return
78
+ }
69
79
70
- if ! alreadyExists {
71
- err = c . SaveUploadedFile ( fileHeader , util . ExPath + "/uploads/docs/" + filteredFilename )
72
- if err != nil {
73
- c . String ( http . StatusInternalServerError , "Failed to save file: %s" , err . Error ())
74
- return
75
- }
80
+ savedFileName := database . AddDoc ( doc )
81
+
82
+ err = c . SaveUploadedFile ( fileHeader , util . ExPath + "/uploads/docs/" + filteredFilename )
83
+ if err != nil {
84
+ c . String ( http . StatusInternalServerError , "Failed to save file: %s" , err . Error ())
85
+ return
76
86
}
77
87
78
88
body := gin.H {
You can’t perform that action at this time.
0 commit comments