remove admin/drive/cleanup API

This API endpoint is not working correctly and can cause unintended data loss:
It may remove emojis that have been imported from other instances.

See also https://github.com/misskey-dev/misskey/issues/8222
This commit is contained in:
Johann150 2022-08-03 11:00:48 +02:00
parent 2fa90e7f43
commit bc1c66e16e
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
4 changed files with 14 additions and 31 deletions

View file

@ -0,0 +1,13 @@
export class driveFileUserConstraint1659516638000 {
name = 'driveFileUserConstraint1659516638000';
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "drive_file" DROP CONSTRAINT "FK_860fa6f6c7df5bb887249fba22e"`);
await queryRunner.query(`ALTER TABLE "drive_file" ADD CONSTRAINT "FK_860fa6f6c7df5bb887249fba22e" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "drive_file" DROP CONSTRAINT "FK_860fa6f6c7df5bb887249fba22e"`);
await queryRunner.query(`ALTER TABLE "drive_file" ADD CONSTRAINT "FK_860fa6f6c7df5bb887249fba22e" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE SET NULL`);
}
}

View file

@ -24,7 +24,7 @@ export class DriveFile {
public userId: User['id'] | null;
@ManyToOne(type => User, {
onDelete: 'SET NULL',
onDelete: 'RESTRICT',
})
@JoinColumn()
public user: User | null;

View file

@ -10,7 +10,6 @@ import * as ep___admin_announcements_list from './endpoints/admin/announcements/
import * as ep___admin_announcements_update from './endpoints/admin/announcements/update.js';
import * as ep___admin_deleteAllFilesOfAUser from './endpoints/admin/delete-all-files-of-a-user.js';
import * as ep___admin_drive_cleanRemoteFiles from './endpoints/admin/drive/clean-remote-files.js';
import * as ep___admin_drive_cleanup from './endpoints/admin/drive/cleanup.js';
import * as ep___admin_drive_files from './endpoints/admin/drive/files.js';
import * as ep___admin_drive_showFile from './endpoints/admin/drive/show-file.js';
import * as ep___admin_emoji_addAliasesBulk from './endpoints/admin/emoji/add-aliases-bulk.js';
@ -320,7 +319,6 @@ const eps = [
['admin/announcements/update', ep___admin_announcements_update],
['admin/delete-all-files-of-a-user', ep___admin_deleteAllFilesOfAUser],
['admin/drive/clean-remote-files', ep___admin_drive_cleanRemoteFiles],
['admin/drive/cleanup', ep___admin_drive_cleanup],
['admin/drive/files', ep___admin_drive_files],
['admin/drive/show-file', ep___admin_drive_showFile],
['admin/emoji/add-aliases-bulk', ep___admin_emoji_addAliasesBulk],

View file

@ -1,28 +0,0 @@
import { IsNull } from 'typeorm';
import define from '../../../define.js';
import { deleteFile } from '@/services/drive/delete-file.js';
import { DriveFiles } from '@/models/index.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
} as const;
export const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const files = await DriveFiles.findBy({
userId: IsNull(),
});
for (const file of files) {
deleteFile(file);
}
});