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/.idea
*.traineddata
# blender backups
*.blend1
*.blend2

View file

@ -8,6 +8,7 @@ const replace = require("gulp-replace");
const terser = require("gulp-terser");
const cssnano = require("gulp-cssnano");
const locales = require("./locales");
const meta = require("./package.json");
gulp.task("copy:backend:views", () =>
@ -28,9 +29,8 @@ gulp.task("copy:client: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 });
const { default: locales } = await import("./locales/index.mjs");
const v = { _version_: meta.version };
@ -45,9 +45,7 @@ gulp.task("copy:client:locales", async (cb) => {
cb();
});
gulp.task("build:backend:script", async () => {
const { default: locales } = await import("./locales/index.mjs");
gulp.task("build:backend:script", () => {
return gulp
.src([
"./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."
suggested: "Suggested"
noLanguage: "No language"
searchCwAndAlt: "Include content warnings and alt texts"
_sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing

View file

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

View file

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

View file

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

View file

@ -1,7 +1,6 @@
BEGIN;
DELETE FROM "migrations" WHERE name IN (
'IndexAltTextAndCw1708872574733',
'SeparateHardMuteWordsAndPatterns1706413792769',
'RenameMetaColumns1705944717480',
'RemoveNativeUtilsMigration1705877093218',
@ -14,10 +13,6 @@ DELETE FROM "migrations" WHERE name IN (
'EmojiModerator1692825433698'
);
-- index-alt-text-and-cw
DROP INDEX "IDX_f4f7b93d05958527300d79ac82";
DROP INDEX "IDX_8e3bbbeb3df04d1a8105da4c8f";
-- separate-hard-mute-words-and-patterns
UPDATE "user_profile" SET "mutedWords" = "mutedWords" || array_to_json("mutedPatterns")::jsonb;
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;
@Index() // USING pgroonga pgroonga_varchar_full_text_search_ops_v2
@Column("varchar", {
length: DB_MAX_IMAGE_COMMENT_LENGTH,
nullable: true,

View file

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

View file

@ -14,7 +14,18 @@ export const paramDef = {
} as const;
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 {
tag_name: "neko",
tag_name,
};
});

View file

@ -1,5 +1,4 @@
// import { FindManyOptions, In } from "typeorm";
import { Brackets } from "typeorm";
import { Notes } from "@/models/index.js";
import { Note } from "@/models/entities/note.js";
// import config from "@/config/index.js";
@ -57,7 +56,6 @@ export const paramDef = {
default: null,
},
withFiles: { type: "boolean", nullable: true },
searchCwAndAlt: { type: "boolean", nullable: true },
channelId: {
type: "string",
format: "misskey:id",
@ -94,28 +92,7 @@ export default define(meta, paramDef, async (ps, me) => {
}
if (ps.query != null) {
const 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.andWhere("note.text &@~ :q", { q: `${sqlLikeEscape(ps.query)}` });
}
query.innerJoinAndSelect("note.user", "user");

View file

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

View file

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

View file

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

View file

@ -42,6 +42,15 @@
i18n.ts.configure
}}</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>
</div>
@ -104,6 +113,7 @@ const noBotProtection =
!instance.enableRecaptcha;
const noEmailServer = !instance.enableEmail;
const thereIsUnresolvedAbuseReport = ref(false);
const updateAvailable = ref(false);
const currentPage = computed(() => router.currentRef.value.child);
os.api("admin/abuse-user-reports", {
@ -113,6 +123,13 @@ os.api("admin/abuse-user-reports", {
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 ro = new ResizeObserver((entries, observer) => {
if (entries.length === 0) return;

View file

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

View file

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

View file

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

View file

@ -2,10 +2,10 @@ import * as fs from "fs";
import pluginVue from "@vitejs/plugin-vue";
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 locales from "../../locales";
import meta from "../../package.json";
import pluginJson5 from "./vite.json5";
const extensions = [
".ts",

View file

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

View file

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

View file

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