add logos
This commit is contained in:
parent
d30069d796
commit
b01184d151
@ -249,6 +249,8 @@ class API:
|
||||
self.mimeType = 'text/html'
|
||||
response = siteData.split(b'-', 2)[-1]
|
||||
resp = Response(response)
|
||||
elif action == 'info':
|
||||
resp = new Response(json.dumps({'id' : 'not yet implemented'}))
|
||||
elif action == "insertBlock":
|
||||
response = {'success' : False, 'reason' : 'An unknown error occurred'}
|
||||
|
||||
|
2
onionr/static-data/www/ui/dist/index.html
vendored
2
onionr/static-data/www/ui/dist/index.html
vendored
@ -43,7 +43,7 @@
|
||||
<img id="onionr-profile-user-icon" class="onionr-profile-user-icon" src="img/default.png">
|
||||
</div>
|
||||
<div class="col-8 col-lg-12">
|
||||
<h2 id="onionr-profile-username" class="onionr-profile-username text-left text-lg-center text-sm-left">arinerron</h2>
|
||||
<h2 id="onionr-profile-username" class="onionr-profile-username text-left text-lg-center text-sm-left" data-placement="top" data-toggle="tooltip" title="unknown">arinerron</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
32
onionr/static-data/www/ui/dist/js/main.js
vendored
32
onionr/static-data/www/ui/dist/js/main.js
vendored
@ -17,6 +17,13 @@ function remove(key) {
|
||||
return localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
function getParameter(name) {
|
||||
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
|
||||
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
/* usermap localStorage stuff */
|
||||
|
||||
var usermap = JSON.parse(get('usermap', '{}'));
|
||||
|
||||
function getUserMap() {
|
||||
@ -24,11 +31,29 @@ function getUserMap() {
|
||||
}
|
||||
|
||||
function deserializeUser(id) {
|
||||
if(!(id in getUserMap()))
|
||||
return null;
|
||||
|
||||
var serialized = getUserMap()[id]
|
||||
var user = new User();
|
||||
|
||||
user.setName(serialized['name']);
|
||||
user.setID(serialized['id']);
|
||||
user.setIcon(serialized['icon']);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
function serializeUser(user) {
|
||||
if(user !== null && user !== undefined) {
|
||||
var serialized = {'name' : user.getName(), 'id' : user.getID(), 'icon' : user.getIcon()};
|
||||
|
||||
usermap[user.getID()] = serialized;
|
||||
|
||||
set('usermap', JSON.stringify(getUserMap()));
|
||||
|
||||
return serialized;
|
||||
}
|
||||
}
|
||||
|
||||
/* returns a relative date format, e.g. "5 minutes" */
|
||||
@ -219,7 +244,7 @@ class Post {
|
||||
// postTemplate = postTemplate.replaceAll('$user-id-truncated', Sanitize.html(this.getUser().getID().split('-').slice(0, 4).join('-')));
|
||||
|
||||
postTemplate = postTemplate.replaceAll('$user-id', Sanitize.html(this.getUser().getID()));
|
||||
postTemplate = postTemplate.replaceAll('$user-image', Sanitize.html(this.getUser().getIcon()));
|
||||
postTemplate = postTemplate.replaceAll('$user-image', "data:image/jpeg;base64," + Sanitize.html(this.getUser().getIcon()));
|
||||
postTemplate = postTemplate.replaceAll('$content', Sanitize.html(this.getContent()));
|
||||
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
|
||||
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
|
||||
@ -449,3 +474,8 @@ if(getWebPassword() === null) {
|
||||
setWebPassword(password);
|
||||
window.location.reload(true);
|
||||
}
|
||||
|
||||
var tt = getParameter("timingToken");
|
||||
if(tt !== null && tt !== undefined) {
|
||||
setTimingToken(tt);
|
||||
}
|
||||
|
63
onionr/static-data/www/ui/dist/js/timeline.js
vendored
63
onionr/static-data/www/ui/dist/js/timeline.js
vendored
@ -1,21 +1,57 @@
|
||||
function getUserInfo(id, callback) {
|
||||
var user = deserializeUser(id);
|
||||
if(user === null) {
|
||||
Block.getBlocks({'type' : 'onionr-user-info', 'signed' : true, 'reverse' : true}, function(data) {
|
||||
if(data.length !== 0) {
|
||||
try {
|
||||
user = new User();
|
||||
|
||||
var userInfo = JSON.parse(data[0].getContent());
|
||||
|
||||
if(userInfo['id'] === id) {
|
||||
user.setName(userInfo['name']);
|
||||
user.setIcon(userInfo['icon']);
|
||||
user.setID(id);
|
||||
|
||||
serializeUser(user);
|
||||
|
||||
return callback(user);
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return callback(null);
|
||||
}
|
||||
} else {
|
||||
return callback(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return callback(user);
|
||||
}
|
||||
}
|
||||
|
||||
/* just for testing rn */
|
||||
Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, function(data) {
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
try {
|
||||
var block = data[i];
|
||||
|
||||
var post = new Post();
|
||||
var user = new User();
|
||||
var finished = false;
|
||||
getUserInfo(new String(block.getHeader('signer', 'unknown')), function(user) {
|
||||
var post = new Post();
|
||||
|
||||
var blockContent = JSON.parse(block.getContent());
|
||||
var blockContent = JSON.parse(block.getContent());
|
||||
|
||||
user.setName('unknown');
|
||||
user.setID(new String(block.getHeader('signer', 'unknown')));
|
||||
post.setContent(blockContent['content']);
|
||||
post.setPostDate(block.getDate());
|
||||
post.setUser(user);
|
||||
post.setContent(blockContent['content']);
|
||||
post.setPostDate(block.getDate());
|
||||
post.setUser(user);
|
||||
|
||||
document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
|
||||
document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
|
||||
|
||||
finished = true;
|
||||
});
|
||||
|
||||
while(!finished);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
@ -23,5 +59,14 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
|
||||
});
|
||||
|
||||
function viewProfile(id, name) {
|
||||
id = decodeURIComponent(id);
|
||||
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(decodeURIComponent(name));
|
||||
|
||||
getUserInfo(id, function(data) {
|
||||
if(data !== null) {
|
||||
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(data.getName());
|
||||
document.getElementById("onionr-profile-username").title = Sanitize.html(data.getID());
|
||||
document.getElementById("onionr-profile-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(data.getIcon());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
<img id="onionr-profile-user-icon" class="onionr-profile-user-icon" src="img/default.png">
|
||||
</div>
|
||||
<div class="col-8 col-lg-12">
|
||||
<h2 id="onionr-profile-username" class="onionr-profile-username text-left text-lg-center text-sm-left">arinerron</h2>
|
||||
<h2 id="onionr-profile-username" class="onionr-profile-username text-left text-lg-center text-sm-left" data-placement="top" data-toggle="tooltip" title="unknown">arinerron</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -17,6 +17,13 @@ function remove(key) {
|
||||
return localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
function getParameter(name) {
|
||||
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
|
||||
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
/* usermap localStorage stuff */
|
||||
|
||||
var usermap = JSON.parse(get('usermap', '{}'));
|
||||
|
||||
function getUserMap() {
|
||||
@ -24,11 +31,29 @@ function getUserMap() {
|
||||
}
|
||||
|
||||
function deserializeUser(id) {
|
||||
if(!(id in getUserMap()))
|
||||
return null;
|
||||
|
||||
var serialized = getUserMap()[id]
|
||||
var user = new User();
|
||||
|
||||
user.setName(serialized['name']);
|
||||
user.setID(serialized['id']);
|
||||
user.setIcon(serialized['icon']);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
function serializeUser(user) {
|
||||
if(user !== null && user !== undefined) {
|
||||
var serialized = {'name' : user.getName(), 'id' : user.getID(), 'icon' : user.getIcon()};
|
||||
|
||||
usermap[user.getID()] = serialized;
|
||||
|
||||
set('usermap', JSON.stringify(getUserMap()));
|
||||
|
||||
return serialized;
|
||||
}
|
||||
}
|
||||
|
||||
/* returns a relative date format, e.g. "5 minutes" */
|
||||
@ -187,7 +212,7 @@ class Post {
|
||||
// postTemplate = postTemplate.replaceAll('$user-id-truncated', Sanitize.html(this.getUser().getID().split('-').slice(0, 4).join('-')));
|
||||
|
||||
postTemplate = postTemplate.replaceAll('$user-id', Sanitize.html(this.getUser().getID()));
|
||||
postTemplate = postTemplate.replaceAll('$user-image', Sanitize.html(this.getUser().getIcon()));
|
||||
postTemplate = postTemplate.replaceAll('$user-image', "data:image/jpeg;base64," + Sanitize.html(this.getUser().getIcon()));
|
||||
postTemplate = postTemplate.replaceAll('$content', Sanitize.html(this.getContent()));
|
||||
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
|
||||
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
|
||||
@ -417,3 +442,8 @@ if(getWebPassword() === null) {
|
||||
setWebPassword(password);
|
||||
window.location.reload(true);
|
||||
}
|
||||
|
||||
var tt = getParameter("timingToken");
|
||||
if(tt !== null && tt !== undefined) {
|
||||
setTimingToken(tt);
|
||||
}
|
||||
|
@ -1,3 +1,34 @@
|
||||
function getUserInfo(id, callback) {
|
||||
var user = deserializeUser(id);
|
||||
if(user === null) {
|
||||
Block.getBlocks({'type' : 'onionr-user-info', 'signed' : true, 'reverse' : true}, function(data) {
|
||||
if(data.length !== 0) {
|
||||
try {
|
||||
user = new User();
|
||||
|
||||
var userInfo = JSON.parse(data[0].getContent());
|
||||
|
||||
if(userInfo['id'] === id) {
|
||||
user.setName(userInfo['name']);
|
||||
user.setIcon(userInfo['icon']);
|
||||
user.setID(id);
|
||||
|
||||
serializeUser(user);
|
||||
|
||||
return callback(user);
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return callback(null);
|
||||
}
|
||||
} else {
|
||||
return callback(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return callback(user);
|
||||
}
|
||||
}
|
||||
|
||||
/* just for testing rn */
|
||||
Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, function(data) {
|
||||
@ -5,18 +36,22 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
|
||||
try {
|
||||
var block = data[i];
|
||||
|
||||
var post = new Post();
|
||||
var user = new User();
|
||||
var finished = false;
|
||||
getUserInfo(new String(block.getHeader('signer', 'unknown')), function(user) {
|
||||
var post = new Post();
|
||||
|
||||
var blockContent = JSON.parse(block.getContent());
|
||||
var blockContent = JSON.parse(block.getContent());
|
||||
|
||||
user.setName('unknown');
|
||||
user.setID(new String(block.getHeader('signer', 'unknown')));
|
||||
post.setContent(blockContent['content']);
|
||||
post.setPostDate(block.getDate());
|
||||
post.setUser(user);
|
||||
post.setContent(blockContent['content']);
|
||||
post.setPostDate(block.getDate());
|
||||
post.setUser(user);
|
||||
|
||||
document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
|
||||
document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
|
||||
|
||||
finished = true;
|
||||
});
|
||||
|
||||
while(!finished);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
@ -24,5 +59,14 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
|
||||
});
|
||||
|
||||
function viewProfile(id, name) {
|
||||
id = decodeURIComponent(id);
|
||||
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(decodeURIComponent(name));
|
||||
|
||||
getUserInfo(id, function(data) {
|
||||
if(data !== null) {
|
||||
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(data.getName());
|
||||
document.getElementById("onionr-profile-username").title = Sanitize.html(data.getID());
|
||||
document.getElementById("onionr-profile-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(data.getIcon());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user