2020-04-03 18:08:49 +02:00
|
|
|
package query
|
|
|
|
|
2020-04-04 13:53:52 +02:00
|
|
|
import (
|
|
|
|
"time"
|
2020-04-03 18:08:49 +02:00
|
|
|
|
2020-04-04 13:53:52 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FileShares returns up to 100 file shares for a given account id and status.
|
2020-05-08 15:41:01 +02:00
|
|
|
func FileShares(accountId uint, status string) (result []entity.FileShare, err error) {
|
|
|
|
s := Db().Where(&entity.FileShare{})
|
2020-04-03 18:08:49 +02:00
|
|
|
|
|
|
|
if accountId > 0 {
|
2022-10-15 21:54:11 +02:00
|
|
|
s = s.Where("service_id = ?", accountId)
|
2020-04-03 18:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != "" {
|
|
|
|
s = s.Where("status = ?", status)
|
|
|
|
}
|
|
|
|
|
|
|
|
s = s.Order("created_at ASC")
|
|
|
|
s = s.Limit(100).Offset(0)
|
|
|
|
|
|
|
|
s = s.Preload("File")
|
|
|
|
|
|
|
|
if err := s.Find(&result).Error; err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
2020-04-04 13:53:52 +02:00
|
|
|
|
|
|
|
// ExpiredFileShares returns up to 100 expired file shares for a given account.
|
2022-10-15 21:54:11 +02:00
|
|
|
func ExpiredFileShares(account entity.Service) (result []entity.FileShare, err error) {
|
2020-04-04 13:53:52 +02:00
|
|
|
if account.ShareExpires <= 0 {
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
s := Db().Where(&entity.FileShare{})
|
2020-04-04 13:53:52 +02:00
|
|
|
|
2020-04-04 17:19:34 +02:00
|
|
|
exp := time.Now().Add(time.Duration(-1*account.ShareExpires) * time.Second)
|
2020-04-04 13:53:52 +02:00
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
s = s.Where("service_id = ?", account.ID)
|
2020-04-04 13:53:52 +02:00
|
|
|
s = s.Where("status = ?", entity.FileShareShared)
|
|
|
|
s = s.Where("updated_at < ?", exp)
|
|
|
|
|
|
|
|
s = s.Order("updated_at ASC")
|
|
|
|
s = s.Limit(100).Offset(0)
|
|
|
|
|
|
|
|
s = s.Preload("File")
|
|
|
|
|
|
|
|
if err := s.Find(&result).Error; err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|