forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage.go
46 lines (38 loc) · 1.08 KB
/
image.go
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
package models
import (
"errors"
"time"
)
var (
// ErrImageNotFound is returned when the image does not exist.
ErrImageNotFound = errors.New("image not found")
)
type Image struct {
ID int64 `xorm:"pk autoincr 'id'"`
Token string `xorm:"token"`
Path string `xorm:"path"`
URL string `xorm:"url"`
CreatedAt time.Time `xorm:"created_at"`
ExpiresAt time.Time `xorm:"expires_at"`
}
// ExtendDuration extends the expiration time of the image. It can shorten
// the duration of the image if d is negative.
func (i *Image) ExtendDuration(d time.Duration) {
i.ExpiresAt = i.ExpiresAt.Add(d)
}
// HasExpired returns true if the image has expired.
func (i *Image) HasExpired() bool {
return timeNow().After(i.ExpiresAt)
}
// HasPath returns true if the image has a path on disk.
func (i *Image) HasPath() bool {
return i.Path != ""
}
// HasURL returns true if the image has a URL.
func (i *Image) HasURL() bool {
return i.URL != ""
}
// A XORM interface that defines the used table for this struct.
func (i *Image) TableName() string {
return "alert_image"
}