Skip to content

Commit

Permalink
Remove down-scaling avatar endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Jul 29, 2024
1 parent ee9983d commit b59b5bb
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 58 deletions.
48 changes: 0 additions & 48 deletions src/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -528,54 +528,6 @@ export async function launch(trie, libp2p) {
);
return reply.status(200).type("text/html").send(content);
});
app.get("/avatar/:address", async (request, reply) => {
let address;
try {
address = utils.getAddress(request.params.address);
} catch (err) {
return reply
.status(404)
.type("text/plain")
.send("No valid Ethereum address");
}
let data;
try {
data = await ens.resolve(address);
} catch (err) {
return reply.status(404).type("text/plain").send(err.message);
}

const size = 250;
let url;
if (
data.safeAvatar.includes("imagedelivery.net") ||
data.safeAvatar.includes("imgur.com")
) {
url = data.safeAvatar;
} else {
url = preview.cfTransform(data.safeAvatar, size);
}
const response = await fetch(url);
if (!response.ok) {
return reply.status(404).type("text/plain").send("Not Found");
}

try {
const message = await response.clone().text();
if (message.startsWith("ERROR")) {
return reply.status(404).type("text/plain").send("Not Found");
}
} catch (err) {
return reply.status(500).type("text/plain").send("Internal Server Error");
}

reply.header("Content-Type", response.headers.get("Content-Type"));
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, must-revalidate, stale-while-revalidate=31536000",
);
response.body.pipe(reply);
});
app.get("/stories", async (request, reply) => {
let submission;
try {
Expand Down
4 changes: 2 additions & 2 deletions src/views/activity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function generateCommentRow(activity, identity, bgColor, theme) {
const comment = DOMPurify.sanitize(truncateComment(activity.message.title));
const avatar = identity.safeAvatar
? html`<img
src="/avatar/${identity.address}"
src="${DOMPurify.sanitize(identity.safeAvatar)}"
alt="avatar"
style="border: 1px solid #828282; width: 28px; height: 28px; border-radius: 2px; margin-top: 1.5rem;"
/>`
Expand Down Expand Up @@ -162,7 +162,7 @@ function generateRow(lastUpdate, theme) {
)}"
>
<img
src="/avatar/${identity.address}"
src="${DOMPurify.sanitize(identity.safeAvatar)}"
alt="avatar"
style="z-index: ${index}; width: ${size}px; height: ${size}px; border: 1px solid #828282; border-radius: 2px; margin-left: 15px;"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/views/best.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function getStories(trie, page, period, domain) {
for await (let upvoter of story.upvoters) {
const profile = await ens.resolve(upvoter);
if (profile.safeAvatar) {
avatars.push(`/avatar/${profile.address}`);
avatars.push(profile.safeAvatar);
}
}
const isOriginal = Object.keys(writers).some(
Expand Down
2 changes: 1 addition & 1 deletion src/views/comments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function generateCommentRow(activity, identity, borderColor, theme) {
const comment = DOMPurify.sanitize(truncateComment(activity.message.title));
const avatar = identity.safeAvatar
? html`<img
src="/avatar/${identity.address}"
src="${DOMPurify.sanitize(identity.safeAvatar)}"
alt="avatar"
style="border: 1px solid #828282; width: 28px; height: 28px; border-radius: 2px; margin-top: 1.5rem;"
/>`
Expand Down
4 changes: 3 additions & 1 deletion src/views/community.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ export default async function (trie, theme, query, identity) {
${ensData.safeAvatar
? html`<img
loading="lazy"
src="/avatar/${ensData.address}"
src="${DOMPurify.sanitize(
ensData.safeAvatar,
)}"
style="border: 1px solid #828282; width: 20px; height: 20px; border-radius: 2px; margin-right: 15px;"
/>`
: html`
Expand Down
2 changes: 1 addition & 1 deletion src/views/feed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export async function index(trie, page, domain) {
for await (let upvoter of story.upvoters) {
const profile = await ens.resolve(upvoter);
if (profile.safeAvatar) {
avatars.push(`/avatar/${profile.address}`);
avatars.push(profile.safeAvatar);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/new.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function recompute() {
for await (let upvoter of story.upvoters) {
const profile = await ens.resolve(upvoter);
if (profile.safeAvatar) {
avatars.push(`/avatar/${profile.address}`);
avatars.push(profile.safeAvatar);
}
}
const isOriginal = Object.keys(writers).some(
Expand Down
2 changes: 1 addition & 1 deletion src/views/story.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default async function (trie, theme, index, value) {
address: profile.address,
});
if (profile.safeAvatar) {
avatars.push(`/avatar/${profile.address}`);
avatars.push(profile.safeAvatar);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/src/CommentSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Comment = ({ comment, index }) => {
{comment.identity.safeAvatar && (
<img
loading="lazy"
src={`/avatar/${comment.identity.address}`}
src={comment.identity.safeAvatar}
alt="avatar"
style={{
marginRight: "5px",
Expand Down
3 changes: 2 additions & 1 deletion src/web/src/SignupDialogue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const SignupDialogue = (props) => {
!isEligible &&
(window.location.pathname === "/submit" ||
window.location.pathname === "/stories" ||
window.location.pathname === "/comments")
window.location.pathname === "/comments" ||
window.location.pathname === "/community")
) {
return (
<div
Expand Down

0 comments on commit b59b5bb

Please sign in to comment.