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{
2023-12-03 03:47:23 +08:00
ID: file.ID,
Name: file.Name,
Type: file.Type,
MimeType: file.MimeType,
Path: file.Path,
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 {
2023-12-03 03:47:23 +08:00
parts := []schemas.Part{}
for _, part := range *file.Parts {
parts = append(parts, schemas.Part{
ID: part.ID,
Salt: part.Salt,
2023-12-03 03:47:23 +08:00
})
}
return &schemas.FileOutFull{
FileOut: ToFileOut(file),
Parts: parts,
ChannelID: *file.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
}