Merge branch 'develop' into deps-update-openapits

This commit is contained in:
kakkokari-gtyih 2025-05-25 23:43:12 +09:00
commit efb50f03d9
19 changed files with 181 additions and 99 deletions

View File

@ -14,6 +14,8 @@
- デフォルト値は「ローカルのコンテンツだけ公開」になっています
- Feat: ロールでアップロード可能なファイル種別を設定可能になりました
- デフォルトは**テキスト、JSON、画像、動画、音声ファイル**になっています。zipなど、その他の種別のファイルは含まれていないため、必要に応じて設定を変更してください。
- 場合によってはファイル種別を正しく検出できないことがあります(特にテキストフォーマット)。その場合、ファイル種別は application/octet-stream と見做されます。
- したがって、それらの種別不明ファイルを許可したい場合は application/octet-stream を指定に追加してください。
- Enhance: UIのアイコンデータの読み込みを軽量化
### Client

4
locales/index.d.ts vendored
View File

@ -7753,6 +7753,10 @@ export interface Locale extends ILocale {
* MIMEタイプを指定します(*)(: image/*)
*/
"uploadableFileTypes_caption": string;
/**
* {x}
*/
"uploadableFileTypes_caption2": ParameterizedString<"x">;
};
"_condition": {
/**

View File

@ -2007,6 +2007,7 @@ _role:
chatAvailability: "チャットを許可"
uploadableFileTypes: "アップロード可能なファイル種別"
uploadableFileTypes_caption: "MIMEタイプを指定します。改行で区切って複数指定できるほか、アスタリスク(*)でワイルドカード指定できます。(例: image/*)"
uploadableFileTypes_caption2: "ファイルによっては種別を判定できないことがあります。そのようなファイルを許可する場合は {x} を指定に追加してください。"
_condition:
roleAssignedTo: "マニュアルロールにアサイン済み"
isLocal: "ローカルユーザー"

View File

@ -1,6 +1,6 @@
{
"name": "misskey",
"version": "2025.5.1-beta.0",
"version": "2025.5.1-beta.2",
"codename": "nasubi",
"repository": {
"type": "git",

View File

@ -469,13 +469,14 @@ export class DriveService {
if (user && this.meta.sensitiveMediaDetection === 'remote' && this.userEntityService.isLocalUser(user)) skipNsfwCheck = true;
const info = await this.fileInfoService.getFileInfo(path, {
fileName: name,
skipSensitiveDetection: skipNsfwCheck,
sensitiveThreshold: // 感度が高いほどしきい値は低くすることになる
this.meta.sensitiveMediaDetectionSensitivity === 'veryHigh' ? 0.1 :
this.meta.sensitiveMediaDetectionSensitivity === 'high' ? 0.3 :
this.meta.sensitiveMediaDetectionSensitivity === 'low' ? 0.7 :
this.meta.sensitiveMediaDetectionSensitivity === 'veryLow' ? 0.9 :
0.5,
this.meta.sensitiveMediaDetectionSensitivity === 'veryHigh' ? 0.1 :
this.meta.sensitiveMediaDetectionSensitivity === 'high' ? 0.3 :
this.meta.sensitiveMediaDetectionSensitivity === 'low' ? 0.7 :
this.meta.sensitiveMediaDetectionSensitivity === 'veryLow' ? 0.9 :
0.5,
sensitiveThresholdForPorn: 0.75,
enableSensitiveMediaDetectionForVideos: this.meta.enableSensitiveMediaDetectionForVideos,
});

View File

@ -64,6 +64,7 @@ export class FileInfoService {
*/
@bindThis
public async getFileInfo(path: string, opts: {
fileName?: string | null;
skipSensitiveDetection: boolean;
sensitiveThreshold?: number;
sensitiveThresholdForPorn?: number;
@ -76,6 +77,26 @@ export class FileInfoService {
let type = await this.detectType(path);
if (type.mime === TYPE_OCTET_STREAM.mime && opts.fileName != null) {
const ext = opts.fileName.split('.').pop();
if (ext === 'txt') {
type = {
mime: 'text/plain',
ext: 'txt',
};
} else if (ext === 'csv') {
type = {
mime: 'text/csv',
ext: 'csv',
};
} else if (ext === 'json') {
type = {
mime: 'application/json',
ext: 'json',
};
}
}
// image dimensions
let width: number | undefined;
let height: number | undefined;
@ -438,12 +459,12 @@ export class FileInfoService {
*/
@bindThis
private async detectImageSize(path: string): Promise<{
width: number;
height: number;
wUnits: string;
hUnits: string;
orientation?: number;
}> {
width: number;
height: number;
wUnits: string;
hUnits: string;
orientation?: number;
}> {
const readable = fs.createReadStream(path);
const imageSize = await probeImageSize(readable);
readable.destroy();

View File

@ -63,6 +63,12 @@ export const meta = {
id: 'b9d8c348-33f0-4673-b9a9-5d4da058977a',
httpStatusCode: 413,
},
unallowedFileType: {
message: 'Cannot upload the file because it is an unallowed file type.',
code: 'UNALLOWED_FILE_TYPE',
id: '4becd248-7f2c-48c4-a9f0-75edc4f9a1ea',
},
},
} as const;
@ -123,6 +129,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (err.id === '282f77bf-5816-4f72-9264-aa14d8261a21') throw new ApiError(meta.errors.inappropriate);
if (err.id === 'c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6') throw new ApiError(meta.errors.noFreeSpace);
if (err.id === 'f9e4e5f3-4df4-40b5-b400-f236945f7073') throw new ApiError(meta.errors.maxFileSizeExceeded);
if (err.id === 'bd71c601-f9b0-4808-9137-a330647ced9b') throw new ApiError(meta.errors.unallowedFileType);
}
throw new ApiError();
} finally {

View File

@ -19,7 +19,26 @@ export const meta = {
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
properties: {
id: {
type: 'string',
optional: false, nullable: false,
},
reactions: {
type: 'object',
optional: false, nullable: false,
additionalProperties: {
type: 'number',
},
},
reactionEmojis: {
type: 'object',
optional: false, nullable: false,
additionalProperties: {
type: 'string',
},
},
},
},
},

View File

@ -193,7 +193,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { computed, inject, onMounted, ref, useTemplateRef, watch, provide, shallowRef, reactive } from 'vue';
import { computed, inject, onMounted, ref, useTemplateRef, provide } from 'vue';
import * as mfm from 'mfm-js';
import * as Misskey from 'misskey-js';
import { isLink } from '@@/js/is-link.js';
@ -283,12 +283,10 @@ if (noteViewInterruptors.length > 0) {
const isRenote = Misskey.note.isPureRenote(note);
const appearNote = getAppearNote(note);
const $appearNote = reactive({
reactions: appearNote.reactions,
reactionCount: appearNote.reactionCount,
reactionEmojis: appearNote.reactionEmojis,
myReaction: appearNote.myReaction,
pollChoices: appearNote.poll?.choices,
const { $note: $appearNote, subscribe: subscribeManuallyToNoteCapture } = useNoteCapture({
note: appearNote,
parentNote: note,
mock: props.mock,
});
const rootEl = useTemplateRef('rootEl');
@ -410,17 +408,6 @@ provide(DI.mfmEmojiReactCallback, (reaction) => {
});
});
let subscribeManuallyToNoteCapture: () => void = () => { };
if (!props.mock) {
const { subscribe } = useNoteCapture({
note: appearNote,
parentNote: note,
$note: $appearNote,
});
subscribeManuallyToNoteCapture = subscribe;
}
if (!props.mock) {
useTooltip(renoteButton, async (showing) => {
const renotes = await misskeyApi('notes/renotes', {

View File

@ -228,7 +228,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { computed, inject, onMounted, provide, reactive, ref, useTemplateRef } from 'vue';
import { computed, inject, onMounted, provide, ref, useTemplateRef } from 'vue';
import * as mfm from 'mfm-js';
import * as Misskey from 'misskey-js';
import { isLink } from '@@/js/is-link.js';
@ -304,12 +304,9 @@ if (noteViewInterruptors.length > 0) {
const isRenote = Misskey.note.isPureRenote(note);
const appearNote = getAppearNote(note);
const $appearNote = reactive({
reactions: appearNote.reactions,
reactionCount: appearNote.reactionCount,
reactionEmojis: appearNote.reactionEmojis,
myReaction: appearNote.myReaction,
pollChoices: appearNote.poll?.choices,
const { $note: $appearNote, subscribe: subscribeManuallyToNoteCapture } = useNoteCapture({
note: appearNote,
parentNote: note,
});
const rootEl = useTemplateRef('rootEl');
@ -397,12 +394,6 @@ const reactionsPagination = computed(() => ({
},
}));
const { subscribe: subscribeManuallyToNoteCapture } = useNoteCapture({
note: appearNote,
parentNote: note,
$note: $appearNote,
});
useTooltip(renoteButton, async (showing) => {
const renotes = await misskeyApi('notes/renotes', {
noteId: appearNote.id,

View File

@ -73,7 +73,10 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSelect>
<div>{{ i18n.tsx._uploader.maxFileSizeIsX({ x: $i.policies.maxFileSizeMb + 'MB' }) }}</div>
<div>{{ i18n.ts._uploader.allowedTypes }}: {{ $i.policies.uploadableFileTypes.join(', ') }}</div>
<!-- クライアントで検出するMIME typeとサーバーで検出するMIME typeが異なる場合があり混乱の元になるのでとりあえず隠しとく -->
<!-- https://github.com/misskey-dev/misskey/issues/16091 -->
<!--<div>{{ i18n.ts._uploader.allowedTypes }}: {{ $i.policies.uploadableFileTypes.join(', ') }}</div>-->
</div>
</div>

View File

@ -3,10 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { onUnmounted } from 'vue';
import { onUnmounted, reactive } from 'vue';
import * as Misskey from 'misskey-js';
import { EventEmitter } from 'eventemitter3';
import type { Reactive, Ref } from 'vue';
import type { Reactive } from 'vue';
import { useStream } from '@/stream.js';
import { $i } from '@/i.js';
import { store } from '@/store.js';
@ -179,60 +179,83 @@ function realtimeSubscribe(props: {
});
}
type ReactiveNoteData = Reactive<{
export type ReactiveNoteData = {
reactions: Misskey.entities.Note['reactions'];
reactionCount: Misskey.entities.Note['reactionCount'];
reactionEmojis: Misskey.entities.Note['reactionEmojis'];
myReaction: Misskey.entities.Note['myReaction'];
pollChoices: NonNullable<Misskey.entities.Note['poll']>['choices'];
}>;
};
const noReaction = Symbol();
export function useNoteCapture(props: {
note: Pick<Misskey.entities.Note, 'id' | 'createdAt'>;
note: Misskey.entities.Note;
parentNote: Misskey.entities.Note | null;
$note: ReactiveNoteData;
mock?: boolean;
}): {
$note: Reactive<ReactiveNoteData>;
subscribe: () => void;
} {
const { note, parentNote, $note } = props;
const { note, parentNote, mock } = props;
const $note = reactive<ReactiveNoteData>({
reactions: Object.entries(note.reactions).reduce((acc, [name, count]) => {
// Normalize reactions
const normalizedName = name.replace(/^:(\w+):$/, ':$1@.:');
if (acc[normalizedName] == null) {
acc[normalizedName] = count;
} else {
acc[normalizedName] += count;
}
return acc;
}, {} as Misskey.entities.Note['reactions']),
reactionCount: note.reactionCount,
reactionEmojis: note.reactionEmojis,
myReaction: note.myReaction,
pollChoices: note.poll?.choices ?? [],
});
noteEvents.on(`reacted:${note.id}`, onReacted);
noteEvents.on(`unreacted:${note.id}`, onUnreacted);
noteEvents.on(`pollVoted:${note.id}`, onPollVoted);
let latestReactedKey: string | null = null;
let latestUnreactedKey: string | null = null;
// 操作がダブっていないかどうかを簡易的に記録するためのMap
const reactionUserMap = new Map<Misskey.entities.User['id'], string | typeof noReaction>();
let latestPollVotedKey: string | null = null;
function onReacted(ctx: { userId: Misskey.entities.User['id']; reaction: string; emoji?: { name: string; url: string; }; }): void {
const newReactedKey = `${ctx.userId}:${ctx.reaction}`;
if (newReactedKey === latestReactedKey) return;
latestReactedKey = newReactedKey;
const normalizedName = ctx.reaction.replace(/^:(\w+):$/, ':$1@.:');
if (reactionUserMap.has(ctx.userId) && reactionUserMap.get(ctx.userId) === normalizedName) return;
reactionUserMap.set(ctx.userId, normalizedName);
if (ctx.emoji && !(ctx.emoji.name in $note.reactionEmojis)) {
$note.reactionEmojis[ctx.emoji.name] = ctx.emoji.url;
}
const currentCount = $note.reactions[ctx.reaction] || 0;
const currentCount = $note.reactions[normalizedName] || 0;
$note.reactions[ctx.reaction] = currentCount + 1;
$note.reactions[normalizedName] = currentCount + 1;
$note.reactionCount += 1;
if ($i && (ctx.userId === $i.id)) {
$note.myReaction = ctx.reaction;
$note.myReaction = normalizedName;
}
}
function onUnreacted(ctx: { userId: Misskey.entities.User['id']; reaction: string; emoji?: { name: string; url: string; }; }): void {
const newUnreactedKey = `${ctx.userId}:${ctx.reaction}`;
if (newUnreactedKey === latestUnreactedKey) return;
latestUnreactedKey = newUnreactedKey;
const normalizedName = ctx.reaction.replace(/^:(\w+):$/, ':$1@.:');
const currentCount = $note.reactions[ctx.reaction] || 0;
// 確実に一度リアクションされて取り消されている場合のみ処理をとめるAPIで初回読み込み→Streamでアップデート等の場合、reactionUserMapに情報がないため
if (reactionUserMap.has(ctx.userId) && reactionUserMap.get(ctx.userId) === noReaction) return;
reactionUserMap.set(ctx.userId, noReaction);
$note.reactions[ctx.reaction] = Math.max(0, currentCount - 1);
const currentCount = $note.reactions[normalizedName] || 0;
$note.reactions[normalizedName] = Math.max(0, currentCount - 1);
$note.reactionCount = Math.max(0, $note.reactionCount - 1);
if ($note.reactions[ctx.reaction] === 0) delete $note.reactions[ctx.reaction];
if ($note.reactions[normalizedName] === 0) delete $note.reactions[normalizedName];
if ($i && (ctx.userId === $i.id)) {
$note.myReaction = null;
@ -257,10 +280,20 @@ export function useNoteCapture(props: {
}
function subscribe() {
if (mock) {
// モックモードでは購読しない
return;
}
if ($i && store.s.realtimeMode) {
realtimeSubscribe(props);
realtimeSubscribe({
note,
});
} else {
pollingSubscribe(props);
pollingSubscribe({
note,
$note,
});
}
}
@ -277,6 +310,7 @@ export function useNoteCapture(props: {
if ((Date.now() - new Date(note.createdAt).getTime()) > 1000 * 60 * 5) { // 5min
// リノートで表示されているノートでもないし、投稿からある程度経過しているので自動で購読しない
return {
$note,
subscribe: () => {
subscribe();
},
@ -286,6 +320,7 @@ export function useNoteCapture(props: {
if ((Date.now() - new Date(parentNote.createdAt).getTime()) > 1000 * 60 * 5) { // 5min
// リノートで表示されているノートだが、リノートされてからある程度経過しているので自動で購読しない
return {
$note,
subscribe: () => {
subscribe();
},
@ -296,6 +331,7 @@ export function useNoteCapture(props: {
subscribe();
return {
$note,
subscribe: () => {
// すでに購読しているので何もしない
},

View File

@ -418,7 +418,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts._role.useBaseValue }}</template>
</MkSwitch>
<MkTextarea :modelValue="role.policies.uploadableFileTypes.value.join('\n')" :disabled="role.policies.uploadableFileTypes.useDefault" :readonly="readonly" @update:modelValue="role.policies.uploadableFileTypes.value = $event.split('\n')">
<template #caption>{{ i18n.ts._role._options.uploadableFileTypes_caption }}</template>
<template #caption>
<div>{{ i18n.ts._role._options.uploadableFileTypes_caption }}</div>
<div><i class="ti ti-alert-triangle" style="color: var(--MI_THEME-warn);"></i> {{ i18n.tsx._role._options.uploadableFileTypes_caption2({ x: 'application/octet-stream' }) }}</div>
</template>
</MkTextarea>
<MkRange v-model="role.policies.uploadableFileTypes.priority" :min="0" :max="2" :step="1" easing :textConverter="(v) => v === 0 ? i18n.ts._role._priority.low : v === 1 ? i18n.ts._role._priority.middle : v === 2 ? i18n.ts._role._priority.high : ''">
<template #label>{{ i18n.ts._role.priority }}</template>

View File

@ -150,6 +150,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts._role._options.uploadableFileTypes }}</template>
<template #suffix>...</template>
<MkTextarea :modelValue="policies.uploadableFileTypes.join('\n')">
<template #caption>
<div>{{ i18n.ts._role._options.uploadableFileTypes_caption }}</div>
<div><i class="ti ti-alert-triangle" style="color: var(--MI_THEME-warn);"></i> {{ i18n.tsx._role._options.uploadableFileTypes_caption2({ x: 'application/octet-stream' }) }}</div>
</template>
</MkTextarea>
</MkFolder>

View File

@ -101,27 +101,15 @@ html._themeChanging_ {
}
html::view-transition-new(theme-changing) {
z-index: 4000001;
animation: themeChangingNew 0.5s ease;
animation-fill-mode: forwards;
z-index: 4000000;
}
html::view-transition-old(theme-changing) {
z-index: 4000000;
z-index: 4000001;
animation: themeChangingOld 0.5s ease;
animation-fill-mode: forwards;
}
@keyframes themeChangingNew {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes themeChangingOld {
0% {
opacity: 1;

View File

@ -15,6 +15,7 @@ import { globalEvents } from '@/events.js';
import { miLocalStorage } from '@/local-storage.js';
import { $i } from '@/i.js';
import { prefer } from '@/preferences.js';
import { deepEqual } from '@/utility/deep-equal.js';
export type Theme = {
id: string;
@ -127,6 +128,7 @@ function applyThemeInternal(theme: Theme, persist: boolean) {
}
let timeout: number | null = null;
let currentTheme: Theme | null = null;
export function applyTheme(theme: Theme, persist = true) {
if (timeout) {
@ -134,6 +136,9 @@ export function applyTheme(theme: Theme, persist = true) {
timeout = null;
}
if (deepEqual(currentTheme, theme)) return;
currentTheme = theme;
if (window.document.startViewTransition != null && prefer.s.animation) {
window.document.documentElement.classList.add('_themeChanging_');
window.document.startViewTransition(async () => {

View File

@ -39,20 +39,22 @@ export function uploadFile(file: File | Blob, options: {
const filePromise = new Promise<Misskey.entities.DriveFile>((resolve, reject) => {
if ($i == null) return reject();
const allowedMimeTypes = $i.policies.uploadableFileTypes;
const isAllowedMimeType = allowedMimeTypes.some(mimeType => {
if (mimeType === '*' || mimeType === '*/*') return true;
if (mimeType.endsWith('/*')) return file.type.startsWith(mimeType.slice(0, -1));
return file.type === mimeType;
});
if (!isAllowedMimeType) {
os.alert({
type: 'error',
title: i18n.ts.failedToUpload,
text: i18n.ts.cannotUploadBecauseUnallowedFileType,
});
return reject();
}
// こっち側で検出するMIME typeとサーバーで検出するMIME typeは異なる場合があるため、こっち側ではやらないことにする
// https://github.com/misskey-dev/misskey/issues/16091
//const allowedMimeTypes = $i.policies.uploadableFileTypes;
//const isAllowedMimeType = allowedMimeTypes.some(mimeType => {
// if (mimeType === '*' || mimeType === '*/*') return true;
// if (mimeType.endsWith('/*')) return file.type.startsWith(mimeType.slice(0, -1));
// return file.type === mimeType;
//});
//if (!isAllowedMimeType) {
// os.alert({
// type: 'error',
// title: i18n.ts.failedToUpload,
// text: i18n.ts.cannotUploadBecauseUnallowedFileType,
// });
// return reject();
//}
if ((file.size > instance.maxFileSize) || (file.size > ($i.policies.maxFileSizeMb * 1024 * 1024))) {
os.alert({

View File

@ -1,7 +1,7 @@
{
"type": "module",
"name": "misskey-js",
"version": "2025.5.1-beta.0",
"version": "2025.5.1-beta.2",
"description": "Misskey SDK for JavaScript",
"license": "MIT",
"main": "./built/index.js",

View File

@ -29772,7 +29772,15 @@ export interface operations {
[name: string]: unknown;
};
content: {
'application/json': Record<string, never>[];
'application/json': {
id: string;
reactions: {
[key: string]: number;
};
reactionEmojis: {
[key: string]: string;
};
}[];
};
};
/** @description Client error */