2023-12-03 03:47:23 +08:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/divyam234/teldrive/pkg/models"
|
|
|
|
"github.com/divyam234/teldrive/pkg/schemas"
|
|
|
|
)
|
|
|
|
|
2023-12-03 07:03:16 +08:00
|
|
|
func ToFileOut(file models.File) schemas.FileOut {
|
|
|
|
var size int64
|
|
|
|
if file.Size != nil {
|
|
|
|
size = *file.Size
|
|
|
|
}
|
2023-12-03 03:47:23 +08:00
|
|
|
return schemas.FileOut{
|
|
|
|
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{
|
2023-12-08 15:46:05 +08:00
|
|
|
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,
|
2023-12-08 15:46:05 +08:00
|
|
|
Salt: in.Salt,
|
2023-12-03 03:47:23 +08:00
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|