Commit 77f26b50550020fe2795e58ee7b816df90cdca45
make sure that key is a valid feedId before checking avatar
Ev Bogue committed on 6/25/2018, 11:39:52 PMParent: a91aacd99613bd8ba1f3551725dd523017b34d18
Files changed
avatar.js | changed |
avatar.js | ||
---|---|---|
@@ -10,39 +10,42 @@ | ||
10 | 10 | var config = require('./config')() |
11 | 11 | |
12 | 12 | var id = require('./keys').id |
13 | 13 | |
14 | +var ref = require('ssb-ref') | |
15 | + | |
14 | 16 | module.exports.name = function (key) { |
15 | 17 | |
16 | 18 | var avatarname = h('span', key.substring(0, 10)) |
17 | - | |
18 | - avatar(sbot, id, key, function (err, data) { | |
19 | - if (err) throw err | |
20 | - if (data.name) { | |
21 | - if (data.name[0] != '@') { | |
22 | - var name = '@' + data.name | |
23 | - } else { | |
24 | - var name = data.name | |
19 | + if (ref.isFeedId(key)) { | |
20 | + avatar(sbot, id, key, function (err, data) { | |
21 | + if (err) throw err | |
22 | + if (data.name) { | |
23 | + if (data.name[0] != '@') { | |
24 | + var name = '@' + data.name | |
25 | + } else { | |
26 | + var name = data.name | |
27 | + } | |
28 | + localStorage[key + 'name'] = name | |
29 | + avatarname.textContent = name | |
25 | 30 | } |
26 | - localStorage[key + 'name'] = name | |
27 | - avatarname.textContent = name | |
28 | - } | |
29 | - }) | |
30 | - | |
31 | + }) | |
32 | + } | |
31 | 33 | return avatarname |
32 | 34 | } |
33 | 35 | |
34 | 36 | module.exports.image = function (key) { |
35 | 37 | var img = visualize(new Buffer(key.substring(1), 'base64'), 256) |
36 | 38 | |
37 | - avatar(sbot, id, key, function (err, data) { | |
38 | - if (err) throw err | |
39 | - if (data.image) { | |
40 | - localStorage[key + 'image'] = data.image | |
41 | - img.src = config.blobsUrl + data.image | |
42 | - } | |
43 | - }) | |
44 | - | |
39 | + if (ref.isFeedId(key)) { | |
40 | + avatar(sbot, id, key, function (err, data) { | |
41 | + if (err) throw err | |
42 | + if (data.image) { | |
43 | + localStorage[key + 'image'] = data.image | |
44 | + img.src = config.blobsUrl + data.image | |
45 | + } | |
46 | + }) | |
47 | + } | |
45 | 48 | return img |
46 | 49 | } |
47 | 50 | |
48 | 51 | module.exports.cachedName = function (key) { |
@@ -50,19 +53,21 @@ | ||
50 | 53 | |
51 | 54 | if (localStorage[key + 'name']) { |
52 | 55 | avatarname.textContent = localStorage[key + 'name'] |
53 | 56 | } else { |
54 | - avatar(sbot, id, key, function (err, data) { | |
55 | - if (data.name) { | |
56 | - if (data.name[0] != '@') { | |
57 | - var name = '@' + data.name | |
58 | - } else { | |
59 | - var name = data.name | |
57 | + if (ref.isFeedId(key)) { | |
58 | + avatar(sbot, id, key, function (err, data) { | |
59 | + if (data.name) { | |
60 | + if (data.name[0] != '@') { | |
61 | + var name = '@' + data.name | |
62 | + } else { | |
63 | + var name = data.name | |
64 | + } | |
65 | + localStorage[key + 'name'] = name | |
66 | + avatarname.textContent = name | |
60 | 67 | } |
61 | - localStorage[key + 'name'] = name | |
62 | - avatarname.textContent = name | |
63 | - } | |
64 | - }) | |
68 | + }) | |
69 | + } | |
65 | 70 | } |
66 | 71 | |
67 | 72 | return avatarname |
68 | 73 | } |
@@ -72,14 +77,16 @@ | ||
72 | 77 | |
73 | 78 | if (localStorage[key + 'image']) { |
74 | 79 | img.src = config.blobsUrl + localStorage[key + 'image'] |
75 | 80 | } else { |
76 | - avatar(sbot, id, key, function (err, data) { | |
77 | - if (data.image) { | |
78 | - localStorage[key + 'image'] = data.image | |
79 | - img.src = config.blobsUrl + data.image | |
80 | - } | |
81 | - }) | |
81 | + if (ref.isFeedId(key)) { | |
82 | + avatar(sbot, id, key, function (err, data) { | |
83 | + if (data.image) { | |
84 | + localStorage[key + 'image'] = data.image | |
85 | + img.src = config.blobsUrl + data.image | |
86 | + } | |
87 | + }) | |
88 | + } | |
82 | 89 | } |
83 | 90 | |
84 | 91 | return img |
85 | 92 | } |
Built with git-ssb-web