2023-09-12 22:48:10 +02:00
|
|
|
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
2023-09-13 02:29:13 +02:00
|
|
|
import { APObject } from "activitypub-types";
|
2023-09-18 07:38:08 +02:00
|
|
|
import { getConfig } from "@config";
|
|
|
|
|
import { appendFile } from "fs/promises";
|
2023-09-12 22:48:10 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stores an ActivityPub object as raw JSON-LD data
|
|
|
|
|
*/
|
|
|
|
|
@Entity({
|
|
|
|
|
name: "objects",
|
|
|
|
|
})
|
|
|
|
|
export class RawObject extends BaseEntity {
|
|
|
|
|
@PrimaryGeneratedColumn("uuid")
|
|
|
|
|
id!: string;
|
|
|
|
|
|
2023-09-14 05:39:11 +02:00
|
|
|
@Column("jsonb")
|
2023-09-12 22:48:10 +02:00
|
|
|
data!: APObject;
|
2023-09-18 07:38:08 +02:00
|
|
|
|
|
|
|
|
static async getById(id: string) {
|
|
|
|
|
return await RawObject.createQueryBuilder("object")
|
|
|
|
|
.where("object.data->>'id' = :id", {
|
|
|
|
|
id,
|
|
|
|
|
})
|
|
|
|
|
.getOne();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async isObjectFiltered() {
|
|
|
|
|
const config = getConfig();
|
|
|
|
|
|
|
|
|
|
const filter_result = await Promise.all(
|
|
|
|
|
config.filters.note_filters.map(async filter => {
|
|
|
|
|
if (
|
|
|
|
|
this.data.type === "Note" &&
|
|
|
|
|
this.data.content?.match(filter)
|
|
|
|
|
) {
|
|
|
|
|
// Log filter
|
|
|
|
|
|
|
|
|
|
if (config.logging.log_filters)
|
|
|
|
|
await appendFile(
|
|
|
|
|
process.cwd() + "/logs/filters.log",
|
|
|
|
|
`${new Date().toISOString()} Filtered note content: "${this.data.content.replaceAll(
|
|
|
|
|
"\n",
|
|
|
|
|
" "
|
|
|
|
|
)}" (ID: ${
|
|
|
|
|
this.data.id
|
|
|
|
|
}) based on rule: ${filter}\n`
|
|
|
|
|
);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return filter_result.includes(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async exists(id: string) {
|
|
|
|
|
return !!(await RawObject.getById(id));
|
|
|
|
|
}
|
2023-09-13 02:29:13 +02:00
|
|
|
}
|