Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: To make return 400 when drive limit is exceeded #809

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/server/api/endpoints/drive/files/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import define from '../../../define';
import { apiLogger } from '../../../logger';
import { ApiError } from '../../../error';
import { DriveFiles } from '../../../../../models';
import { IdentifiableError } from '../../../../../misc/identifiable-error';

export const meta = {
desc: {
Expand Down Expand Up @@ -74,7 +75,13 @@ export const meta = {
message: 'Invalid file name.',
code: 'INVALID_FILE_NAME',
id: 'f449b209-0c60-4e51-84d5-29486263bfd4'
}
},

noFreeSpace: {
message: 'Cannot upload the file because you have no free space of drive.',
code: 'NO_FREE_SPACE',
id: 'd08dbc37-a6a9-463a-8c47-96c32ab5f064',
},
}
};

Expand All @@ -99,7 +106,12 @@ export default define(meta, async (ps, user, app, file, cleanup) => {
const driveFile = await create(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive);
return await DriveFiles.pack(driveFile, { self: true });
} catch (e) {
apiLogger.error(e);
if (e instanceof Error || typeof e === 'string') {
apiLogger.error(e);
}
if (e instanceof IdentifiableError) {
if (e.id === 'c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6') throw new ApiError(meta.errors.noFreeSpace);
}
throw new ApiError();
} finally {
cleanup!();
Expand Down
3 changes: 2 additions & 1 deletion src/services/drive/add-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { genId } from '../../misc/gen-id';
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
import * as S3 from 'aws-sdk/clients/s3';
import { getS3 } from './s3';
import { IdentifiableError } from '../../misc/identifiable-error';

const logger = driveLogger.createSubLogger('register', 'yellow');

Expand Down Expand Up @@ -331,7 +332,7 @@ export default async function(
// If usage limit exceeded
if (usage + info.size > driveCapacity) {
if (Users.isLocalUser(user)) {
throw new Error('no-free-space');
throw new IdentifiableError('c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6', 'No free space.');
} else {
// (アバターまたはバナーを含まず)最も古いファイルを削除する
deleteOldFile(user as IRemoteUser);
Expand Down