mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-09-20 08:15:55 +08:00
fix: pass filename in get category
This commit is contained in:
parent
a7734821a1
commit
ddc1691ac0
53
internal/category/category_test.go
Normal file
53
internal/category/category_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
//gen test suite
|
||||
|
||||
package category
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetCategory(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileName string
|
||||
want Category
|
||||
}{
|
||||
{
|
||||
name: "Document",
|
||||
fileName: "file.doc",
|
||||
want: Document,
|
||||
},
|
||||
{
|
||||
name: "Image",
|
||||
fileName: "file.jpg",
|
||||
want: Image,
|
||||
},
|
||||
{
|
||||
name: "Video",
|
||||
fileName: "file.mp4",
|
||||
want: Video,
|
||||
},
|
||||
{
|
||||
name: "Audio",
|
||||
fileName: "file.mp3",
|
||||
want: Audio,
|
||||
},
|
||||
{
|
||||
name: "Archive",
|
||||
fileName: "file.zip",
|
||||
want: Archive,
|
||||
},
|
||||
{
|
||||
name: "Other",
|
||||
fileName: "file",
|
||||
want: Other,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetCategory(tt.fileName); got != tt.want {
|
||||
t.Errorf("GetCategory() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ func (fs *FileService) CreateFile(c *gin.Context, userId int64, fileIn *schemas.
|
|||
}
|
||||
fileDB.ChannelID = &channelId
|
||||
fileDB.MimeType = fileIn.MimeType
|
||||
fileDB.Category = string(category.GetCategory(fileIn.MimeType))
|
||||
fileDB.Category = string(category.GetCategory(fileIn.Name))
|
||||
parts := models.Parts{}
|
||||
for _, part := range fileIn.Parts {
|
||||
parts = append(parts, models.Part{
|
||||
|
|
Loading…
Reference in a new issue