teldrive/pkg/mapper/mapper.go

55 lines
1.1 KiB
Go
Raw Normal View History

2023-12-03 03:47:23 +08:00
package mapper
import (
"github.com/divyam234/teldrive/pkg/models"
"github.com/divyam234/teldrive/pkg/schemas"
)
func ToFileOut(file models.File) *schemas.FileOut {
2023-12-03 07:03:16 +08:00
var size int64
if file.Size != nil {
size = *file.Size
}
return &schemas.FileOut{
Id: file.Id,
2023-12-03 03:47:23 +08:00
Name: file.Name,
Type: file.Type,
MimeType: file.MimeType,
2024-04-19 04:46:47 +08:00
Category: file.Category,
2024-04-19 16:39:44 +08:00
Encrypted: file.Encrypted,
2023-12-03 07:03:16 +08:00
Size: size,
2023-12-03 03:47:23 +08:00
Starred: file.Starred,
ParentID: file.ParentID,
UpdatedAt: file.UpdatedAt,
}
}
2023-12-03 07:03:16 +08:00
func ToFileOutFull(file models.File) *schemas.FileOutFull {
2024-06-04 16:46:03 +08:00
var channelId int64
if file.ChannelID != nil {
channelId = *file.ChannelID
2023-12-03 03:47:23 +08:00
}
return &schemas.FileOutFull{
FileOut: ToFileOut(file),
2024-06-04 16:46:03 +08:00
Parts: file.Parts,
ChannelID: channelId,
2023-12-08 05:46:06 +08:00
Encrypted: file.Encrypted,
2023-12-03 03:47:23 +08:00
}
}
func ToUploadOut(in *models.Upload) *schemas.UploadPartOut {
out := &schemas.UploadPartOut{
Name: in.Name,
PartId: in.PartId,
ChannelID: in.ChannelID,
PartNo: in.PartNo,
Size: in.Size,
2023-12-08 06:05:40 +08:00
Encrypted: in.Encrypted,
Salt: in.Salt,
2023-12-03 03:47:23 +08:00
}
return out
}