Fix #18 add ability to block specific users
This commit is contained in:
parent
d716b3882b
commit
052c93d461
@ -5,6 +5,7 @@ YOUTUBE_DISABLE = false
|
|||||||
MASTODON_INSTANCE = 'metalhead.club'
|
MASTODON_INSTANCE = 'metalhead.club'
|
||||||
BASE_URL = 'https://moshingmammut.phlaym.net'
|
BASE_URL = 'https://moshingmammut.phlaym.net'
|
||||||
VERBOSE = false
|
VERBOSE = false
|
||||||
|
IGNORE_USERS = @moshhead@metalhead.club
|
||||||
|
|
||||||
PUBLIC_REFRESH_INTERVAL = 10000
|
PUBLIC_REFRESH_INTERVAL = 10000
|
||||||
PUBLIC_MASTODON_INSTANCE_DISPLAY_NAME = 'Metalhead.club'
|
PUBLIC_MASTODON_INSTANCE_DISPLAY_NAME = 'Metalhead.club'
|
@ -1,10 +1,15 @@
|
|||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
|
import { IGNORE_USERS } from '$env/static/private';
|
||||||
import type { Account, Post, Tag } from '$lib/mastodon/response';
|
import type { Account, Post, Tag } from '$lib/mastodon/response';
|
||||||
import { isTruthy } from '$lib/truthyString';
|
import { isTruthy } from '$lib/truthyString';
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
const { DEV } = import.meta.env;
|
const { DEV } = import.meta.env;
|
||||||
|
|
||||||
const db: sqlite3.Database = new sqlite3.Database('moshingmammut.db');
|
const db: sqlite3.Database = new sqlite3.Database('moshingmammut.db');
|
||||||
|
const ignoredUsers: string[] =
|
||||||
|
IGNORE_USERS === undefined
|
||||||
|
? []
|
||||||
|
: IGNORE_USERS.split(',').map((u) => (u.startsWith('@') ? u.substring(1) : u));
|
||||||
|
|
||||||
if (DEV && isTruthy(env.VERBOSE)) {
|
if (DEV && isTruthy(env.VERBOSE)) {
|
||||||
sqlite3.verbose();
|
sqlite3.verbose();
|
||||||
@ -194,7 +199,7 @@ export async function savePost(post: Post): Promise<undefined> {
|
|||||||
|
|
||||||
export async function getPosts(since: string | null, before: string | null, limit: number) {
|
export async function getPosts(since: string | null, before: string | null, limit: number) {
|
||||||
const promise = await new Promise<Post[]>((resolve, reject) => {
|
const promise = await new Promise<Post[]>((resolve, reject) => {
|
||||||
let filter_query;
|
let filter_query = '';
|
||||||
const params: any = { $limit: limit };
|
const params: any = { $limit: limit };
|
||||||
if (since === null && before === null) {
|
if (since === null && before === null) {
|
||||||
filter_query = '';
|
filter_query = '';
|
||||||
@ -206,6 +211,17 @@ export async function getPosts(since: string | null, before: string | null, limi
|
|||||||
filter_query = 'WHERE posts.created_at < $before';
|
filter_query = 'WHERE posts.created_at < $before';
|
||||||
params.$before = before;
|
params.$before = before;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignoredUsers.forEach((ignoredUser, index) => {
|
||||||
|
const userParam = `$user_${index}`;
|
||||||
|
const acctParam = userParam + 'a';
|
||||||
|
const usernameParam = userParam + 'u';
|
||||||
|
const prefix = filter_query === '' ? ' WHERE' : ' AND';
|
||||||
|
filter_query += `${prefix} acct != ${acctParam} AND username != ${usernameParam} `;
|
||||||
|
params[acctParam] = ignoredUser;
|
||||||
|
params[usernameParam] = ignoredUser;
|
||||||
|
});
|
||||||
|
|
||||||
const sql = `SELECT posts.id, posts.content, posts.created_at, posts.url,
|
const sql = `SELECT posts.id, posts.content, posts.created_at, posts.url,
|
||||||
accounts.id AS account_id, accounts.acct, accounts.username, accounts.display_name,
|
accounts.id AS account_id, accounts.acct, accounts.username, accounts.display_name,
|
||||||
accounts.url AS account_url, accounts.avatar
|
accounts.url AS account_url, accounts.avatar
|
||||||
|
Loading…
Reference in New Issue
Block a user