-
Notifications
You must be signed in to change notification settings - Fork 249
/
server_media.go
202 lines (169 loc) · 6.13 KB
/
server_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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package server
import (
"database/sql"
"net/url"
"strconv"
"github.com/status-im/status-go/ipfs"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/services/wallet/thirdparty"
"github.com/status-im/status-go/signal"
)
type MediaServer struct {
Server
db *sql.DB
downloader *ipfs.Downloader
multiaccountsDB *multiaccounts.Database
walletDB *sql.DB
}
// NewMediaServer returns a *MediaServer
func NewMediaServer(db *sql.DB, downloader *ipfs.Downloader, multiaccountsDB *multiaccounts.Database, walletDB *sql.DB) (*MediaServer, error) {
err := generateMediaTLSCert()
if err != nil {
return nil, err
}
s := &MediaServer{
Server: NewServer(
globalMediaCertificate,
Localhost,
signal.SendMediaServerStarted,
logutils.ZapLogger().Named("MediaServer"),
),
db: db,
downloader: downloader,
multiaccountsDB: multiaccountsDB,
walletDB: walletDB,
}
s.SetHandlers(HandlerPatternMap{
accountImagesPath: handleAccountImages(s.multiaccountsDB, s.logger),
accountInitialsPath: handleAccountInitials(s.multiaccountsDB, s.logger),
audioPath: handleAudio(s.db, s.logger),
contactImagesPath: handleContactImages(s.db, s.logger),
discordAttachmentsPath: handleDiscordAttachment(s.db, s.logger),
discordAuthorsPath: handleDiscordAuthorAvatar(s.db, s.logger),
generateQRCode: handleQRCodeGeneration(s.multiaccountsDB, s.logger),
imagesPath: handleImage(s.db, s.logger),
ipfsPath: handleIPFS(s.downloader, s.logger),
LinkPreviewThumbnailPath: handleLinkPreviewThumbnail(s.db, s.logger),
LinkPreviewFaviconPath: handleLinkPreviewFavicon(s.db, s.logger),
StatusLinkPreviewThumbnailPath: handleStatusLinkPreviewThumbnail(s.db, s.logger),
communityTokenImagesPath: handleCommunityTokenImages(s.db, s.logger),
walletCommunityImagesPath: handleWalletCommunityImages(s.walletDB, s.logger),
walletCollectionImagesPath: handleWalletCollectionImages(s.walletDB, s.logger),
walletCollectibleImagesPath: handleWalletCollectibleImages(s.walletDB, s.logger),
})
return s, nil
}
func (s *MediaServer) MakeImageServerURL() string {
u := s.MakeBaseURL()
u.Path = basePath + "/"
return u.String()
}
func (s *MediaServer) MakeImageURL(id string) string {
u := s.MakeBaseURL()
u.Path = imagesPath
u.RawQuery = url.Values{"messageId": {id}}.Encode()
return u.String()
}
func (s *MediaServer) MakeLinkPreviewThumbnailURL(msgID string, previewURL string) string {
u := s.MakeBaseURL()
u.Path = LinkPreviewThumbnailPath
u.RawQuery = url.Values{"message-id": {msgID}, "url": {previewURL}}.Encode()
return u.String()
}
func (s *MediaServer) MakeStatusLinkPreviewThumbnailURL(msgID string, previewURL string, imageID common.MediaServerImageID) string {
u := s.MakeBaseURL()
u.Path = StatusLinkPreviewThumbnailPath
u.RawQuery = url.Values{"message-id": {msgID}, "url": {previewURL}, "image-id": {string(imageID)}}.Encode()
return u.String()
}
func (s *MediaServer) MakeLinkPreviewFaviconURL(msgID string, previewURL string) string {
u := s.MakeBaseURL()
u.Path = LinkPreviewFaviconPath
u.RawQuery = url.Values{"message-id": {msgID}, "url": {previewURL}}.Encode()
return u.String()
}
func (s *MediaServer) MakeDiscordAuthorAvatarURL(authorID string) string {
u := s.MakeBaseURL()
u.Path = discordAuthorsPath
u.RawQuery = url.Values{"authorId": {authorID}}.Encode()
return u.String()
}
func (s *MediaServer) MakeDiscordAttachmentURL(messageID string, id string) string {
u := s.MakeBaseURL()
u.Path = discordAttachmentsPath
u.RawQuery = url.Values{"messageId": {messageID}, "attachmentId": {id}}.Encode()
return u.String()
}
func (s *MediaServer) MakeAudioURL(id string) string {
u := s.MakeBaseURL()
u.Path = audioPath
u.RawQuery = url.Values{"messageId": {id}}.Encode()
return u.String()
}
func (s *MediaServer) MakeStickerURL(stickerHash string) string {
u := s.MakeBaseURL()
u.Path = ipfsPath
u.RawQuery = url.Values{"hash": {stickerHash}}.Encode()
return u.String()
}
func (s *MediaServer) MakeQRURL(qurul string,
allowProfileImage string,
level string,
size string,
keyUID string,
imageName string) string {
u := s.MakeBaseURL()
u.Path = generateQRCode
u.RawQuery = url.Values{"url": {qurul},
"level": {level},
"allowProfileImage": {allowProfileImage},
"size": {size},
"keyUid": {keyUID},
"imageName": {imageName}}.Encode()
return u.String()
}
func (s *MediaServer) MakeContactImageURL(publicKey string, imageType string) string {
u := s.MakeBaseURL()
u.Path = contactImagesPath
u.RawQuery = url.Values{"publicKey": {publicKey}, "imageName": {imageType}}.Encode()
return u.String()
}
func (s *MediaServer) MakeCommunityTokenImagesURL(communityID string, chainID uint64, symbol string) string {
u := s.MakeBaseURL()
u.Path = communityTokenImagesPath
u.RawQuery = url.Values{
"communityID": {communityID},
"chainID": {strconv.FormatUint(chainID, 10)},
"symbol": {symbol},
}.Encode()
return u.String()
}
func (s *MediaServer) MakeWalletCommunityImagesURL(communityID string) string {
u := s.MakeBaseURL()
u.Path = walletCommunityImagesPath
u.RawQuery = url.Values{
"communityID": {communityID},
}.Encode()
return u.String()
}
func (s *MediaServer) MakeWalletCollectionImagesURL(contractID thirdparty.ContractID) string {
u := s.MakeBaseURL()
u.Path = walletCollectionImagesPath
u.RawQuery = url.Values{
"chainID": {contractID.ChainID.String()},
"contractAddress": {contractID.Address.Hex()},
}.Encode()
return u.String()
}
func (s *MediaServer) MakeWalletCollectibleImagesURL(collectibleID thirdparty.CollectibleUniqueID) string {
u := s.MakeBaseURL()
u.Path = walletCollectibleImagesPath
u.RawQuery = url.Values{
"chainID": {collectibleID.ContractID.ChainID.String()},
"contractAddress": {collectibleID.ContractID.Address.Hex()},
"tokenID": {collectibleID.TokenID.String()},
}.Encode()
return u.String()
}