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'
|
||||
BASE_URL = 'https://moshingmammut.phlaym.net'
|
||||
VERBOSE = false
|
||||
IGNORE_USERS = @moshhead@metalhead.club
|
||||
|
||||
PUBLIC_REFRESH_INTERVAL = 10000
|
||||
PUBLIC_MASTODON_INSTANCE_DISPLAY_NAME = 'Metalhead.club'
|
@ -1,10 +1,15 @@
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { IGNORE_USERS } from '$env/static/private';
|
||||
import type { Account, Post, Tag } from '$lib/mastodon/response';
|
||||
import { isTruthy } from '$lib/truthyString';
|
||||
import sqlite3 from 'sqlite3';
|
||||
const { DEV } = import.meta.env;
|
||||
|
||||
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)) {
|
||||
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) {
|
||||
const promise = await new Promise<Post[]>((resolve, reject) => {
|
||||
let filter_query;
|
||||
let filter_query = '';
|
||||
const params: any = { $limit: limit };
|
||||
if (since === null && before === null) {
|
||||
filter_query = '';
|
||||
@ -206,6 +211,17 @@ export async function getPosts(since: string | null, before: string | null, limi
|
||||
filter_query = 'WHERE posts.created_at < $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,
|
||||
accounts.id AS account_id, accounts.acct, accounts.username, accounts.display_name,
|
||||
accounts.url AS account_url, accounts.avatar
|
||||
|
Loading…
Reference in New Issue
Block a user