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