feat (minio): done, upload wip
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package uploadhelper
|
||||
|
||||
type UploadResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url,omitempty"`
|
||||
FileName string `json:"filename,omitempty"`
|
||||
}
|
||||
|
||||
type MultipleUploadResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
TotalFiles int `json:"total_files"`
|
||||
SuccessCount int `json:"success_count"`
|
||||
Results []UploadResponse `json:"results"`
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package uploadhelper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
ere "simrs-vx/internal/domain/references/encounter"
|
||||
)
|
||||
|
||||
func getBucketForType(docType string) (string, error) {
|
||||
switch strings.ToLower(docType) {
|
||||
case "resident", "resident-number", "ktp":
|
||||
return string(ere.UCPRN), nil
|
||||
case "driver-license", "sim", "license":
|
||||
return string(ere.UCPDL), nil
|
||||
case "passport", "paspor":
|
||||
return string(ere.UCPP), nil
|
||||
case "family-card", "kk", "family":
|
||||
return string(ere.UCPFC), nil
|
||||
case "mcu", "medical", "mcu-result":
|
||||
return string(ere.UCMIR), nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown document type: %s", docType)
|
||||
}
|
||||
}
|
||||
|
||||
// getValidFileTypesForBucket returns allowed file types for each bucket
|
||||
func getValidFileTypesForBucket(bucketName string) []string {
|
||||
switch bucketName {
|
||||
case string(ere.UCPRN), string(ere.UCPDL), string(ere.UCPP), string(ere.UCPFC):
|
||||
return []string{".jpg", ".jpeg", ".png", ".pdf", ".gif"}
|
||||
case string(ere.UCMIR):
|
||||
return []string{".jpg", ".jpeg", ".png", ".pdf", ".gif", ".doc", ".docx", ".xls", ".xlsx"}
|
||||
default:
|
||||
return []string{".jpg", ".jpeg", ".png", ".pdf"}
|
||||
}
|
||||
}
|
||||
|
||||
// isValidFileType checks if the uploaded file type is allowed for the specific bucket
|
||||
func isValidFileType(filename, bucketName string) bool {
|
||||
allowedTypes := getValidFileTypesForBucket(bucketName)
|
||||
ext := strings.ToLower(filepath.Ext(filename))
|
||||
|
||||
for _, allowedExt := range allowedTypes {
|
||||
if ext == allowedExt {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// getContentType determines the content type based on file extension
|
||||
func getContentType(filename string) string {
|
||||
switch strings.ToLower(filepath.Ext(filename)) {
|
||||
case ".jpg", ".jpeg":
|
||||
return "image/jpeg"
|
||||
case ".png":
|
||||
return "image/png"
|
||||
case ".pdf":
|
||||
return "application/pdf"
|
||||
case ".gif":
|
||||
return "image/gif"
|
||||
case ".doc":
|
||||
return "application/msword"
|
||||
case ".docx":
|
||||
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
case ".xls":
|
||||
return "application/vnd.ms-excel"
|
||||
case ".xlsx":
|
||||
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
default:
|
||||
return "application/octet-stream"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user