-
Notifications
You must be signed in to change notification settings - Fork 13
/
file.go
54 lines (46 loc) · 1.38 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
package file
import (
"github.com/coretrix/hitrix/pkg/dto/file"
"github.com/coretrix/hitrix/pkg/entity"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/oss"
)
type CDNInterface interface {
GetImageURLWithTemplate(image string) string
}
func GetFileTypeCounter(fileObject *entity.FileObject, namespace oss.Namespace) *file.File {
objectURL, err := service.DI().OSService().GetObjectURL(namespace, fileObject)
if err != nil {
panic(err)
}
return &file.File{
ID: fileObject.ID,
Filename: fileObject.StorageKey,
URL: objectURL,
IDType: file.IDTypeOSSCounterID,
}
}
func GetFileTypeCounterWithCDN(fileObject *entity.FileObject, namespace oss.Namespace, cdn CDNInterface) *file.File {
objectURL, err := service.DI().OSService().GetObjectURL(namespace, fileObject)
if err != nil {
panic(err)
}
return &file.File{
ID: fileObject.ID,
Filename: fileObject.StorageKey,
URL: cdn.GetImageURLWithTemplate(objectURL),
IDType: file.IDTypeOSSCounterID,
}
}
func GetFileTypeID(fileEntity *entity.FileEntity, namespace oss.Namespace) *file.File {
objectURL, err := service.DI().OSService().GetObjectURL(namespace, fileEntity.File)
if err != nil {
panic(err)
}
return &file.File{
ID: fileEntity.ID,
URL: objectURL,
Namespace: oss.Namespace(fileEntity.Namespace),
IDType: file.IDTypeFileID,
}
}