Better thumbs loading, now with browser caching

This commit is contained in:
Patrick Speiser
2012-09-29 10:53:38 +02:00
parent 1681e30b62
commit 0ba49dc1fc
2 changed files with 35 additions and 2 deletions

View File

@@ -46,7 +46,7 @@
"aTargets": [ 0 ],
"mData":"ArtistID",
"mRender": function ( data, type, full ) {
return '<div id="artistImg"><img class="albumArt" alt="" id="'+ data + '"/></div>';
return '<div id="artistImg"><img class="albumArt" alt="" id="'+ data + '" src="/thumbs/artist/' + data + '"/></div>';
}
},
{"aTargets":[1],"mDataProp":"ArtistSortName"},
@@ -73,7 +73,6 @@
},
"fnInitComplete": function(oSettings, json)
{
getArtistArt();
}});

View File

@@ -872,3 +872,37 @@ class WebInterface(object):
return simplejson.dumps(image_dict)
getImageLinks.exposed = True
class Thumbs(object):
def index(self):
return "Here be thumbs"
index.exposed = True
def default(self,ArtistOrAlbum="",ID=None):
from headphones import cache
ArtistID = None
AlbumID = None
if ArtistOrAlbum == "artist":
ArtistID = ID
elif ArtistOrAlbum == "album":
AlbumID = None
relpath = cache.getThumb(ArtistID,AlbumID)
if not relpath:
if ArtistOrAlbum == "artist":
relpath = "data/interfaces/default/images/no-cover-artist.png"
elif ArtistOrAlbum == "album":
relpath = "data/interfaces/default/images/no-cover-art.png"
cherrypy.response.headers['Content-type'] = 'image/png'
cherrypy.response.headers['Cache-Control'] = 'no-cache'
else:
fileext = os.path.splitext(relpath)[1][1::]
cherrypy.response.headers['Content-type'] = 'image/' + fileext
cherrypy.response.headers['Cache-Control'] = 'max-age=31556926'
path = os.path.abspath(relpath)
f = open(path,'rb')
return f.read()
default.exposed = True
WebInterface.thumbs = Thumbs()