Skip to content

Commit

Permalink
overhaul auto source handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Oct 19, 2024
1 parent 566a7d4 commit 3d8ae1e
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 109 deletions.
4 changes: 4 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
maidboye:
image: maidboye
build: .
6 changes: 6 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export class Configuration extends PrivateConfiguration {
static override get tempAuth() {
return super.tempAuth;
}
static override get femboyFansUser() {
return super.femboyFansUser;
}
static override get femboyFansKey() {
return super.femboyFansKey;
}

/* db */
static get dbHost() {
Expand Down
2 changes: 1 addition & 1 deletion src/config/private
19 changes: 14 additions & 5 deletions src/events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ export default new ClientEvent("messageCreate", async function messageCreateEven
if (sauce.post !== null && !sources.some(s => s.startsWith("https://e621.net/posts/"))) {
sources.unshift(`https://e621.net/posts/${sauce.post.id}`);
}
if (sauce.ffpost !== null && !sources.some(s => s.startsWith("https://femboy.fan/posts/"))) {
sources.unshift(`https://femboy.fan/posts/${sauce.ffpost.id}`);
}
await this.rest.channels.createMessage(msg.channelID, {
content: sources.join("\n"),
messageReference: {
Expand Down Expand Up @@ -214,6 +217,9 @@ export default new ClientEvent("messageCreate", async function messageCreateEven
if (sauce.post !== null && !sources.some(s => s.startsWith("https://e621.net/posts/"))) {
sources.unshift(`https://e621.net/posts/${sauce.post.id}`);
}
if (sauce.ffpost !== null && !sources.some(s => s.startsWith("https://femboy.fan/posts/"))) {
sources.unshift(`https://femboy.fan/posts/${sauce.ffpost.id}`);
}
if (sources.length !== 0) {
await this.rest.channels.createMessage(msg.channelID, {
content: sources.join("\n"),
Expand Down Expand Up @@ -252,11 +258,14 @@ export default new ClientEvent("messageCreate", async function messageCreateEven
}
});
const md5 = createHash("md5").update(Buffer.from(await file.arrayBuffer())).digest("hex");
const att = await directMD5(md5);
if (att !== null) {
const sources = Array.isArray(att.sourceOverride) ? att.sourceOverride : (att.sourceOverride === undefined ? [] : [att.sourceOverride]);
if (att.post !== null && !sources.some(s => s.startsWith("https://e621.net/posts/"))) {
sources.unshift(`https://e621.net/posts/${att.post.id}`);
const sauce = await directMD5(md5);
if (sauce !== null) {
const sources = Array.isArray(sauce.sourceOverride) ? sauce.sourceOverride : (sauce.sourceOverride === undefined ? [] : [sauce.sourceOverride]);
if (sauce.post !== null && !sources.some(s => s.startsWith("https://e621.net/posts/"))) {
sources.unshift(`https://e621.net/posts/${sauce.post.id}`);
}
if (sauce.ffpost !== null && !sources.some(s => s.startsWith("https://femboy.fan/posts/"))) {
sources.unshift(`https://femboy.fan/posts/${sauce.ffpost.id}`);
}
if (sources.length !== 0) {
await this.rest.channels.createMessage(msg.channelID, {
Expand Down
105 changes: 105 additions & 0 deletions src/util/@types/femboyfans.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
declare namespace FemboyFans {
export interface Post {
approver_id: number | null;
change_seq: number;
comment_count: number;
created_at: string;
crop: Crop;
description: string;
duration: null;
fav_count: number;
file: File;
flags: Flags;
framecount: null;
has_notes: boolean;
id: number;
is_favorited: boolean;
locked_tags: Array<string>;
own_vote: number;
pools: Array<number>;
preview: Crop;
qtags: Array<string>;
rating: string;
relationships: Relationships;
sample: Crop;
score: Score;
sources: Array<string>;
tags: Tags;
thumbnail_frame: null;
updated_at: string;
upload_url: string | null;
uploader_id: number;
views: Views;
}

export interface Crop {
alternates?: Alternates;
has?: boolean;
height: number;
url: string;
width: number;
}

export interface Alternates {
"480p"?: Alternate;
"720p"?: Alternate;
"original": Alternate;
}

export interface Alternate {
height: number;
type: "video";
urls: [webm: string | null, mp4: string | null];
width: number;
}

export interface File {
ext: string;
height: number;
md5: string;
size: number;
url: string;
width: number;
}

export interface Flags {
deleted: boolean;
flagged: boolean;
note_locked: boolean;
pending: boolean;
rating_locked: boolean;
status_locked: boolean;
}

export interface Relationships {
children: Array<number>;
has_active_children: boolean;
has_children: boolean;
parent_id: number | null;
}

export interface Score {
down: number;
total: number;
up: number;
}

export interface Tags {
artist: Array<string>;
character: Array<string>;
copyright: Array<string>;
gender: Array<string>;
general: Array<string>;
invalid: Array<string>;
lore: Array<string>;
meta: Array<string>;
species: Array<string>;
voice_actor: Array<string>;
}

export interface Views {
daily: number;
total: number;
}

}
5 changes: 4 additions & 1 deletion src/util/RequestProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { fetch } from "undici";

export default class RequestProxy {
static DIRECT_WHITELIST = [
/^https?:\/\/static\d+\.e(621|926)\.net\//,
/^https?:\/\/static\d+\.e(621|926)\.net/,
/^https?:\/\/static\.femboy\.fan/,
/^https?:\/\/v2\.yiff\.media/,
/^https?:\/\/yiff\.media\/V2/,
/^https:\/\/media\.discordapp\.net/,
/^https:\/\/cdn\.discordapp\.com/
];
Expand Down
Loading

0 comments on commit 3d8ae1e

Please sign in to comment.