2023-12-03 03:47:23 +08:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
import (
|
2024-12-31 03:19:28 +08:00
|
|
|
"github.com/tgdrive/teldrive/internal/api"
|
2024-08-31 23:50:17 +08:00
|
|
|
"github.com/tgdrive/teldrive/pkg/models"
|
2023-12-03 03:47:23 +08:00
|
|
|
)
|
|
|
|
|
2024-12-31 03:19:28 +08:00
|
|
|
func ToFileOut(file models.File, extended bool) *api.File {
|
|
|
|
res := &api.File{
|
|
|
|
ID: api.NewOptString(file.Id),
|
2023-12-03 03:47:23 +08:00
|
|
|
Name: file.Name,
|
2024-12-31 03:19:28 +08:00
|
|
|
Type: api.FileType(file.Type),
|
|
|
|
MimeType: api.NewOptString(file.MimeType),
|
|
|
|
Encrypted: api.NewOptBool(file.Encrypted),
|
|
|
|
ParentId: api.NewOptString(file.ParentID.String),
|
|
|
|
UpdatedAt: api.NewOptDateTime(file.UpdatedAt),
|
2023-12-03 03:47:23 +08:00
|
|
|
}
|
2024-12-31 03:19:28 +08:00
|
|
|
if file.Size != nil {
|
|
|
|
res.Size = api.NewOptInt64(*file.Size)
|
2023-12-03 03:47:23 +08:00
|
|
|
}
|
2024-12-31 03:19:28 +08:00
|
|
|
if file.Category != "" {
|
|
|
|
res.Category = api.NewOptFileCategory(api.FileCategory(file.Category))
|
|
|
|
}
|
|
|
|
if extended {
|
|
|
|
res.Parts = file.Parts
|
|
|
|
if file.ChannelID != nil {
|
|
|
|
res.ChannelId = api.NewOptInt64(*file.ChannelID)
|
|
|
|
}
|
2023-12-03 03:47:23 +08:00
|
|
|
}
|
2024-12-31 03:19:28 +08:00
|
|
|
return res
|
2023-12-03 03:47:23 +08:00
|
|
|
}
|