Compare commits

..

2 commits

Author SHA1 Message Date
c38902c976
fix (backend): apply word mutes in notifications
Co-authored-by: naskya <m@naskya.net>
2024-02-23 20:35:37 +09:00
ffb6c8da58
fix (backend-rs): properly compare strings in check_word_mute
Co-authored-by: naskya <m@naskya.net>
2024-02-23 20:35:16 +09:00
23 changed files with 62 additions and 120 deletions

2
.gitignore vendored
View file

@ -58,8 +58,6 @@ packages/backend/assets/LICENSE
packages/megalodon/lib packages/megalodon/lib
packages/megalodon/.idea packages/megalodon/.idea
*.traineddata
# blender backups # blender backups
*.blend1 *.blend1
*.blend2 *.blend2

View file

@ -8,6 +8,7 @@ const replace = require("gulp-replace");
const terser = require("gulp-terser"); const terser = require("gulp-terser");
const cssnano = require("gulp-cssnano"); const cssnano = require("gulp-cssnano");
const locales = require("./locales");
const meta = require("./package.json"); const meta = require("./package.json");
gulp.task("copy:backend:views", () => gulp.task("copy:backend:views", () =>
@ -28,9 +29,8 @@ gulp.task("copy:client:fonts", () =>
.pipe(gulp.dest("./built/_client_dist_/fonts/")), .pipe(gulp.dest("./built/_client_dist_/fonts/")),
); );
gulp.task("copy:client:locales", async (cb) => { gulp.task("copy:client:locales", (cb) => {
fs.mkdirSync("./built/_client_dist_/locales", { recursive: true }); fs.mkdirSync("./built/_client_dist_/locales", { recursive: true });
const { default: locales } = await import("./locales/index.mjs");
const v = { _version_: meta.version }; const v = { _version_: meta.version };
@ -45,9 +45,7 @@ gulp.task("copy:client:locales", async (cb) => {
cb(); cb();
}); });
gulp.task("build:backend:script", async () => { gulp.task("build:backend:script", () => {
const { default: locales } = await import("./locales/index.mjs");
return gulp return gulp
.src([ .src([
"./packages/backend/src/server/web/boot.js", "./packages/backend/src/server/web/boot.js",

View file

@ -1178,7 +1178,6 @@ useCdn: "Get assets from CDN"
useCdnDescription: "Load some static assets like Twemoji from the JSDelivr CDN instead of this Firefish server." useCdnDescription: "Load some static assets like Twemoji from the JSDelivr CDN instead of this Firefish server."
suggested: "Suggested" suggested: "Suggested"
noLanguage: "No language" noLanguage: "No language"
searchCwAndAlt: "Include content warnings and alt texts"
_sensitiveMediaDetection: _sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing description: "Reduces the effort of server moderation through automatically recognizing

View file

@ -2,14 +2,8 @@
* Languages Loader * Languages Loader
*/ */
import fs from "node:fs"; const fs = require("fs");
import yaml from "js-yaml"; const yaml = require("js-yaml");
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const languages = []; const languages = [];
const languages_custom = []; const languages_custom = [];
@ -72,13 +66,12 @@ const locales_custom = languages_custom.reduce(
); );
Object.assign(locales, locales_custom); Object.assign(locales, locales_custom);
export default Object.entries(locales).reduce( module.exports = Object.entries(locales).reduce(
(a, [k, v]) => ( (a, [k, v]) => (
(a[k] = (() => { (a[k] = (() => {
const [lang] = k.split("-"); const [lang] = k.split("-");
return k === "en-US" return k === "en-US" ? v :
? v merge(
: merge(
locales["en-US"], locales["en-US"],
locales[`${lang}-${primaries[lang]}`] || {}, locales[`${lang}-${primaries[lang]}`] || {},
v, v,

View file

@ -2057,4 +2057,3 @@ searchUsersDescription: "投稿検索で投稿者を絞りたい場合、@user@e
searchRange: "投稿期間(オプション)" searchRange: "投稿期間(オプション)"
searchRangeDescription: "投稿検索で投稿期間を絞りたい場合、20220615-20231031 のような形式で投稿期間を入力してください。今年の日付を指定する場合には年の指定を省略できます0105-0106 や 20231105-0110 のように)。\n\n開始日と終了日のどちらか一方は省略可能です。例えば -0102 とすると今年1月2日までの投稿のみを、20231026- とすると2023年10月26日以降の投稿のみを検索します。" searchRangeDescription: "投稿検索で投稿期間を絞りたい場合、20220615-20231031 のような形式で投稿期間を入力してください。今年の日付を指定する場合には年の指定を省略できます0105-0106 や 20231105-0110 のように)。\n\n開始日と終了日のどちらか一方は省略可能です。例えば -0102 とすると今年1月2日までの投稿のみを、20231026- とすると2023年10月26日以降の投稿のみを検索します。"
searchPostsWithFiles: "添付ファイルのある投稿のみ" searchPostsWithFiles: "添付ファイルのある投稿のみ"
searchCwAndAlt: "閲覧注意の注釈と添付ファイルの代替テキストも検索する"

View file

@ -2050,4 +2050,3 @@ searchUsersDescription: "如欲搜尋特定使用者的貼文,請以「@user@e
searchWords: "搜尋關鍵字 / 查詢ID或URL" searchWords: "搜尋關鍵字 / 查詢ID或URL"
searchWordsDescription: "如欲搜尋貼文請在此欄位輸入欲搜尋的關鍵字。以空格分隔關鍵字以進行AND搜尋、在關鍵字之間插入「OR」以進行OR搜尋。\n舉例來說輸入「早上 晚上」會搜尋包含「早上」和「晚上」的貼文,「早上 OR 晚上」會搜尋包含「早上」或「晚上」(或兩者皆包含)的貼文。\n\n如欲前往特定使用者或貼文的頁面請在此欄位輸入使用者ID@user@example.com或貼文的URL並點擊「查詢」按鈕。點擊「搜尋」按鈕則會搜尋字面上包含輸入的ID或URL的貼文。" searchWordsDescription: "如欲搜尋貼文請在此欄位輸入欲搜尋的關鍵字。以空格分隔關鍵字以進行AND搜尋、在關鍵字之間插入「OR」以進行OR搜尋。\n舉例來說輸入「早上 晚上」會搜尋包含「早上」和「晚上」的貼文,「早上 OR 晚上」會搜尋包含「早上」或「晚上」(或兩者皆包含)的貼文。\n\n如欲前往特定使用者或貼文的頁面請在此欄位輸入使用者ID@user@example.com或貼文的URL並點擊「查詢」按鈕。點擊「搜尋」按鈕則會搜尋字面上包含輸入的ID或URL的貼文。"
suggested: "建議" suggested: "建議"
searchCwAndAlt: "包含內容警告及替代文字"

View file

@ -1,7 +1,6 @@
BEGIN; BEGIN;
DELETE FROM "migrations" WHERE name IN ( DELETE FROM "migrations" WHERE name IN (
'IndexAltTextAndCw1708872574733',
'SeparateHardMuteWordsAndPatterns1706413792769', 'SeparateHardMuteWordsAndPatterns1706413792769',
'RenameMetaColumns1705944717480', 'RenameMetaColumns1705944717480',
'RemoveNativeUtilsMigration1705877093218', 'RemoveNativeUtilsMigration1705877093218',
@ -14,10 +13,6 @@ DELETE FROM "migrations" WHERE name IN (
'EmojiModerator1692825433698' 'EmojiModerator1692825433698'
); );
-- index-alt-text-and-cw
DROP INDEX "IDX_f4f7b93d05958527300d79ac82";
DROP INDEX "IDX_8e3bbbeb3df04d1a8105da4c8f";
-- separate-hard-mute-words-and-patterns -- separate-hard-mute-words-and-patterns
UPDATE "user_profile" SET "mutedWords" = "mutedWords" || array_to_json("mutedPatterns")::jsonb; UPDATE "user_profile" SET "mutedWords" = "mutedWords" || array_to_json("mutedPatterns")::jsonb;
ALTER TABLE "user_profile" DROP "mutedPatterns"; ALTER TABLE "user_profile" DROP "mutedPatterns";

View file

@ -1,17 +0,0 @@
export class IndexAltTextAndCw1708872574733 {
name = "IndexAltTextAndCw1708872574733";
async up(queryRunner) {
await queryRunner.query(
`CREATE INDEX "IDX_8e3bbbeb3df04d1a8105da4c8f" ON "note" USING "pgroonga" ("cw" pgroonga_varchar_full_text_search_ops_v2)`,
);
await queryRunner.query(
`CREATE INDEX "IDX_f4f7b93d05958527300d79ac82" ON "drive_file" USING "pgroonga" ("comment" pgroonga_varchar_full_text_search_ops_v2)`,
);
}
async down(queryRunner) {
await queryRunner.query(`DROP INDEX "IDX_f4f7b93d05958527300d79ac82"`);
await queryRunner.query(`DROP INDEX "IDX_8e3bbbeb3df04d1a8105da4c8f"`);
}
}

View file

@ -70,7 +70,6 @@ export class DriveFile {
}) })
public size: number; public size: number;
@Index() // USING pgroonga pgroonga_varchar_full_text_search_ops_v2
@Column("varchar", { @Column("varchar", {
length: DB_MAX_IMAGE_COMMENT_LENGTH, length: DB_MAX_IMAGE_COMMENT_LENGTH,
nullable: true, nullable: true,

View file

@ -79,7 +79,6 @@ export class Note {
}) })
public name: string | null; public name: string | null;
@Index() // USING pgroonga pgroonga_varchar_full_text_search_ops_v2
@Column("varchar", { @Column("varchar", {
length: 512, length: 512,
nullable: true, nullable: true,

View file

@ -14,7 +14,18 @@ export const paramDef = {
} as const; } as const;
export default define(meta, paramDef, async () => { export default define(meta, paramDef, async () => {
let tag_name: string;
const pattern = /&quot;version&quot;: &quot;(.*)&quot;,$/m;
await fetch(
"https://code.naskya.net/naskya/firefish/source-by/main/package.json",
)
.then((response) => response.text())
.then((text) => {
tag_name = pattern.exec(text)[1];
});
return { return {
tag_name: "neko", tag_name,
}; };
}); });

View file

@ -1,5 +1,4 @@
// import { FindManyOptions, In } from "typeorm"; // import { FindManyOptions, In } from "typeorm";
import { Brackets } from "typeorm";
import { Notes } from "@/models/index.js"; import { Notes } from "@/models/index.js";
import { Note } from "@/models/entities/note.js"; import { Note } from "@/models/entities/note.js";
// import config from "@/config/index.js"; // import config from "@/config/index.js";
@ -57,7 +56,6 @@ export const paramDef = {
default: null, default: null,
}, },
withFiles: { type: "boolean", nullable: true }, withFiles: { type: "boolean", nullable: true },
searchCwAndAlt: { type: "boolean", nullable: true },
channelId: { channelId: {
type: "string", type: "string",
format: "misskey:id", format: "misskey:id",
@ -94,28 +92,7 @@ export default define(meta, paramDef, async (ps, me) => {
} }
if (ps.query != null) { if (ps.query != null) {
const q = sqlLikeEscape(ps.query); query.andWhere("note.text &@~ :q", { q: `${sqlLikeEscape(ps.query)}` });
if (ps.searchCwAndAlt) {
query.andWhere(
new Brackets((qb) => {
qb.where("note.text &@~ :q", { q })
.orWhere("note.cw &@~ :q", { q })
.orWhere(
`EXISTS (
SELECT FROM "drive_file"
WHERE
comment &@~ :q
AND
drive_file."id" = ANY(note."fileIds")
)`,
{ q },
);
}),
);
} else {
query.andWhere("note.text &@~ :q", { q });
}
} }
query.innerJoinAndSelect("note.user", "user"); query.innerJoinAndSelect("note.user", "user");

View file

@ -54,9 +54,7 @@ const bullBoardPath = "/queue";
// Authenticate // Authenticate
app.use(async (ctx, next) => { app.use(async (ctx, next) => {
const url = decodeURI(ctx.path); if (ctx.path === bullBoardPath || ctx.path.startsWith(`${bullBoardPath}/`)) {
if (url === bullBoardPath || url.startsWith(`${bullBoardPath}/`)) {
const token = ctx.cookies.get("token"); const token = ctx.cookies.get("token");
if (token == null) { if (token == null) {
ctx.status = 401; ctx.status = 401;

View file

@ -1,7 +1,6 @@
{ {
"name": "client", "name": "client",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"watch": "pnpm vite build --watch --mode development", "watch": "pnpm vite build --watch --mode development",
"build": "pnpm vite build", "build": "pnpm vite build",

View file

@ -68,12 +68,6 @@
:class="$style.input" :class="$style.input"
>{{ i18n.ts.searchPostsWithFiles }}</FormSwitch >{{ i18n.ts.searchPostsWithFiles }}</FormSwitch
> >
<FormSwitch
v-model="searchCwAndAlt"
class="form-switch"
:class="$style.input"
>{{ i18n.ts.searchCwAndAlt }}</FormSwitch
>
<div :class="$style.buttons"> <div :class="$style.buttons">
<MkButton inline primary @click="search" <MkButton inline primary @click="search"
>{{ i18n.ts.search }} >{{ i18n.ts.search }}
@ -134,8 +128,7 @@ const searchRange = ref(
}` }`
: "", : "",
); );
const searchPostsWithFiles = ref(searchParams.get("withFiles") === "1"); const searchPostsWithFiles = ref(searchParams.get("withFiles") === "true");
const searchCwAndAlt = ref(searchParams.get("detailed") === "1");
function done(canceled: boolean, result?: searchQuery) { function done(canceled: boolean, result?: searchQuery) {
emit("done", { canceled, result }); emit("done", { canceled, result });
@ -156,7 +149,6 @@ function search() {
from: searchUsers.value === "" ? undefined : searchUsers.value, from: searchUsers.value === "" ? undefined : searchUsers.value,
range: searchRange.value === "" ? undefined : searchRange.value, range: searchRange.value === "" ? undefined : searchRange.value,
withFiles: searchPostsWithFiles.value, withFiles: searchPostsWithFiles.value,
searchCwAndAlt: searchCwAndAlt.value,
}); });
} }

View file

@ -42,6 +42,15 @@
i18n.ts.configure i18n.ts.configure
}}</MkA></MkInfo }}</MkA></MkInfo
> >
<MkInfo v-if="updateAvailable" warn class="info"
>{{ i18n.ts.updateAvailable }}
<a
href="https://code.naskya.net/naskya/firefish"
target="_bank"
class="_link"
>{{ i18n.ts.check }}</a
></MkInfo
>
<MkSuperMenu :def="menuDef" :grid="narrow"></MkSuperMenu> <MkSuperMenu :def="menuDef" :grid="narrow"></MkSuperMenu>
</div> </div>
@ -104,6 +113,7 @@ const noBotProtection =
!instance.enableRecaptcha; !instance.enableRecaptcha;
const noEmailServer = !instance.enableEmail; const noEmailServer = !instance.enableEmail;
const thereIsUnresolvedAbuseReport = ref(false); const thereIsUnresolvedAbuseReport = ref(false);
const updateAvailable = ref(false);
const currentPage = computed(() => router.currentRef.value.child); const currentPage = computed(() => router.currentRef.value.child);
os.api("admin/abuse-user-reports", { os.api("admin/abuse-user-reports", {
@ -113,6 +123,13 @@ os.api("admin/abuse-user-reports", {
if (reports?.length > 0) thereIsUnresolvedAbuseReport.value = true; if (reports?.length > 0) thereIsUnresolvedAbuseReport.value = true;
}); });
if (defaultStore.state.showAdminUpdates) {
os.api("latest-version").then((res) => {
if (res == null || res.tag_name == null) return;
updateAvailable.value = !version.startsWith(res.tag_name);
});
}
const NARROW_THRESHOLD = 600; const NARROW_THRESHOLD = 600;
const ro = new ResizeObserver((entries, observer) => { const ro = new ResizeObserver((entries, observer) => {
if (entries.length === 0) return; if (entries.length === 0) return;

View file

@ -63,8 +63,7 @@ const props = defineProps<{
since?: string; since?: string;
until?: string; until?: string;
channel?: string; channel?: string;
withFiles: "0" | "1"; withFiles: "false" | "true";
searchCwAndAlt: "0" | "1";
}>(); }>();
const userId = props.user == null ? undefined : await getUserId(props.user); const userId = props.user == null ? undefined : await getUserId(props.user);
@ -80,8 +79,7 @@ const notesPagination = {
props.since == null ? undefined : getUnixTime(props.since, false), props.since == null ? undefined : getUnixTime(props.since, false),
untilDate: untilDate:
props.until == null ? undefined : getUnixTime(props.until, true), props.until == null ? undefined : getUnixTime(props.until, true),
withFiles: props.withFiles === "1", withFiles: props.withFiles === "true",
searchCwAndAlt: props.searchCwAndAlt === "1",
channelId: props.channel, channelId: props.channel,
})), })),
}; };

View file

@ -310,7 +310,6 @@ export const routes = [
until: "until", until: "until",
withFiles: "withFiles", withFiles: "withFiles",
channel: "channel", channel: "channel",
detailed: "searchCwAndAlt",
}, },
}, },
{ {

View file

@ -21,7 +21,6 @@ export async function search() {
from?: string; from?: string;
range?: string; range?: string;
withFiles: boolean; withFiles: boolean;
searchCwAndAlt: boolean;
}; };
} }
>((resolve, _) => { >((resolve, _) => {
@ -70,35 +69,24 @@ export async function search() {
} }
if (result.action === "search") { if (result.action === "search") {
const params = new URLSearchParams(); let paramString = `withFiles=${result.withFiles ? "true" : "false"}`;
params.append("withFiles", result.withFiles ? "1" : "0");
if (result.query != null) { if (result.query != null) {
params.append("q", result.query); paramString += `&q=${encodeURIComponent(result.query)}`;
} }
if (result.from != null) { if (result.from != null) {
if (result.from === "me" || result.from.includes("@")) if (result.from === "me" || result.from.includes("@"))
params.append("user", result.from); paramString += `&user=${encodeURIComponent(result.from)}`;
else params.append("host", result.from); else paramString += `&host=${encodeURIComponent(result.from)}`;
} }
if (result.range != null) { if (result.range != null) {
const split = result.range.split("-"); const split = result.range.split("-");
if (split.length === 1) { if (split[0] !== "") paramString += `&since=${split[0]}`;
params.append("since", result.range); if (split[1] !== "") paramString += `&until=${split[1]}`;
params.append("until", result.range);
} else {
if (split[0] !== "") params.append("since", split[0]);
if (split[1] !== "") params.append("until", split[1]);
}
} }
if (result.searchCwAndAlt) { mainRouter.push(`/search?${paramString}`);
params.append("detailed", "1");
}
mainRouter.push(`/search?${params.toString()}`);
} }
} }

View file

@ -2,10 +2,10 @@ import * as fs from "fs";
import pluginVue from "@vitejs/plugin-vue"; import pluginVue from "@vitejs/plugin-vue";
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import locales from "../../locales/index.mjs";
import meta from "../../package.json" assert { type: "json" };
import pluginJson5 from "./vite.json5";
import viteCompression from "vite-plugin-compression"; import viteCompression from "vite-plugin-compression";
import locales from "../../locales";
import meta from "../../package.json";
import pluginJson5 from "./vite.json5";
const extensions = [ const extensions = [
".ts", ".ts",

View file

@ -1,7 +1,6 @@
{ {
"name": "sw", "name": "sw",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"build": "pnpm vite build --emptyOutDir", "build": "pnpm vite build --emptyOutDir",
"build:debug": "pnpm run build", "build:debug": "pnpm run build",

View file

@ -16,7 +16,6 @@
"noLib": false, "noLib": false,
"strict": true, "strict": true,
"strictNullChecks": true, "strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
@ -24,7 +23,10 @@
"paths": { "paths": {
"@/*": ["./src/*"] "@/*": ["./src/*"]
}, },
"typeRoots": ["node_modules/@types", "@types"], "typeRoots": [
"node_modules/@types",
"@types",
],
"lib": ["esnext", "webworker"] "lib": ["esnext", "webworker"]
}, },
"compileOnSave": false, "compileOnSave": false,

View file

@ -1,6 +1,6 @@
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import locales from "../../locales/index.mjs"; const locales = require("../../locales");
import meta from "../../package.json" assert { type: "json" }; const meta = require("../../package.json");
const isProduction = process.env.NODE_ENV === "production"; const isProduction = process.env.NODE_ENV === "production";
import viteCompression from "vite-plugin-compression"; import viteCompression from "vite-plugin-compression";