Added HTML endpoint /mirrors to show a pretty HTML with the mirrored accounts

This commit is contained in:
Bofh 2021-02-10 20:21:53 +01:00
parent 9aaa5f4b34
commit 7f04f21bc3
2 changed files with 91 additions and 2 deletions

View File

@ -457,6 +457,32 @@ def pixelfed_setinfo(acc_id, bio, website, count=0):
return True
def pixelfed_htmlfill_mirrors(html):
accounts = os.listdir('./db/accounts')
mirr_html = ''
for acc_id in sorted(set(accounts)):
accdata = db_get('accounts', acc_id)
mirr_html += """
<div class="item">
<h3 class="name">{1}</h3>
<b>@{0}</b>
<div class="links">
<div><a href="https://{2}/{0}">Pixelfed</a></div>
<div><a href="https://www.instagram.com/{0}">Instagram</a></div>
</div>
</div>
""".format( accdata['username'], htmlesc(accdata['name']), \
config()['instance'] )
html = html.replace('{mirrors}', mirr_html)
html = html.replace('{item_count}', str(len(accounts)) )
html = html.replace('{instance}', config()['instance'])
return html
def htmlesc(strr):
return strr.replace('&', '&amp;')\
.replace('<', '&lt;')\
.replace('>', '&gt;')
def random_string(count=32):
return ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=count))

View File

@ -28,15 +28,78 @@ class MyServer(BaseHTTPRequestHandler):
<html>
<head>
<meta charset="utf-8"/>
<title>Pixelfed IG Mirrors</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{instance} - Mirrors</title>
</head>
<body>
<style type="text/css">
body {
font-family: Arial;
}
div#content {
max-width: 40em;
margin: auto;
}
div#content > div:nth-child(1) {
display: flex;
margin: 2em 1em;
border-bottom: 3px solid #dbdbdb;
padding-bottom: 2em;
}
div#content > div:nth-child(1) > h3 {
margin: 0;
width: 100%;
}
div#content > div:nth-child(1) > span {
min-width: 6em;
}
div.item {
padding: 1em;
box-shadow: 0px 2px .2em #acacac;
margin-bottom: 1em;
}
div.item > h3.name {
font-weight: initial;
}
div.item > div.links {
display: flex;
height: 2.5em;
margin-top: 2em;
}
div.item > div.links > div {
display: flex;
width: 100%;
}
div.item > div.links > div > a {
margin: auto;
text-decoration: none;
}
div.item > div.links > div:nth-child(1) {
background: #ffdade;
}
div.item > div.links > div:nth-child(1) > a {
font-weight: bold;
color: #ce0680;
}
div.item > div.links > div:nth-child(2) {
background: #f2f2f2;
}
div.item > div.links > div:nth-child(2) > a {
color: #367280;
font-style: italic;
}
</style>
<div id="mirrors">{mirrors}</div>
<div id="content">
<div>
<h3>{instance}</h3>
<span>{item_count} accounts</span>
</div>
{mirrors}
</div>
</body>
</html>
"""
html = igmirror.pixelfed_htmlfill_mirrors(html)
self.wfile.write(bytes(html, "utf-8"))
return