Browse Source

Add filecache

tags/1.8.8
Leonie 3 months ago
parent
commit
6145ad1007
4 changed files with 37 additions and 9 deletions
  1. +2
    -1
      .gitignore
  2. +28
    -6
      backend.py
  3. +2
    -2
      www/app.js
  4. +5
    -0
      www/style.css

+ 2
- 1
.gitignore View File

@@ -23,4 +23,5 @@ typings/
# backend downloads
files/*.png
files/*.jpg
files/*.gif
files/*.gif
filecache

+ 28
- 6
backend.py View File

@@ -258,14 +258,36 @@ def getprimarycolor():
response.headers['Access-Control-Allow-Origin'] = '*'
response.content_type = "text/plain"
url = request.query["url"] # pylint: disable=unsubscriptable-object
filecache = ""
filename = "files/"+url.split("/")[len(url.split("/")) - 1]
if "/api/v1/getbanner" in url:
filename = "banners/"+url.split("/")[len(url.split("/")) - 1]+".jpg"
if os.path.exists("filecache"):
f = open("filecache", "r")
x = f.readlines()
f.close()
for i in x:
if i.split("#")[0] == filename:
filecache = i.split("#")[1]
if not filecache == "":
return filecache
else:
if not "/api/v1/getbanner" in url:
subprocess.Popen(["wget", "-O", filename, url], shell=False).wait()
color_thief = ColorThief(filename)
dominant_color = color_thief.get_color()
x = str(dominant_color).replace("(", "").replace(" ", "").replace(")", "")
f = open("filecache", "a+")
f.write(filename+"#"+x+"\n")
return x
else:
filename = "files/"+url.split("/")[len(url.split("/")) - 1]
subprocess.Popen(["wget", "-O", filename, url], shell=False).wait()
color_thief = ColorThief(filename)
dominant_color = color_thief.get_color()
x = str(dominant_color).replace("(", "").replace(" ", "").replace(")", "")
return x
if not "/api/v1/getbanner" in url:
subprocess.Popen(["wget", "-O", filename, url], shell=False).wait()
color_thief = ColorThief(filename)
dominant_color = color_thief.get_color()
x = str(dominant_color).replace("(", "").replace(" ", "").replace(")", "")
f = open("filecache", "a+")
f.write(filename+"#"+x+"\n")
return x

run(server="tornado",port=9000,host="0.0.0.0")

+ 2
- 2
www/app.js View File

@@ -424,7 +424,7 @@ $(document).ready(function() {
if (callback.feed.summary !== undefined) {
summary = callback.feed.summary.replaceAll("\n", "<br>");
}
$("#section__list").html($("#section__list").html()+"<div class=\"item\" id=\"itemcard-"+secret+"\"><div class=\"item-head\"><a class=\"cardlink\" data-cast=\""+Base64.encode(callback.href)+"\"><img src=\""+callback.feed.image.href+"\" class=\"card__small\" id=\"item-card-"+secret+"\" /></a><br><b>"+callback.feed.title+"</b></div><br><p>"+summary+"</p></div>");
$("#section__list").html($("#section__list").html()+"<a class=\"cardlink\" data-cast=\""+Base64.encode(callback.href)+"\"><div class=\"item\" id=\"itemcard-"+secret+"\"><div class=\"item-head\"><img src=\""+callback.feed.image.href+"\" class=\"card__small\" id=\"item-card-"+secret+"\" /><br><b>"+callback.feed.title+"</b></div><br><p>"+summary+"</p></div></a>");
$.get(backend+"/api/v1/getprimarycolor?url="+callback.feed.image.href, function(color) {
if (Number(color.split(",")[0]) > 140) {
if (summary !== "") {
@@ -491,7 +491,7 @@ $(document).ready(function() {
$("#section__featured").html($("#section__featured").html()+"<div><a class=\"cardlink\" data-cast=\""+Base64.encode(item[1])+"\"><img src=\""+backend+"/api/v1/getbanner/"+item[0]+"\" class=\"card__big\" id=\"featured-"+Base64.encode(item[1]).replaceAll("=", "")+"\"/></a></div>");
window.setTimeout(function() {
$.get(backend+"/api/v1/getprimarycolor?url="+backend+"/api/v1/getbanner/"+item[0], function(color) {
$("#featured-"+Base64.encode(item[1]).replaceAll("=", "")).attr("style", "box-shadow: 0px 0px 13px 2px rgba('"+color+"',0.75);");
$("#featured-"+Base64.encode(item[1]).replaceAll("=", "")).attr("style", "box-shadow: 0px 0px 13px 2px rgba("+color+",0.75);");
});
},200);
});


+ 5
- 0
www/style.css View File

@@ -400,6 +400,11 @@ h1 .emoji {
width: 90%;
}

#img__cast2 {
width: 64px !important;
height: 64px !important;
}

/* Hack for ionicicons v2 (no animation code) */
.ion-spin-animation { -webkit-animation: spin 1s infinite linear; -moz-animation: spin 1s infinite linear; -o-animation: spin 1s infinite linear; animation: spin 1s infinite linear; }



Loading…
Cancel
Save