summaryrefslogtreecommitdiff
path: root/packages/frontend-shared
diff options
context:
space:
mode:
authorJulia <julia@insertdomain.name>2025-03-02 19:54:32 +0000
committerJulia <julia@insertdomain.name>2025-03-02 19:54:32 +0000
commit9e13c375c5ef4103ad5ee87fea583b154e9e16f3 (patch)
treefe9e7b1a474e22fb0c37bd68cfd260f7ba39be74 /packages/frontend-shared
parentmerge: pin corepack version (!885) (diff)
parentbump version (diff)
downloadsharkey-9e13c375c5ef4103ad5ee87fea583b154e9e16f3.tar.gz
sharkey-9e13c375c5ef4103ad5ee87fea583b154e9e16f3.tar.bz2
sharkey-9e13c375c5ef4103ad5ee87fea583b154e9e16f3.zip
merge: 2025.2.2 (!927)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/927 Approved-by: Marie <github@yuugi.dev> Approved-by: Julia <julia@insertdomain.name>
Diffstat (limited to 'packages/frontend-shared')
-rw-r--r--packages/frontend-shared/build.js8
-rw-r--r--packages/frontend-shared/js/append-content-warning.ts62
-rw-r--r--packages/frontend-shared/js/compute-merged-cw.ts17
-rw-r--r--packages/frontend-shared/package.json2
4 files changed, 87 insertions, 2 deletions
diff --git a/packages/frontend-shared/build.js b/packages/frontend-shared/build.js
index 17b6da8d30..9941114757 100644
--- a/packages/frontend-shared/build.js
+++ b/packages/frontend-shared/build.js
@@ -23,10 +23,14 @@ const options = {
sourcemap: 'linked',
};
+const args = process.argv.slice(2).map(arg => arg.toLowerCase());
+
// js-built配下をすべて削除する
-fs.rmSync('./js-built', { recursive: true, force: true });
+if (!args.includes('--no-clean')) {
+ fs.rmSync('./js-built', { recursive: true, force: true });
+}
-if (process.argv.map(arg => arg.toLowerCase()).includes('--watch')) {
+if (args.includes('--watch')) {
await watchSrc();
} else {
await buildSrc();
diff --git a/packages/frontend-shared/js/append-content-warning.ts b/packages/frontend-shared/js/append-content-warning.ts
new file mode 100644
index 0000000000..7f24a66f23
--- /dev/null
+++ b/packages/frontend-shared/js/append-content-warning.ts
@@ -0,0 +1,62 @@
+/*
+ * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+/*
+ * Important Note: this file must be kept in sync with packages/backend/src/misc/append-content-warning.ts
+ */
+
+/**
+ * Appends an additional content warning onto an existing one.
+ * The additional value will not be added if it already exists within the original input.
+ * @param original Existing content warning
+ * @param additional Content warning to append
+ * @param reverse If true, then the additional CW will be prepended instead of appended.
+ */
+export function appendContentWarning(original: string | null | undefined, additional: string, reverse = false): string {
+ // Easy case - if original is empty, then additional replaces it.
+ if (!original) {
+ return additional;
+ }
+
+ // Easy case - if the additional CW is empty, then don't append it.
+ if (!additional) {
+ return original;
+ }
+
+ // If the additional CW already exists in the input, then we *don't* append another copy!
+ if (includesWholeWord(original, additional)) {
+ return original;
+ }
+
+ return reverse
+ ? `${additional}, ${original}`
+ : `${original}, ${additional}`;
+}
+
+/**
+ * Emulates a regular expression like /\b(pattern)\b/, but with a raw non-regex pattern.
+ * We're checking to see whether the default CW appears inside the existing CW, but *only* if there's word boundaries on either side.
+ * @param input Input string to search
+ * @param target Target word / phrase to search for
+ */
+function includesWholeWord(input: string, target: string): boolean {
+ const parts = input.split(target);
+
+ // The additional string could appear multiple times within the original input.
+ // We need to check each occurrence, since any of them could potentially match.
+ for (let i = 0; i + 1 < parts.length; i++) {
+ const before = parts[i];
+ const after = parts[i + 1];
+
+ // If either the preceding or following tokens are a "word", then this "match" is actually just part of a longer word.
+ // Likewise, if *neither* token is a word, then this is a real match and the CW already exists in the input.
+ if (!/\w$/.test(before) && !/^\w/.test(after)) {
+ return true;
+ }
+ }
+
+ // If we don't match, then there is no existing CW.
+ return false;
+}
diff --git a/packages/frontend-shared/js/compute-merged-cw.ts b/packages/frontend-shared/js/compute-merged-cw.ts
new file mode 100644
index 0000000000..dfea57fdce
--- /dev/null
+++ b/packages/frontend-shared/js/compute-merged-cw.ts
@@ -0,0 +1,17 @@
+/*
+ * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import * as Misskey from 'misskey-js';
+import { appendContentWarning } from '@@/js/append-content-warning.js';
+
+export function computeMergedCw(note: Misskey.entities.Note): string | null {
+ let cw = note.cw;
+
+ if (note.user.mandatoryCW) {
+ cw = appendContentWarning(cw, note.user.mandatoryCW);
+ }
+
+ return cw ?? null;
+}
diff --git a/packages/frontend-shared/package.json b/packages/frontend-shared/package.json
index 8bf25da161..6afd4e8a23 100644
--- a/packages/frontend-shared/package.json
+++ b/packages/frontend-shared/package.json
@@ -26,6 +26,7 @@
"@typescript-eslint/parser": "7.17.0",
"esbuild": "0.24.0",
"eslint-plugin-vue": "9.31.0",
+ "nodemon": "3.1.7",
"typescript": "5.6.3",
"vue-eslint-parser": "9.4.3"
},
@@ -34,6 +35,7 @@
],
"dependencies": {
"misskey-js": "workspace:*",
+ "nodemon": "3.1.7",
"vue": "3.5.12"
}
}