fix: create post
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
|
||||
@@ -12,26 +13,14 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type MediaType string
|
||||
|
||||
const (
|
||||
MediaTypeUnknown MediaType = "unknown"
|
||||
MediaTypeArchive MediaType = "archive"
|
||||
MediaTypeImage MediaType = "image"
|
||||
MediaTypeVideo MediaType = "video"
|
||||
MediaTypeDocument MediaType = "document"
|
||||
MediaTypeAudio MediaType = "audio"
|
||||
MediaTypePDF MediaType = "pdf"
|
||||
)
|
||||
|
||||
type MediaItem struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
UploadTime string `json:"upload_time"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
MimeType string `json:"media_type"`
|
||||
FileType MediaType `json:"file_type"`
|
||||
ThumbnailUrl string `json:"thumbnail_url"`
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
UploadTime string `json:"upload_time"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
MimeType string `json:"media_type"`
|
||||
FileType fields.MediaAssetType `json:"file_type"`
|
||||
ThumbnailUrl string `json:"thumbnail_url"`
|
||||
}
|
||||
|
||||
// @provider
|
||||
@@ -150,30 +139,57 @@ func (m *mediasModel) Create(ctx context.Context, model *model.Medias) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mediasModel) ConvertFileTypeByMimeType(mimeType string) MediaType {
|
||||
func (m *mediasModel) ConvertFileTypeByMimeType(mimeType string) fields.MediaAssetType {
|
||||
switch mimeType {
|
||||
case "image/jpeg", "image/jpg", "image/png":
|
||||
return MediaTypeImage
|
||||
case "video/mp4":
|
||||
return MediaTypeVideo
|
||||
case "image/jpeg", "image/jpg", "image/png", "image/gif":
|
||||
return fields.MediaAssetTypeImage
|
||||
case "video/mp4", "video/x-m4v":
|
||||
return fields.MediaAssetTypeVideo
|
||||
case "audio/mpeg":
|
||||
return MediaTypeAudio
|
||||
case "application/pdf":
|
||||
return MediaTypePDF
|
||||
case "application/msword",
|
||||
return fields.MediaAssetTypeAudio
|
||||
case "application/pdf",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
||||
return MediaTypeDocument
|
||||
return fields.MediaAssetTypeDocument
|
||||
case "application/rar",
|
||||
"application/x-rar-compressed",
|
||||
"application/x-zip-compressed",
|
||||
"application/x-zip",
|
||||
"application/zip",
|
||||
"application/x-7z-compressed":
|
||||
return MediaTypeArchive
|
||||
return fields.MediaAssetTypeArchive
|
||||
}
|
||||
return MediaTypeUnknown
|
||||
return fields.MediaAssetTypeUnknown
|
||||
}
|
||||
|
||||
// GetByIds
|
||||
func (m *mediasModel) GetByIds(ctx context.Context, ids []int64) ([]*model.Medias, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
condIds := lo.Map(ids, func(id int64, _ int) Expression {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
tbl := table.Medias
|
||||
stmt := tbl.
|
||||
SELECT(tbl.AllColumns).
|
||||
WHERE(tbl.ID.IN(condIds...))
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var medias []model.Medias
|
||||
err := stmt.QueryContext(ctx, db, &medias)
|
||||
if err != nil {
|
||||
m.log.Errorf("error querying media items: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lo.Map(medias, func(media model.Medias, _ int) *model.Medias {
|
||||
return &media
|
||||
}), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user