git ssb

0+

cel / ssb-wikimedia



Commit caf3d30d63d6aeaa044de2339d4f9a0bd26a80e2

Support older API without slots

cel committed on 12/1/2019, 5:14:10 AM
Parent: 2bf1394722753ed8aff3228422571438b98fe96f

Files changed

bin.jschanged
bin.jsView
@@ -260,17 +260,40 @@
260260 console.log('Getting revisions for', pageInfo.title + '...',
261261 rvstart || '', rvcontinue || '')
262262 var url = api + '?format=json&action=query&prop=revisions&rvslots=*'
263263 + '&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'
265265 + '&rvdir=newer'
266266 + (rvcontinue ? '&rvcontinue=' + rvcontinue : '')
267267 + (rvstart ? '&rvstart=' + rvstart : '')
268268 + '&rvlimit=50'
269269 getJson(url, function (err, data) {
270270 if (aborted) return err && console.trace(err)
271271 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 +
273296 rvcontinue = data.continue && data.continue.rvcontinue
274297 if (!rvcontinue) rvdone = true
275298 var page
276299 if (data.query) for (var pageid in data.query.pages) {
@@ -291,8 +314,31 @@
291314 cb(null, page.revisions)
292315 })
293316 },
294317 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 +
295341 pull.asyncMap(function (rev, cb) {
296342 // Calculate blob id for user page URL + title, for linking
297343 var hash = userHashes[rev.user]
298344 if (hash) {

Built with git-ssb-web