Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 7abd7707 authored by echicken's avatar echicken 🐔

New Avatar fetch/cache thing for new forum.

parent 3178b8df
......@@ -38,48 +38,49 @@ function Avatarizer() {
}
const Avatars = new (function () {
const Avatars = new ( function () {
const gc = new GraphicsConverter('./images/cp437-ibm-vga8.png', 8, 16, 64, 4);
function draw(data) {
const img = new Image();
img.addEventListener('load', () => document.querySelectorAll(`div[data-avatar="${data.user}"]:empty`).forEach(e => e.appendChild(img.cloneNode(true))));
img.addEventListener('load', () => {
document.querySelectorAll(`div[data-avatar="${data.user}"]:empty`).forEach(e => {
e.appendChild(img.cloneNode(true))
});
});
img.src = data.dataURL || 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABgCAYAAACKa/UAAAABiUlEQVR4Xu3c0YqCUBiFUXtKX1Gfcga6TPBgn6LDrG5zSy3377EQX8uy/ExeXwu8AH5t9w4CbH4Aox9AgFUg5p0Dnw44z3P8iC2+rmvbwSB9eQMBxuMHEOCugBGOBQEIcF/AKhwbAvC/Ad592TLyPruRpy8iAEeHcPA+QICHBIzwIa7txgABHhOwCh/z2mwNEGAUiHENBBgFYlwDAUaBGNdAgFEgxjUQYBSIcQ0EGAViXAMBRoEY10CAUSDGNRBgFIhxDQQYBWJcAwFGgRjXQIBRIMYf38DP73f33Vpng31+v9PvjQEYRwQgwEMCRvgQ13ZjgAD3BR6/Ct99mRILNFXgPMIA44N3AAJMZwEjHJ+pABBgmkCrcOObAD4e8K9fplwNPFxEAO4/+QjgoKKjn3oAAdazXPs3RwM1UAOvFYh7t4gAjAIxroEAo0CMayDAKBDjGggwCsS4BgKMAjGugQCjQIxrIMAoEOMaCDAKxLgGAowCMa6BAKNAjGsgwCgQ4xoIMArE+KiBv6PnKB+V8OyaAAAAAElFTkSuQmCC';
}
function cacheAvatar(data) {
if (data.data) {
gc.from_bin(atob(data.data), 10, 6, dataURL => {
data.dataURL = dataURL;
localStorage.setItem(`avatar-${data.user}`, JSON.stringify(data));
draw(data);
}, true);
} else {
data.data = null;
localStorage.setItem(`avatar-${data.user}`, JSON.stringify(data));
draw(data);
this.draw = async function (user) {
const u = [];
for (let e of [].concat(user)) {
const a = await sbbs.avatars.get(e);
if (!a) {
u.push(e);
} else {
draw(a);
}
}
}
if (!u.length) return;
function fromCache(user) {
return JSON.parse(localStorage.getItem(`avatar-${user}`));
// should return null if local copy is aged; as it is, avatars will remain in local storage until user clears it
}
const a = await v4_get(`./api/system.ssjs?call=get-avatar&user=${u.join('&user=')}`);
a.forEach(e => {
if (e.data) {
gc.from_bin(atob(e.data), 10, 6, dataURL => {
const o = { ...e, dataURL };
sbbs.avatars.set(o);
draw(o);
}, true);
} else {
const o = { user: e.user, data: null, dataURL: null, created: -1, updated: -1 };
sbbs.avatars.set(o);
draw(o);
}
});
async function fetchAvatar(user) {
const u = [].concat(user);
const data = await v4_get(`./api/system.ssjs?call=get-avatar&user=${u.join('&user=')}`);
[].concat(data).forEach(cacheAvatar);
}
this.draw = async function (user) {
const u = [].concat(user).filter(e => {
const a = fromCache(e);
if (a === null) return true; // Not cached
if (a) draw(a);
});
if (u.length) fetchAvatar(u);
}
})();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment