-
Notifications
You must be signed in to change notification settings - Fork 4
/
media.go
42 lines (32 loc) · 1.22 KB
/
media.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
package utils
import (
"strings"
)
const (
// BigPicture :nodoc:
BigPicture = "big_picture"
// LargeIcon :nodoc:
LargeIcon = "large_icon"
// IOSAttachment :nodoc:
IOSAttachment = "ios_attahcment"
)
// GeneratePushNotificationMediaURL Generates manipulated media URL for push notification purpose
// e.g. GeneratePushNotificationMediaURL("http://mycdn.com", "http://my.image.com/image/upload/v123/image.jpg", LargeIcon) => http://mycdn.com/image/upload/v123/image.jpg
func GeneratePushNotificationMediaURL(cdnURL, mediaSrcURL, imageType string) string {
if mediaSrcURL == "" || cdnURL == "" {
return ""
}
splitMediaSrcImageURL := strings.Split(mediaSrcURL, "/")
coverMediaFile := splitMediaSrcImageURL[len(splitMediaSrcImageURL)-2] + "/" + splitMediaSrcImageURL[len(splitMediaSrcImageURL)-1]
var param string
switch imageType {
case LargeIcon:
param = "image/upload/fl_progressive,fl_lossy,c_fill,g_face,q_auto:best,w_256,ar_1:1"
case BigPicture:
param = "image/upload/fl_progressive,fl_lossy,c_fill,g_face,q_auto:best,w_1440,h_720"
case IOSAttachment:
param = "image/upload/fl_progressive,fl_lossy,c_fill,g_face,q_auto:best,w_1024,h_1024"
}
mediaURL := cdnURL + "/" + param + "/" + coverMediaFile
return mediaURL
}