Skip to content

Commit

Permalink
Add moderation for images
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Jan 26, 2025
1 parent 8eb2d54 commit 7283630
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
4 changes: 4 additions & 0 deletions src/views/feed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,10 @@ export async function index(
const augmentedStory = await addMetadata(story);
if (augmentedStory) {
story = augmentedStory;
const href = normalizeUrl(story.href, { stripWWW: false });
if (href && policy?.images.includes(href) && story.metadata?.image) {
delete story.metadata.image;
}
}

stories.push({
Expand Down
65 changes: 31 additions & 34 deletions src/views/moderation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,72 +106,69 @@ export async function getWriters() {
}

export async function getLists() {
const defaultObj = {
addresses: [],
titles: {},
hrefs: {},
links: [],
messages: [],
};
let addresses = [];
let titles = {};
let hrefs = {};
let links = [];
let messages = [];
let images = [];

let addrResponse;
try {
addrResponse = await getConfig("banlist_addresses");
const addrResponse = await getConfig("banlist_addresses");
addresses = addrResponse.map(({ address }) => address.toLowerCase());
} catch (err) {
log(`banlist_addresses: Couldn't get config: ${err.toString()}`);
return defaultObj;
}
// TODO: Should start using ethers.utils.getAddress
const addresses = addrResponse.map(({ address }) => address.toLowerCase());

let linkResponse;
try {
linkResponse = await getConfig("banlist_links");
const linkResponse = await getConfig("banlist_links");
links = linkResponse.map(({ link }) => normalizeUrl(link));
} catch (err) {
log(`banlist_links: Couldn't get config: ${err.toString()}`);
return defaultObj;
}
const links = linkResponse.map(({ link }) => normalizeUrl(link));

let titleResponse;
try {
titleResponse = await getConfig("moderation_titles");
const imagesResponse = await getConfig("banlist_images");
images = imagesResponse.map(({ link }) =>
normalizeUrl(link, { stripWWW: false }),
);
} catch (err) {
log(`moderation_titles: Couldn't get config: ${err.toString()}`);
return defaultObj;
log(`banlist_images: Couldn't get config: ${err.toString()}`);
}
const titles = {};
for (let obj of titleResponse) {
if (!obj.link || !obj.title) continue;
titles[normalizeUrl(obj.link)] = obj.title;

try {
const titleResponse = await getConfig("moderation_titles");
for (let obj of titleResponse) {
if (!obj.link || !obj.title) continue;
titles[normalizeUrl(obj.link)] = obj.title;
}
} catch (err) {
log(`moderation_titles: Couldn't get config: ${err.toString()}`);
}

let hrefResponse;
try {
hrefResponse = await getConfig("moderation_hrefs");
const hrefResponse = await getConfig("moderation_hrefs");
for (let obj of hrefResponse) {
if (!obj.old || !obj.new) continue;
hrefs[normalizeUrl(obj.old)] = normalizeUrl(obj.new);
}
} catch (err) {
log(`moderation_hrefs: Couldn't get config: ${err.toString()}`);
return defaultObj;
}
const hrefs = {};
for (let obj of hrefResponse) {
if (!obj.old || !obj.new) continue;
hrefs[normalizeUrl(obj.old)] = normalizeUrl(obj.new);
}

let messages;
try {
messages = await getConfig("banlist_messages");
} catch (err) {
log(`banlist_messages: Couldn't get config: ${err.toString()}`);
return defaultObj;
}

return {
hrefs,
messages,
titles,
addresses,
links,
images,
};
}

Expand Down

0 comments on commit 7283630

Please sign in to comment.