aboutsummaryrefslogtreecommitdiff
path: root/database/images.go
blob: 8fa1a478aed004aff5e40a338c24930e45e0bdcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package database

import (
	"imageboard/models"
	"imageboard/utils/format"
	"time"
)

func GetTotalPostsCount() (int64, error) {
	var count int64
	err := DB.Model(&models.Image{}).Count(&count).Error
	return count, err
}

func GetTodayPostsCount() (int64, error) {
	var count int64
	today := time.Now().Truncate(24 * time.Hour)
	err := DB.Model(&models.Image{}).Where("created_at >= ?", today).Count(&count).Error
	return count, err
}

func GetTotalStorageSize() (string, error) {
	var imageSizes []models.ImageSize
	if err := DB.Select("file_size").Find(&imageSizes).Error; err != nil {
		return "0 B", err
	}

	var totalSize int64
	for _, size := range imageSizes {
		totalSize += size.FileSize
	}

	return format.FileSize(totalSize), nil
}