@@ -255,25 +255,32 @@ def notfound():
255
255
elif key != 'id' :
256
256
value = self .query (category , key , value )
257
257
258
- if not value or (value and safeint (value ) in config .blocked_covers ):
258
+ value = safeint (value )
259
+ if value is None or value in config .blocked_covers :
259
260
return notfound ()
260
261
262
+ if 8_820_000 > value >= 8_000_000 and size == "L" :
263
+ # This item is currently offline due to heavy traffic;
264
+ # Fix incoming in the next ~week; See:
265
+ # - https://webarchive.jira.com/browse/PBOX-3879
266
+ # - https://github.com/internetarchive/openlibrary/issues/9560
267
+ size = "M"
268
+
261
269
# redirect to archive.org cluster for large size and original images whenever possible
262
270
if size in ("L" , "" ) and self .is_cover_in_cluster (value ):
263
- url = zipview_url_from_id (int ( value ) , size )
271
+ url = zipview_url_from_id (value , size )
264
272
return web .found (url )
265
273
266
274
# covers_0008 batches [_00, _82] are tar'd / zip'd in archive.org items
267
- if isinstance (value , int ) or value .isnumeric (): # noqa: SIM102
268
- if 8_820_000 > int (value ) >= 8_000_000 :
269
- prefix = f"{ size .lower ()} _" if size else ""
270
- pid = "%010d" % int (value )
271
- item_id = f"{ prefix } covers_{ pid [:4 ]} "
272
- item_tar = f"{ prefix } covers_{ pid [:4 ]} _{ pid [4 :6 ]} .tar"
273
- item_file = f"{ pid } { '-' + size .upper () if size else '' } "
274
- path = f"{ item_id } /{ item_tar } /{ item_file } .jpg"
275
- protocol = web .ctx .protocol
276
- return web .found (f"{ protocol } ://archive.org/download/{ path } " )
275
+ if 8_820_000 > value >= 8_000_000 :
276
+ prefix = f"{ size .lower ()} _" if size else ""
277
+ pid = "%010d" % value
278
+ item_id = f"{ prefix } covers_{ pid [:4 ]} "
279
+ item_tar = f"{ prefix } covers_{ pid [:4 ]} _{ pid [4 :6 ]} .tar"
280
+ item_file = f"{ pid } { '-' + size .upper () if size else '' } "
281
+ path = f"{ item_id } /{ item_tar } /{ item_file } .jpg"
282
+ protocol = web .ctx .protocol
283
+ return web .found (f"{ protocol } ://archive.org/download/{ path } " )
277
284
278
285
d = self .get_details (value , size .lower ())
279
286
if not d :
@@ -329,14 +336,9 @@ def get_ia_cover_url(self, identifier, size="M"):
329
336
h ,
330
337
)
331
338
332
- def get_details (self , coverid , size = "" ):
333
- try :
334
- coverid = int (coverid )
335
- except ValueError :
336
- return None
337
-
339
+ def get_details (self , coverid : int , size = "" ):
338
340
# Use tar index if available to avoid db query. We have 0-6M images in tar balls.
339
- if isinstance ( coverid , int ) and coverid < 6000000 and size in "sml" :
341
+ if coverid < 6000000 and size in "sml" :
340
342
path = self .get_tar_filename (coverid , size )
341
343
342
344
if path :
@@ -350,12 +352,12 @@ def get_details(self, coverid, size=""):
350
352
351
353
return db .details (coverid )
352
354
353
- def is_cover_in_cluster (self , coverid ):
355
+ def is_cover_in_cluster (self , coverid : int ):
354
356
"""Returns True if the cover is moved to archive.org cluster.
355
357
It is found by looking at the config variable max_coveritem_index.
356
358
"""
357
359
try :
358
- return int ( coverid ) < IMAGES_PER_ITEM * config .get ("max_coveritem_index" , 0 )
360
+ return coverid < IMAGES_PER_ITEM * config .get ("max_coveritem_index" , 0 )
359
361
except (TypeError , ValueError ):
360
362
return False
361
363
0 commit comments