feat(GODT-2948): Add used space per product to user info

This commit is contained in:
Leander Beernaert
2023-09-27 11:11:10 +02:00
committed by LBeernaertProton
parent 331ad8e6d5
commit f1adb1492e
2 changed files with 35 additions and 4 deletions

View File

@@ -17,7 +17,28 @@ import (
func (b *Backend) GetUser(userID string) (proton.User, error) {
return withAcc(b, userID, func(acc *account) (proton.User, error) {
return acc.toUser(), nil
return withMessages(b, func(m map[string]*message) (proton.User, error) {
return withAtts(b, func(attachments map[string]*attachment) (proton.User, error) {
user := acc.toUser()
var messageBytes uint64
for _, v := range m {
if _, ok := acc.addresses[v.addrID]; ok {
messageBytes += uint64(len(v.armBody))
}
for _, a := range v.attIDs {
if attach, ok := attachments[a]; ok {
messageBytes += uint64(len(b.attData[attach.attDataID]))
}
}
}
user.ProductUsedSpace.Mail = messageBytes
return user, nil
})
})
})
}

View File

@@ -7,12 +7,14 @@ type User struct {
Email string
Keys Keys
UsedSpace int
MaxSpace int
MaxUpload int
UsedSpace uint64
MaxSpace uint64
MaxUpload uint64
Credit int
Currency string
ProductUsedSpace ProductUsedSpace
}
type DeleteUserReq struct {
@@ -20,3 +22,11 @@ type DeleteUserReq struct {
Feedback string
Email string
}
type ProductUsedSpace struct {
Calendar uint64
Contact uint64
Drive uint64
Mail uint64
Pass uint64
}