Commit caf3d30d63d6aeaa044de2339d4f9a0bd26a80e2
Support older API without slots
cel committed on 12/1/2019, 5:14:10 AMParent: 2bf1394722753ed8aff3228422571438b98fe96f
Files changed
bin.js | changed |
bin.js | ||
---|---|---|
@@ -260,17 +260,40 @@ | ||
260 | 260 … | console.log('Getting revisions for', pageInfo.title + '...', |
261 | 261 … | rvstart || '', rvcontinue || '') |
262 | 262 … | var url = api + '?format=json&action=query&prop=revisions&rvslots=*' |
263 | 263 … | + '&titles=' + encodeURIComponent(pageInfo.title) |
264 | - + '&rvprop=ids|timestamp|comment|user|slotsha1|slotsize|content|roles|flags|tags' | |
264 … | + + '&rvprop=ids|timestamp|comment|user|sha1|size|slotsha1|slotsize|content|roles|flags|tags' | |
265 | 265 … | + '&rvdir=newer' |
266 | 266 … | + (rvcontinue ? '&rvcontinue=' + rvcontinue : '') |
267 | 267 … | + (rvstart ? '&rvstart=' + rvstart : '') |
268 | 268 … | + '&rvlimit=50' |
269 | 269 … | getJson(url, function (err, data) { |
270 | 270 … | if (aborted) return err && console.trace(err) |
271 | 271 … | if (err) return cb(err) |
272 | - if (data.warnings) console.trace('Warnings:', data.warnings) | |
272 … | + | |
273 … | + var warnings = data.warnings | |
274 … | + if (warnings) { | |
275 … | + if (warnings.main) { | |
276 … | + if (warnings.main['*'] === 'Unrecognized parameter: rvslots.') { | |
277 … | + delete warnings.main['*'] | |
278 … | + if (Object.keys(warnings.main).length === 0) { | |
279 … | + delete warnings.main | |
280 … | + } | |
281 … | + } | |
282 … | + } | |
283 … | + if (warnings.revisions) { | |
284 … | + if (warnings.revisions['*'] === 'Unrecognized values for parameter "rvprop": slotsha1, slotsize, roles.') { | |
285 … | + delete warnings.revisions['*'] | |
286 … | + if (Object.keys(warnings.revisions).length === 0) { | |
287 … | + delete warnings.revisions | |
288 … | + } | |
289 … | + } | |
290 … | + } | |
291 … | + if (Object.keys(warnings).length > 0) { | |
292 … | + console.trace('Warnings:', warnings) | |
293 … | + } | |
294 … | + } | |
295 … | + | |
273 | 296 … | rvcontinue = data.continue && data.continue.rvcontinue |
274 | 297 … | if (!rvcontinue) rvdone = true |
275 | 298 … | var page |
276 | 299 … | if (data.query) for (var pageid in data.query.pages) { |
@@ -291,8 +314,31 @@ | ||
291 | 314 … | cb(null, page.revisions) |
292 | 315 … | }) |
293 | 316 … | }, |
294 | 317 … | pull.flatten(), |
318 … | + | |
319 … | + pull.through(function (rev) { | |
320 … | + if (!rev.slots) { | |
321 … | + // old API does not use slots. | |
322 … | + // Transform result to be forward-compatible. | |
323 … | + rev.slots = { | |
324 … | + main: { | |
325 … | + size: rev.size, | |
326 … | + sha1: rev.sha1, | |
327 … | + contentmodel: rev.contentmodel, | |
328 … | + contentformat: rev.contentformat, | |
329 … | + '*': rev['*'] | |
330 … | + } | |
331 … | + } | |
332 … | + delete rev.contentmodel | |
333 … | + delete rev.contentformat | |
334 … | + delete rev['*'] | |
335 … | + } | |
336 … | + // duplicate values supplied in new API in slotsize and slotsha1 | |
337 … | + delete rev.sha1 | |
338 … | + delete rev.size | |
339 … | + }), | |
340 … | + | |
295 | 341 … | pull.asyncMap(function (rev, cb) { |
296 | 342 … | // Calculate blob id for user page URL + title, for linking |
297 | 343 … | var hash = userHashes[rev.user] |
298 | 344 … | if (hash) { |
Built with git-ssb-web