@@ -96,27 +96,22 @@ func (s *Server) Tick(ctx context.Context) {
96
96
logrus .Errorf ("Failed getting checksum: (%v)" , err )
97
97
continue
98
98
}
99
- version , err := s .GetVersion (ctx )
100
- if err != nil {
101
- logrus .Errorf ("Failed getting version: (%v)" , err )
102
- continue
103
- }
104
99
if s .arcdps .CheckSum == "" {
105
100
logrus .Infof ("Setting initial version" )
106
- s .arcdps .CheckSum = check
107
- s .arcdps .Timestamp = version
101
+ s .arcdps .CheckSum = check . Checksum
102
+ s .arcdps .Timestamp = check . LastModified
108
103
continue
109
104
}
110
- if s .arcdps .CheckSum != check {
105
+ if s .arcdps .CheckSum != check . Checksum {
111
106
// new version
112
107
if err := s .SendWebHook (ctx ,
113
- fmt .Sprintf ("`%s`" , check ),
114
- fmt .Sprintf ("`%s`" , version .String ()),
108
+ fmt .Sprintf ("`%s`" , check . Checksum ),
109
+ fmt .Sprintf ("`%s`" , check . LastModified .String ()),
115
110
); err != nil {
116
111
logrus .Errorf ("unable to send webhook: (%v)\n " , err )
117
112
}
118
- s .arcdps .CheckSum = check
119
- s .arcdps .Timestamp = version
113
+ s .arcdps .CheckSum = check . Checksum
114
+ s .arcdps .Timestamp = check . LastModified
120
115
}
121
116
case <- ctx .Done ():
122
117
ticker .Stop ()
@@ -125,60 +120,44 @@ func (s *Server) Tick(ctx context.Context) {
125
120
}
126
121
}
127
122
128
- func (s * Server ) GetChecksum (ctx context.Context ) (string , error ) {
123
+ // Checksum : Used to compare local cache to remote
124
+ type Checksum struct {
125
+ Checksum string
126
+ LastModified time.Time
127
+ }
128
+
129
+ func (s * Server ) GetChecksum (ctx context.Context ) (* Checksum , error ) {
129
130
req , err := http .NewRequestWithContext (ctx , "GET" , ArcDPSCheckSumURL , nil )
130
131
if err != nil {
131
- return "" , err
132
+ return nil , err
132
133
}
133
134
134
135
resp , err := s .http .Do (req )
135
136
if err != nil {
136
- return "" , err
137
+ return nil , err
137
138
}
138
139
defer resp .Body .Close ()
139
140
140
141
body , err := io .ReadAll (resp .Body )
141
142
if err != nil {
142
- return "" , err
143
+ return nil , err
143
144
}
144
145
145
146
if resp .StatusCode > 299 {
146
- return "" , fmt .Errorf ("bad response from delta: (%s)" , string (body ))
147
- }
148
-
149
- checkSumSplit := strings .Split (string (body ), " " )
150
- if len (checkSumSplit ) < 2 {
151
- return "" , fmt .Errorf ("incorrect size of checksum split" )
152
- }
153
- return checkSumSplit [0 ], nil
154
-
155
- }
156
-
157
- func (s * Server ) GetVersion (ctx context.Context ) (time.Time , error ) {
158
- req , err := http .NewRequestWithContext (ctx , "HEAD" , ArcDPSDLLURL , nil )
159
- if err != nil {
160
- return time.Time {}, err
147
+ return nil , fmt .Errorf ("bad response from delta: (%s)" , string (body ))
161
148
}
162
149
163
- resp , err := s . http . Do ( req )
150
+ lastModified , err := time . Parse ( time . RFC1123 , resp . Header . Get ( "Last-Modified" ) )
164
151
if err != nil {
165
- return time. Time {} , err
152
+ return nil , fmt . Errorf ( "unable to parse time: (%v)" , err )
166
153
}
167
- defer resp .Body .Close ()
168
154
169
- if resp .StatusCode > 299 {
170
- body , err := io .ReadAll (resp .Body )
171
- if err != nil {
172
- return time.Time {}, err
173
- }
174
- return time.Time {}, fmt .Errorf ("bad response from delta: (%s)" , string (body ))
175
- }
176
- lastModified , err := time .Parse (time .RFC1123 , resp .Header .Get ("Last-Modified" ))
177
- if err != nil {
178
- return time.Time {}, fmt .Errorf ("unable to parse time: (%v)" , err )
155
+ checkSumSplit := strings .Split (string (body ), " " )
156
+ if len (checkSumSplit ) < 2 {
157
+ return nil , fmt .Errorf ("incorrect size of checksum split" )
179
158
}
180
159
181
- return lastModified , nil
160
+ return & Checksum { Checksum : checkSumSplit [ 0 ], LastModified : lastModified } , nil
182
161
}
183
162
184
163
func (s * Server ) SendWebHook (ctx context.Context , checksum , time string ) error {
0 commit comments