File tree 1 file changed +13
-9
lines changed
1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change 149
149
(.mkdir cache-dir :parents T :exist-ok T)
150
150
(setv path (/ cache-dir " infinity_quests_2.zip" ))
151
151
(unless (.exists path)
152
- (import http.client contextlib)
153
- (with [con (contextlib.closing (http.client.HTTPConnection " arfer.net" ))]
152
+ (import http.client contextlib hashlib)
153
+ (setv data (with [con
154
+ (contextlib.closing (http.client.HTTPConnection " arfer.net" ))]
154
155
(.request con " GET" " /downloads/infinity_quests_2.zip"
155
156
:headers {" User-Agent" " Infinitesimal Quest 2 + epsilon" })
156
157
(setv r (.getresponse con))
157
- (assert (= r.status 200 ))
158
- (.write-bytes path (.read r))))
158
+ (when (!= r.status 200 )
159
+ (raise (ValueError f" The HTTP request to get IQ quests returned status code {r.status}" )))
160
+ (.read r)))
161
+ (setv value (.hexdigest (hashlib.sha512 data)))
162
+ (unless (= value " 044b0c16fcc3bda2869d5b97ecaf32b39177988e510230e44456a33485c2df4e929443b9765463654961b7190ecf431a6871417a52c81e81c61f089d2793ab5d" )
163
+ (raise (ValueError f" Bad SHA-512 hash for IQ quests: {value}" )))
164
+ (.write-bytes path data))
159
165
160
166
; Read the files from the archive.
161
- (setv prefix " infinity_quests_2/" )
162
167
(with [z (ZipFile path " r" )] (dfor
163
- q (.namelist z)
164
- :setv v (.read z q)
165
- :if v
166
- (.removeprefix q prefix) v)))
168
+ member (.namelist z)
169
+ :if (not (.endswith member " /" ))
170
+ (.removeprefix member " infinity_quests_2/" ) (.read z member))))
167
171
168
172
(defn read-quest [name inp]
169
173
" Parse `bytes` into a `Quest`."
You can’t perform that action at this time.
0 commit comments