summaryrefslogtreecommitdiff
path: root/packages/backend/src/misc
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-06-01 11:27:03 +0900
committerGitHub <noreply@github.com>2024-06-01 11:27:03 +0900
commitfce66b85b603caac79e1bfa87b5f4621b1ba9d4e (patch)
treed22952ee3f8e30057977a99a33823f4d52990fbc /packages/backend/src/misc
parentMerge pull request #13493 from misskey-dev/develop (diff)
parentfix(backend): use insertOne insteadof insert/findOneOrFail combination (#13908) (diff)
downloadsharkey-fce66b85b603caac79e1bfa87b5f4621b1ba9d4e.tar.gz
sharkey-fce66b85b603caac79e1bfa87b5f4621b1ba9d4e.tar.bz2
sharkey-fce66b85b603caac79e1bfa87b5f4621b1ba9d4e.zip
Merge pull request #13917 from misskey-dev/develop
Release 2024.5.0 (master)
Diffstat (limited to 'packages/backend/src/misc')
-rw-r--r--packages/backend/src/misc/fastify-hook-handlers.ts5
-rw-r--r--packages/backend/src/misc/gen-identicon.ts9
-rw-r--r--packages/backend/src/misc/is-pure-renote.ts10
-rw-r--r--packages/backend/src/misc/is-quote.ts12
-rw-r--r--packages/backend/src/misc/is-renote.ts67
-rw-r--r--packages/backend/src/misc/json-schema.ts4
-rw-r--r--packages/backend/src/misc/loader.ts5
7 files changed, 84 insertions, 28 deletions
diff --git a/packages/backend/src/misc/fastify-hook-handlers.ts b/packages/backend/src/misc/fastify-hook-handlers.ts
index 49a48f6a6b..3e1c099e00 100644
--- a/packages/backend/src/misc/fastify-hook-handlers.ts
+++ b/packages/backend/src/misc/fastify-hook-handlers.ts
@@ -1,3 +1,8 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
import type { onRequestHookHandler } from 'fastify';
export const handleRequestRedirectToOmitSearch: onRequestHookHandler = (request, reply, done) => {
diff --git a/packages/backend/src/misc/gen-identicon.ts b/packages/backend/src/misc/gen-identicon.ts
index 62a8ab8ace..342e0f8602 100644
--- a/packages/backend/src/misc/gen-identicon.ts
+++ b/packages/backend/src/misc/gen-identicon.ts
@@ -8,9 +8,8 @@
* https://en.wikipedia.org/wiki/Identicon
*/
-import * as p from 'pureimage';
+import { createCanvas } from '@napi-rs/canvas';
import gen from 'random-seed';
-import type { WriteStream } from 'node:fs';
const size = 128; // px
const n = 5; // resolution
@@ -45,9 +44,9 @@ const sideN = Math.floor(n / 2);
/**
* Generate buffer of an identicon by seed
*/
-export function genIdenticon(seed: string, stream: WriteStream): Promise<void> {
+export async function genIdenticon(seed: string): Promise<Buffer> {
const rand = gen.create(seed);
- const canvas = p.make(size, size, undefined);
+ const canvas = createCanvas(size, size);
const ctx = canvas.getContext('2d');
const bgColors = colors[rand(colors.length)];
@@ -101,5 +100,5 @@ export function genIdenticon(seed: string, stream: WriteStream): Promise<void> {
}
}
- return p.encodePNGToStream(canvas, stream);
+ return await canvas.encode('png');
}
diff --git a/packages/backend/src/misc/is-pure-renote.ts b/packages/backend/src/misc/is-pure-renote.ts
deleted file mode 100644
index 994d981522..0000000000
--- a/packages/backend/src/misc/is-pure-renote.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import type { MiNote } from '@/models/Note.js';
-
-export function isPureRenote(note: MiNote): note is MiNote & { renoteId: NonNullable<MiNote['renoteId']> } {
- if (!note.renoteId) return false;
-
- if (note.text) return false; // it's quoted with text
- if (note.fileIds.length !== 0) return false; // it's quoted with files
- if (note.hasPoll) return false; // it's quoted with poll
- return true;
-}
diff --git a/packages/backend/src/misc/is-quote.ts b/packages/backend/src/misc/is-quote.ts
deleted file mode 100644
index 75b29f63f4..0000000000
--- a/packages/backend/src/misc/is-quote.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * SPDX-FileCopyrightText: syuilo and misskey-project
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-import type { MiNote } from '@/models/Note.js';
-
-// eslint-disable-next-line import/no-default-export
-export default function(note: MiNote): boolean {
- // sync with NoteCreateService.isQuote
- return note.renoteId != null && (note.text != null || note.hasPoll || (note.fileIds != null && note.fileIds.length > 0));
-}
diff --git a/packages/backend/src/misc/is-renote.ts b/packages/backend/src/misc/is-renote.ts
new file mode 100644
index 0000000000..48f821806c
--- /dev/null
+++ b/packages/backend/src/misc/is-renote.ts
@@ -0,0 +1,67 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import type { MiNote } from '@/models/Note.js';
+import type { Packed } from '@/misc/json-schema.js';
+
+type Renote =
+ MiNote & {
+ renoteId: NonNullable<MiNote['renoteId']>
+ };
+
+type Quote =
+ Renote & ({
+ text: NonNullable<MiNote['text']>
+ } | {
+ cw: NonNullable<MiNote['cw']>
+ } | {
+ replyId: NonNullable<MiNote['replyId']>
+ reply: NonNullable<MiNote['reply']>
+ } | {
+ hasPoll: true
+ });
+
+export function isRenote(note: MiNote): note is Renote {
+ return note.renoteId != null;
+}
+
+export function isQuote(note: Renote): note is Quote {
+ // NOTE: SYNC WITH NoteCreateService.isQuote
+ return note.text != null ||
+ note.cw != null ||
+ note.replyId != null ||
+ note.hasPoll ||
+ note.fileIds.length > 0;
+}
+
+type PackedRenote =
+ Packed<'Note'> & {
+ renoteId: NonNullable<Packed<'Note'>['renoteId']>
+ };
+
+type PackedQuote =
+ PackedRenote & ({
+ text: NonNullable<Packed<'Note'>['text']>
+ } | {
+ cw: NonNullable<Packed<'Note'>['cw']>
+ } | {
+ replyId: NonNullable<Packed<'Note'>['replyId']>
+ } | {
+ poll: NonNullable<Packed<'Note'>['poll']>
+ } | {
+ fileIds: NonNullable<Packed<'Note'>['fileIds']>
+ });
+
+export function isRenotePacked(note: Packed<'Note'>): note is PackedRenote {
+ return note.renoteId != null;
+}
+
+export function isQuotePacked(note: PackedRenote): note is PackedQuote {
+ return note.text != null ||
+ note.cw != null ||
+ note.replyId != null ||
+ note.poll != null ||
+ (note.fileIds != null && note.fileIds.length > 0);
+}
diff --git a/packages/backend/src/misc/json-schema.ts b/packages/backend/src/misc/json-schema.ts
index 46b0bb2fab..41e5bfe9e4 100644
--- a/packages/backend/src/misc/json-schema.ts
+++ b/packages/backend/src/misc/json-schema.ts
@@ -48,6 +48,7 @@ import {
packedRoleCondFormulaValueCreatedSchema,
packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
packedRoleCondFormulaValueSchema,
+ packedRoleCondFormulaValueUserSettingBooleanSchema,
} from '@/models/json-schema/role.js';
import { packedAdSchema } from '@/models/json-schema/ad.js';
import { packedReversiGameLiteSchema, packedReversiGameDetailedSchema } from '@/models/json-schema/reversi-game.js';
@@ -97,6 +98,7 @@ export const refs = {
RoleCondFormulaLogics: packedRoleCondFormulaLogicsSchema,
RoleCondFormulaValueNot: packedRoleCondFormulaValueNot,
RoleCondFormulaValueIsLocalOrRemote: packedRoleCondFormulaValueIsLocalOrRemoteSchema,
+ RoleCondFormulaValueUserSettingBooleanSchema: packedRoleCondFormulaValueUserSettingBooleanSchema,
RoleCondFormulaValueAssignedRole: packedRoleCondFormulaValueAssignedRoleSchema,
RoleCondFormulaValueCreated: packedRoleCondFormulaValueCreatedSchema,
RoleCondFormulaFollowersOrFollowingOrNotes: packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
@@ -226,7 +228,7 @@ export type SchemaTypeDef<p extends Schema> =
p['items']['allOf'] extends ReadonlyArray<Schema> ? UnionToIntersection<UnionSchemaType<NonNullable<p['items']['allOf']>>>[] :
never
) :
- p['items'] extends NonNullable<Schema> ? SchemaTypeDef<p['items']>[] :
+ p['items'] extends NonNullable<Schema> ? SchemaType<p['items']>[] :
any[]
) :
p['anyOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<p['anyOf']> & PartialIntersection<UnionSchemaType<p['anyOf']>> :
diff --git a/packages/backend/src/misc/loader.ts b/packages/backend/src/misc/loader.ts
index 25f7b54d31..7f29b9db10 100644
--- a/packages/backend/src/misc/loader.ts
+++ b/packages/backend/src/misc/loader.ts
@@ -1,3 +1,8 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
export type FetchFunction<K, V> = (key: K) => Promise<V>;
type ResolveReject<V> = Parameters<ConstructorParameters<typeof Promise<V>>[0]>;