Skip to content

Commit

Permalink
Merge remote-tracking branch 'mk/develop' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	locales/index.d.ts
#	locales/ja-JP.yml
#	packages/backend/src/server/web/boot.js
  • Loading branch information
caipira113 committed Aug 26, 2024
2 parents 54122a9 + 255c8bd commit b353223
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
-

### Client
-
- サイズ制限を超過するファイルをアップロードしようとした際にエラーを出すように

### Server
-
- ファイルがサイズの制限を超えてアップロードされた際にエラーを返さなかった問題を修正


## 2024.8.0
Expand Down
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5068,6 +5068,10 @@ export interface Locale extends ILocale {
* 作成したアンテナ
*/
"createdAntennas": string;
/**
* これ以上このクリップにノートを追加できません。
*/
"clipNoteLimitExceeded": string;
/**
* 編集済み: {date} {time}
*/
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ confirmWhenRevealingSensitiveMedia: "センシティブなメディアを表示
sensitiveMediaRevealConfirm: "センシティブなメディアです。表示しますか?"
createdLists: "作成したリスト"
createdAntennas: "作成したアンテナ"
clipNoteLimitExceeded: "これ以上このクリップにノートを追加できません。"
noteUpdatedAt: "編集済み: {date} {time}"

_delivery:
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export type Config = {
proxySmtp: string | undefined;
proxyBypassHosts: string[] | undefined;
allowedPrivateNetworks: string[] | undefined;
maxFileSize: number | undefined;
maxFileSize: number;
clusterLimit: number | undefined;
id: string;
outgoingAddress: string | undefined;
Expand Down Expand Up @@ -254,7 +254,7 @@ export function loadConfig(): Config {
proxySmtp: config.proxySmtp,
proxyBypassHosts: config.proxyBypassHosts,
allowedPrivateNetworks: config.allowedPrivateNetworks,
maxFileSize: config.maxFileSize,
maxFileSize: config.maxFileSize ?? 262144000,
clusterLimit: config.clusterLimit,
outgoingAddress: config.outgoingAddress,
outgoingAddressFamily: config.outgoingAddressFamily,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/DownloadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DownloadService {

const timeout = 30 * 1000;
const operationTimeout = 60 * 1000;
const maxSize = this.config.maxFileSize ?? 262144000;
const maxSize = this.config.maxFileSize;

const urlObj = new URL(url);
let filename = urlObj.pathname.split('/').pop() ?? 'untitled';
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/MetaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class MetaEntityService {
mediaProxy: this.config.mediaProxy,
enableUrlPreview: instance.urlPreviewEnabled,
noteSearchableScope: (this.config.meilisearch == null || this.config.meilisearch.scope !== 'local') ? 'global' : 'local',
maxFileSize: this.config.maxFileSize,
};

return packed;
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export const packedMetaLiteSchema = {
optional: false, nullable: false,
default: 'local',
},
maxFileSize: {
type: 'number',
optional: false, nullable: false,
},
},
} as const;

Expand Down
11 changes: 10 additions & 1 deletion packages/backend/src/server/api/ApiCallService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,18 @@ export class ApiCallService implements OnApplicationShutdown {
return;
}

const [path] = await createTemp();
const [path, cleanup] = await createTemp();
await stream.pipeline(multipartData.file, fs.createWriteStream(path));

// ファイルサイズが制限を超えていた場合
// なお truncated はストリームを読み切ってからでないと機能しないため、stream.pipeline より後にある必要がある
if (multipartData.file.truncated) {
cleanup();
reply.code(413);
reply.send();
return;
}

const fields = {} as Record<string, unknown>;
for (const [k, v] of Object.entries(multipartData.fields)) {
fields[k] = typeof v === 'object' && 'value' in v ? v.value : undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/api/ApiServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ApiServerService {

fastify.register(multipart, {
limits: {
fileSize: this.config.maxFileSize ?? 262144000,
fileSize: this.config.maxFileSize,
files: 1,
},
});
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/server/web/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@
<span class="button-label-big">Reload / リロード</span>
</button>
<p><b>The following actions may solve the problem. / 以下を行うと解決する可能性があります。</b></p>
<p>Clear the browser cache / ブラウザのキャッシュをクリアする</p>
<p>Update your os and browser / ブラウザおよびOSを最新バージョンに更新する</p>
<p>Disable an adblocker / アドブロッカーを無効にする</p>
<p>&#40;Tor Browser&#41; Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する</p>
<p>Clear the browser cache / ブラウザのキャッシュをクリアする</p>
<p>&#40;Tor Browser&#41; Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する</p>
<details style="color: rgb(242, 238, 252);">
<summary>Other options / その他のオプション</summary>
<a href="/flush">
Expand Down Expand Up @@ -212,7 +212,7 @@
<summary>
<code>ERROR CODE: ${code}</code>
</summary>
<code>${JSON.stringify(details)}</code>`;
<code>${details.toString()} ${JSON.stringify(details)}</code>`;
errorsElement.appendChild(detailsElement);
addStyle(`
@import url("https://fonts.bunny.net/css?family=jetbrains-mono");
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkPostForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const submitText = computed((): string => {
});

const textLength = computed((): number => {
return (text.value + imeText.value).trim().length;
return (text.value + imeText.value).length;
});

const maxTextLength = computed((): number => {
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/scripts/get-note-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export async function getNoteClipMenu(props: {
});
if (props.currentClip?.id === clip.id) props.isDeleted.value = true;
}
} else if (err.id === 'f0dba960-ff73-4615-8df4-d6ac5d9dc118') {
os.alert({
type: 'error',
text: i18n.ts.clipNoteLimitExceeded,
});
} else {
os.alert({
type: 'error',
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/scripts/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { apiUrl } from '@/config.js';
import { $i } from '@/account.js';
import { alert } from '@/os.js';
import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js';

type Uploading = {
id: string;
Expand All @@ -39,6 +40,15 @@ export function uploadFile(

if (folder && typeof folder === 'object') folder = folder.id;

if (file.size > instance.maxFileSize) {
alert({
type: 'error',
title: i18n.ts.failedToUpload,
text: i18n.ts.cannotUploadBecauseExceedsFileSizeLimit,
});
return Promise.reject();
}

return new Promise((resolve, reject) => {
const id = uuid();

Expand Down
1 change: 1 addition & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4959,6 +4959,7 @@ export type components = {
* @enum {string}
*/
noteSearchableScope: 'local' | 'global';
maxFileSize: number;
};
MetaDetailedOnly: {
features?: {
Expand Down

2 comments on commit b353223

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chromatic detects changes. Please review the changes on Chromatic.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chromatic detects changes. Please review the changes on Chromatic.

Please sign in to comment.