Removed rating detection.
Removed rating detection logic due to inconsistent behavior across domains.master
parent
cecb0f0f30
commit
f9014fff03
|
|
@ -2,3 +2,5 @@
|
|||
node_modules/
|
||||
dist/
|
||||
coverage/
|
||||
package-lock.json
|
||||
package.json
|
||||
|
|
|
|||
|
|
@ -70,5 +70,8 @@
|
|||
"setupFilesAfterEnv": [
|
||||
"./src/test/jest.setup.ts"
|
||||
]
|
||||
},
|
||||
"overrides": {
|
||||
"@types/node": "18.19.115"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ interface Attachment {
|
|||
url: string; // original URL, ?sensitive=true stripped
|
||||
previewUrl?: string; // local cached preview (for video posters)
|
||||
contentType: ContentType;
|
||||
sensitive: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -31,9 +30,9 @@ interface Attachment {
|
|||
*/
|
||||
export default class Mastodon extends ScrapeEngineBase {
|
||||
name = "mastodon";
|
||||
features: ScrapeEngineFeature[] = ["content", "rating", "source"];
|
||||
features: ScrapeEngineFeature[] = ["content", "source"];
|
||||
notes = [
|
||||
"Rating is assumed to be unsafe when source is marked sensitive."
|
||||
"Rating is assumed to be safe."
|
||||
];
|
||||
|
||||
// Explicit hosts we claim. Other Mastodon instances are picked up by the
|
||||
|
|
@ -59,12 +58,8 @@ export default class Mastodon extends ScrapeEngineBase {
|
|||
post.pageUrl = document.location.href;
|
||||
post.contentUrl = att.url;
|
||||
post.contentType = att.contentType;
|
||||
post.sources = [document.location.href];
|
||||
post.referrer = document.location.origin;
|
||||
|
||||
// Baraag is an adult-focused instance: default to safe,
|
||||
// and bump to explicit when the source flags the attachment.
|
||||
post.rating = att.sensitive ? "unsafe" : "safe";
|
||||
// post.rating = "safe";
|
||||
|
||||
// Cached preview as a poster frame for videos.
|
||||
if (att.contentType === "video" && att.previewUrl) {
|
||||
|
|
@ -104,7 +99,7 @@ export default class Mastodon extends ScrapeEngineBase {
|
|||
const img = a.querySelector("img");
|
||||
const preview = img?.currentSrc || img?.src;
|
||||
|
||||
const { url, sensitive } = this.normalizeUrl(rawHref);
|
||||
const url = this.normalizeUrl(rawHref);
|
||||
const finalUrl = url || this.largestFromSrcset(img);
|
||||
if (!finalUrl) continue;
|
||||
|
||||
|
|
@ -112,7 +107,6 @@ export default class Mastodon extends ScrapeEngineBase {
|
|||
url: finalUrl,
|
||||
previewUrl: preview && preview !== finalUrl ? preview : undefined,
|
||||
contentType: this.contentTypeFor(finalUrl),
|
||||
sensitive,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -124,14 +118,13 @@ export default class Mastodon extends ScrapeEngineBase {
|
|||
* The marker is metadata, not part of the media URL, and leaving it in can
|
||||
* confuse booru deduplication and content-type sniffing.
|
||||
*/
|
||||
private normalizeUrl(href: string): { url: string; sensitive: boolean } {
|
||||
private normalizeUrl(href: string): string {
|
||||
try {
|
||||
const u = new URL(href, document.location.href);
|
||||
const sensitive = u.searchParams.get("sensitive") === "true";
|
||||
u.searchParams.delete("sensitive");
|
||||
return { url: u.toString(), sensitive };
|
||||
return u.toString();
|
||||
} catch {
|
||||
return { url: href, sensitive: false };
|
||||
return href;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue