def image(request,sha,size,basename,ext): # TODO: handle etags # TODO: handle if-modified-since headers # TODO: send image dimensions in headers # TODO: detect noop resizes and 301 to existing ones # instead of creating duplicate files ext = ext.lower() if ext == "jpeg": ext = "jpg" dirpath = full_path_from_hash(sha) full_filename = "image.%s" % ext if size == "full": filename = full_filename else: size = normalize_size_format(size) filename = "%s.%s" % (size,ext) if not os.path.exists(dirpath): # we don't have it on this node, let's check the ring r = read_order(long(sha,16)) for node in r: if node.uuid == settings.CLUSTER['uuid']: # we already know that we don't have it continue try: resp,data = GET(node.base_url + "retrieve/%s/%s/%s/" % (sha,size,ext),resp=True) if resp['status'] == '200': mimes = dict(jpg="image/jpeg",gif="image/gif",png="image/png") return HttpResponse(data,mimes[ext]) except Exception, e: if settings.DEBUG: print str(e) # we don't have it and none of the nodes in the ring have it... raise Http404
def image_info(request,sha,size,basename,ext): ext = ext.lower() if ext == "jpeg": ext = "jpg" dirpath = full_path_from_hash(sha) full_filename = "image.%s" % ext if size == "full": filename = full_filename else: size = normalize_size_format(size) filename = "%s.%s" % (size,ext) data = dict(sha=sha,size=size,basename=basename,ext=ext) data['local'] = True other_nodes = [] if not os.path.exists(dirpath): data['local'] = False r = read_order(long(sha,16)) data['ring'] = r for node in r: node_response = dict(node=node) if node.uuid == settings.CLUSTER['uuid']: # we already know that we don't have it continue try: resp,ndata = GET(node.base_url + "retrieve_info/%s/%s/%s/" % (sha,size,ext),resp=True) if resp['status'] == '200': node_response['response'] = simplejson.loads(ndata) node_response["status"] = resp['status'] except Exception, e: if settings.DEBUG: print str(e) other_nodes.append(node_response)