add md5 hash for file info

This commit is contained in:
r0n1n7an 2024-08-14 09:57:59 +08:00
parent f17d9d9801
commit a8823dcb19
2 changed files with 6 additions and 4 deletions

Binary file not shown.

View File

@ -3,6 +3,8 @@ package main
import (
"APIServer/cnf"
"APIServer/ews"
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"flag"
@ -311,7 +313,7 @@ func handleFileInfo(w http.ResponseWriter, r *http.Request) {
FileName string `json:"FileName"`
FileSize int64 `json:"FileSize"`
LastModified string `json:"LastModified"`
//MD5Hash string `json:"MD5Hash"`
MD5Hash string `json:"MD5Hash"`
}
type FileList struct {
FileList []FileInfo `json:"FileList"`
@ -324,7 +326,7 @@ func handleFileInfo(w http.ResponseWriter, r *http.Request) {
fileInfo.FileName = info.Name()
fileInfo.FileSize = info.Size()
fileInfo.LastModified = info.ModTime().Format("2006-01-02 15:04:05")
//fileInfo.MD5Hash = fileMD5(path)
fileInfo.MD5Hash = fileMD5(path)
infoList = append(infoList, fileInfo)
}
return nil
@ -471,7 +473,7 @@ func parseReqParams(r *http.Request) (map[string]string, error) {
return params, nil
}
/* func fileMD5(filePath string) string {
func fileMD5(filePath string) string {
file, err := os.Open(filePath)
if err != nil {
return ""
@ -482,7 +484,7 @@ func parseReqParams(r *http.Request) (map[string]string, error) {
return ""
}
return hex.EncodeToString(hash.Sum(nil))
} */
}
func chkParams(arg string) bool {
if strings.Contains(arg, ";") ||