aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/repository/media.go
blob: 9915c90c7f8a3ba35b115113c08ca8cdde69f29d (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package repository

import (
	"context"
	"strings"
	"time"
)

type (
	Media struct {
		ID       uint
		Name     string
		Path     string
		PathHash string
		MIMEType string
	}

	MediaEXIF struct {
		Width           *float64
		Height          *float64
		Description     *string
		Camera          *string
		Maker           *string
		Lens            *string
		DateShot        *time.Time
		Exposure        *float64
		Aperture        *float64
		Iso             *int64
		FocalLength     *float64
		Flash           *int64
		Orientation     *int64
		ExposureProgram *int64
		GPSLatitude     *float64
		GPSLongitude    *float64
	}

	Album struct {
		ID   uint
		Name string
		Path string
	}

	MediaThumbnail struct {
		Path string
	}

	Pagination struct {
		Page    int
		Size    int
		AlbumID *uint
		Path    string
	}

	CreateMedia struct {
		Name     string
		Path     string
		PathHash string
		MIMEType string
	}

	CreateAlbum struct {
		ParentID *uint
		Name     string
		Path     string
	}

	CreateAlbumFile struct {
		MediaID uint
		AlbumID uint
	}

	MediaRepository interface {
		Create(context.Context, *CreateMedia) error
		Exists(context.Context, string) (bool, error)
		List(context.Context, *Pagination) ([]*Media, error)
		Get(context.Context, string) (*Media, error)
		GetPath(context.Context, string) (string, error)
		GetThumbnailPath(context.Context, string) (string, error)

		ListEmptyEXIF(context.Context, *Pagination) ([]*Media, error)
		GetEXIF(context.Context, uint) (*MediaEXIF, error)
		CreateEXIF(context.Context, uint, *MediaEXIF) error

		ListEmptyThumbnail(context.Context, *Pagination) ([]*Media, error)
		GetThumbnail(context.Context, uint) (*MediaThumbnail, error)
		CreateThumbnail(context.Context, uint, *MediaThumbnail) error

		ListEmptyAlbums(context.Context, *Pagination) ([]*Media, error)
		ListAlbums(context.Context, uint) ([]*Album, error)
		ExistsAlbumByAbsolutePath(context.Context, string) (bool, error)
		GetAlbumByAbsolutePath(context.Context, string) (*Album, error)
		GetAlbum(context.Context, uint) (*Album, error)
		CreateAlbum(context.Context, *CreateAlbum) (*Album, error)
		CreateAlbumFile(context.Context, *CreateAlbumFile) error
	}
)

func (m *Media) IsVideo() bool {
	return strings.HasPrefix(m.MIMEType, "video")
}