-
Notifications
You must be signed in to change notification settings - Fork 4
/
file.go
69 lines (61 loc) · 1.87 KB
/
file.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package mahi
import (
"context"
"time"
)
// FileService defines the business logic for dealing with all aspects of a file.
type FileService interface {
Create(ctx context.Context, n *NewFile) (*File, error)
File(ctx context.Context, id string) (*File, error)
ApplicationFiles(ctx context.Context, applicationID, sinceID string, limit int) ([]*File, error)
Delete(ctx context.Context, id string) error
}
// FileStorage handles communication with the database for handling files.
type FileStorage interface {
Store(ctx context.Context, n *NewFile) (*File, error)
File(ctx context.Context, id string) (*File, error)
FileByFileBlobID(ctx context.Context, fileBlobID string) (*File, error)
ApplicationFiles(ctx context.Context, applicationID, sinceID string, limit int) ([]*File, error)
Delete(ctx context.Context, id string) error
}
// File holds all the "meta" data of a file.
// From its type and size to who uploaded it and what application it was uploaded to.
type File struct {
ID string
ApplicationID string
Filename string
FileBlobID string
Size int64
MIMEType string
MIMEValue string
Extension string
URL string
Hash string
Width int
Height int
CreatedAt time.Time
UpdatedAt time.Time
}
func (f *File) IsImage() bool {
return f.MIMEType == "image" && f.MIMEValue != "image/svg+xml"
}
func (f *File) IsTransformable() bool {
return f.IsImage() || f.MIMEValue == "application/pdf"
}
// NewFile is a helper struct for creating a new file
type NewFile struct {
ApplicationID string
Filename string
FileBlobID string
Size int64
MIMEType string
MIMEValue string
Extension string
URL string
Hash string
Width int
Height int
}
func (f *NewFile) IsImage() bool {
return f.MIMEType == "image" && f.MIMEValue != "image/svg+xml"
}