Compare commits

...

3 Commits

Author SHA1 Message Date
445f38c6be filter embed 2025-01-15 01:51:45 -05:00
f8a71d0aab maximum call stack size exceeded fuckin 2025-01-15 01:06:55 -05:00
49c8c9f124 filter youtube tracking links 2025-01-15 00:53:22 -05:00

View File

@ -35,7 +35,8 @@ import * as lex from '../lexicon/lexicons'
import { isRecord as isFeedGenerator } from '../lexicon/types/app/bsky/feed/generator'
import { isRecord as isStarterPack } from '../lexicon/types/app/bsky/graph/starterpack'
import { isRecord as isPost } from '../lexicon/types/app/bsky/feed/post'
import { isTag } from '../lexicon/types/app/bsky/richtext/facet'
import { isLink, isTag } from '../lexicon/types/app/bsky/richtext/facet'
import { isMain } from '../lexicon/types/app/bsky/embed/external'
import { isRecord as isList } from '../lexicon/types/app/bsky/graph/list'
import { isRecord as isProfile } from '../lexicon/types/app/bsky/actor/profile'
import { hasExplicitSlur } from '../handle/explicit-slurs'
@ -120,6 +121,7 @@ export const prepareCreate = async (opts: {
const rkey = opts.rkey || nextRkey.toString()
// @TODO: validate against Lexicon record 'key' type, not just overall recordkey syntax
ensureValidRecordKey(rkey)
filterSi(record)
assertNoExplicitSlurs(rkey, record)
return {
action: WriteOpAction.Create,
@ -221,6 +223,26 @@ async function cidForSafeRecord(record: RepoRecord) {
}
}
function filterSi(record: RepoRecord) {
const filt = str => str.replace(/si=[\w-]{16}/, '');
if (isPost(record)) {
// app truncates url so si will never be in text
for (const facet of record.facets || []) {
for (const feat of facet.features) {
if (isLink(feat)) {
feat.uri = filt(feat.uri);
}
}
}
if (record.embed) {
if (isMain(record.embed)) {
record.embed.external.uri = filt(record.embed.external.uri);
}
//todo filter alt text
}
}
}
function assertNoExplicitSlurs(rkey: string, record: RepoRecord) {
let toCheck = ''
if (isProfile(record)) {