diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-07-13 21:59:47 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-07-13 21:59:47 +0900 |
| commit | bce48dfee933d9feb3be381ad22ea765dd6a3aab (patch) | |
| tree | b21a3a765040469885d286487245aeaed373bba6 /packages/backend/src | |
| parent | Merge branch 'develop' (diff) | |
| parent | 12.113.0 (diff) | |
| download | misskey-bce48dfee933d9feb3be381ad22ea765dd6a3aab.tar.gz misskey-bce48dfee933d9feb3be381ad22ea765dd6a3aab.tar.bz2 misskey-bce48dfee933d9feb3be381ad22ea765dd6a3aab.zip | |
Merge branch 'develop'
Diffstat (limited to 'packages/backend/src')
11 files changed, 42 insertions, 12 deletions
diff --git a/packages/backend/src/mfm/to-html.ts b/packages/backend/src/mfm/to-html.ts index 5b382063eb..bcb5c86a3d 100644 --- a/packages/backend/src/mfm/to-html.ts +++ b/packages/backend/src/mfm/to-html.ts @@ -145,6 +145,12 @@ export function toHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMenti a.textContent = node.props.content; return a; }, + + plain(node) { + const el = doc.createElement('span'); + appendChildren(node.children, el); + return el; + }, }; appendChildren(nodes, doc.body); diff --git a/packages/backend/src/queue/processors/db/export-custom-emojis.ts b/packages/backend/src/queue/processors/db/export-custom-emojis.ts index 8ce1d05272..3da887cda2 100644 --- a/packages/backend/src/queue/processors/db/export-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/export-custom-emojis.ts @@ -8,7 +8,7 @@ import { queueLogger } from '../../logger.js'; import { addFile } from '@/services/drive/add-file.js'; import { format as dateFormat } from 'date-fns'; import { Users, Emojis } from '@/models/index.js'; -import { } from '@/queue/types.js'; +import { } from '@/queue/types.js'; import { createTemp, createTempDir } from '@/misc/create-temp.js'; import { downloadUrl } from '@/misc/download-url.js'; import config from '@/config/index.js'; diff --git a/packages/backend/src/remote/activitypub/models/question.ts b/packages/backend/src/remote/activitypub/models/question.ts index 034501572a..f0321fdf2f 100644 --- a/packages/backend/src/remote/activitypub/models/question.ts +++ b/packages/backend/src/remote/activitypub/models/question.ts @@ -1,6 +1,6 @@ import config from '@/config/index.js'; import Resolver from '../resolver.js'; -import { IObject, IQuestion, isQuestion } from '../type.js'; +import { IObject, IQuestion, isQuestion } from '../type.js'; import { apLogger } from '../logger.js'; import { Notes, Polls } from '@/models/index.js'; import { IPoll } from '@/models/entities/poll.js'; diff --git a/packages/backend/src/remote/activitypub/renderer/like.ts b/packages/backend/src/remote/activitypub/renderer/like.ts index da1bfe6e8e..00fb72e8a3 100644 --- a/packages/backend/src/remote/activitypub/renderer/like.ts +++ b/packages/backend/src/remote/activitypub/renderer/like.ts @@ -8,7 +8,7 @@ import renderEmoji from './emoji.js'; export const renderLike = async (noteReaction: NoteReaction, note: Note) => { const reaction = noteReaction.reaction; - const object = { + const object = { type: 'Like', id: `${config.url}/likes/${noteReaction.id}`, actor: `${config.url}/users/${noteReaction.userId}`, diff --git a/packages/backend/src/server/api/api-handler.ts b/packages/backend/src/server/api/api-handler.ts index 34ff970b4c..ec71ddd2c0 100644 --- a/packages/backend/src/server/api/api-handler.ts +++ b/packages/backend/src/server/api/api-handler.ts @@ -68,11 +68,11 @@ export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise<void>((res } try { - UserIps.insert({ + UserIps.createQueryBuilder().insert().values({ createdAt: new Date(), userId: user.id, ip: ip, - }); + }).orIgnore(true).execute(); } catch { } } diff --git a/packages/backend/src/server/api/common/read-notification.ts b/packages/backend/src/server/api/common/read-notification.ts index 17dd8e6f02..cf993ade3e 100644 --- a/packages/backend/src/server/api/common/read-notification.ts +++ b/packages/backend/src/server/api/common/read-notification.ts @@ -12,13 +12,15 @@ export async function readNotification( if (notificationIds.length === 0) return; // Update documents - await Notifications.update({ + const result = await Notifications.update({ id: In(notificationIds), isRead: false, }, { isRead: true, }); + if (result.affected === 0) return; + if (!await Users.getHasUnreadNotification(userId)) return postReadAllNotifications(userId); else return postReadNotifications(userId, notificationIds); } diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 122120f275..3c2f1cea0d 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -214,7 +214,7 @@ export default define(meta, paramDef, async (ps, _user, token) => { const newDescription = profileUpdates.description === undefined ? profile.description : profileUpdates.description; if (newName != null) { - const tokens = mfm.parsePlain(newName); + const tokens = mfm.parseSimple(newName); emojis = emojis.concat(extractCustomEmojisFromMfm(tokens!)); } diff --git a/packages/backend/src/server/nodeinfo.ts b/packages/backend/src/server/nodeinfo.ts index 13a362a75f..f139d203d2 100644 --- a/packages/backend/src/server/nodeinfo.ts +++ b/packages/backend/src/server/nodeinfo.ts @@ -78,6 +78,7 @@ const nodeinfo2 = async () => { enableEmail: meta.enableEmail, enableServiceWorker: meta.enableServiceWorker, proxyAccountName: proxyAccount ? proxyAccount.username : null, + themeColor: meta.themeColor || '#86b300', }, }; }; diff --git a/packages/backend/src/services/detect-sensitive.ts b/packages/backend/src/services/detect-sensitive.ts index 0fa263599b..2ade39d524 100644 --- a/packages/backend/src/services/detect-sensitive.ts +++ b/packages/backend/src/services/detect-sensitive.ts @@ -2,19 +2,34 @@ import * as fs from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname } from 'node:path'; import * as nsfw from 'nsfwjs'; -import * as tf from '@tensorflow/tfjs-node'; +import si from 'systeminformation'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); +const REQUIRED_CPU_FLAGS = ['avx2', 'fma']; +let isSupportedCpu: undefined | boolean = undefined; + let model: nsfw.NSFWJS; export async function detectSensitive(path: string): Promise<nsfw.predictionType[] | null> { try { + if (isSupportedCpu === undefined) { + const cpuFlags = await getCpuFlags(); + isSupportedCpu = REQUIRED_CPU_FLAGS.every(required => cpuFlags.includes(required)); + } + + if (!isSupportedCpu) { + console.error('This CPU cannot use TensorFlow.'); + return null; + } + + const tf = await import('@tensorflow/tfjs-node'); + if (model == null) model = await nsfw.load(`file://${_dirname}/../../nsfw-model/`, { size: 299 }); const buffer = await fs.promises.readFile(path); - const image = await tf.node.decodeImage(buffer, 3) as tf.Tensor3D; + const image = await tf.node.decodeImage(buffer, 3) as any; try { const predictions = await model.classify(image); return predictions; @@ -26,3 +41,8 @@ export async function detectSensitive(path: string): Promise<nsfw.predictionType return null; } } + +async function getCpuFlags(): Promise<string[]> { + const str = await si.cpuFlags(); + return str.split(/\s+/); +} diff --git a/packages/backend/src/services/fetch-instance-metadata.ts b/packages/backend/src/services/fetch-instance-metadata.ts index 029c388dc2..ee1245132a 100644 --- a/packages/backend/src/services/fetch-instance-metadata.ts +++ b/packages/backend/src/services/fetch-instance-metadata.ts @@ -34,7 +34,7 @@ export async function fetchInstanceMetadata(instance: Instance, force = false): const [favicon, icon, themeColor, name, description] = await Promise.all([ fetchFaviconUrl(instance, dom).catch(() => null), fetchIconUrl(instance, dom, manifest).catch(() => null), - getThemeColor(dom, manifest).catch(() => null), + getThemeColor(info, dom, manifest).catch(() => null), getSiteName(info, dom, manifest).catch(() => null), getDescription(info, dom, manifest).catch(() => null), ]); @@ -208,8 +208,8 @@ async function fetchIconUrl(instance: Instance, doc: DOMWindow['document'] | nul return null; } -async function getThemeColor(doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> { - const themeColor = doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') || manifest?.theme_color; +async function getThemeColor(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> { + const themeColor = info?.metadata?.themeColor || doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') || manifest?.theme_color; if (themeColor) { const color = new tinycolor(themeColor); diff --git a/packages/backend/src/services/push-notification.ts b/packages/backend/src/services/push-notification.ts index 5c3bafbb34..393a23d050 100644 --- a/packages/backend/src/services/push-notification.ts +++ b/packages/backend/src/services/push-notification.ts @@ -64,6 +64,7 @@ export async function pushNotification<T extends keyof pushNotificationsTypes>(u type, body: type === 'notification' ? truncateNotification(body as Packed<'Notification'>) : body, userId, + dateTime: (new Date()).getTime(), }), { proxy: config.proxy, }).catch((err: any) => { |