mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-06 00:33:51 +09:00
なんかもうめっちゃ変えた
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import define from '../../../define.js';
|
||||
import { createCleanRemoteFilesJob } from '@/queue/index.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { QueueService } from '@/core/QueueService.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -15,6 +16,13 @@ export const paramDef = {
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
createCleanRemoteFilesJob();
|
||||
});
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
private queueService: QueueService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
this.queueService.createCleanRemoteFilesJob();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { IsNull } from 'typeorm';
|
||||
import define from '../../../define.js';
|
||||
import { deleteFile } from '@/services/drive/delete-file.js';
|
||||
import { DriveFiles } from '@/models/index.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DriveFilesRepository } from '@/models/index.js';
|
||||
import { DriveService } from '@/core/DriveService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -17,12 +19,22 @@ export const paramDef = {
|
||||
} 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(),
|
||||
});
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
for (const file of files) {
|
||||
deleteFile(file);
|
||||
private driveService: DriveService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const files = await this.driveFilesRepository.findBy({
|
||||
userId: IsNull(),
|
||||
});
|
||||
|
||||
for (const file of files) {
|
||||
this.driveService.deleteFile(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { DriveFiles } from '@/models/index.js';
|
||||
import define from '../../../define.js';
|
||||
import { makePaginationQuery } from '../../../common/make-pagination-query.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DriveFilesRepository } from '@/models/index.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -39,32 +41,42 @@ export const paramDef = {
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const query = makePaginationQuery(DriveFiles.createQueryBuilder('file'), ps.sinceId, ps.untilId);
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
if (ps.userId) {
|
||||
query.andWhere('file.userId = :userId', { userId: ps.userId });
|
||||
} else {
|
||||
if (ps.origin === 'local') {
|
||||
query.andWhere('file.userHost IS NULL');
|
||||
} else if (ps.origin === 'remote') {
|
||||
query.andWhere('file.userHost IS NOT NULL');
|
||||
}
|
||||
private queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const query = this.queryService.makePaginationQuery(this.driveFilesRepository.createQueryBuilder('file'), ps.sinceId, ps.untilId);
|
||||
|
||||
if (ps.hostname) {
|
||||
query.andWhere('file.userHost = :hostname', { hostname: ps.hostname });
|
||||
}
|
||||
if (ps.userId) {
|
||||
query.andWhere('file.userId = :userId', { userId: ps.userId });
|
||||
} else {
|
||||
if (ps.origin === 'local') {
|
||||
query.andWhere('file.userHost IS NULL');
|
||||
} else if (ps.origin === 'remote') {
|
||||
query.andWhere('file.userHost IS NOT NULL');
|
||||
}
|
||||
|
||||
if (ps.hostname) {
|
||||
query.andWhere('file.userHost = :hostname', { hostname: ps.hostname });
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.type) {
|
||||
if (ps.type.endsWith('/*')) {
|
||||
query.andWhere('file.type like :type', { type: ps.type.replace('/*', '/') + '%' });
|
||||
} else {
|
||||
query.andWhere('file.type = :type', { type: ps.type });
|
||||
}
|
||||
}
|
||||
|
||||
const files = await query.take(ps.limit).getMany();
|
||||
|
||||
return await this.driveFileEntityService.packMany(files, { detail: true, withUser: true, self: true });
|
||||
});
|
||||
}
|
||||
|
||||
if (ps.type) {
|
||||
if (ps.type.endsWith('/*')) {
|
||||
query.andWhere('file.type like :type', { type: ps.type.replace('/*', '/') + '%' });
|
||||
} else {
|
||||
query.andWhere('file.type = :type', { type: ps.type });
|
||||
}
|
||||
}
|
||||
|
||||
const files = await query.take(ps.limit).getMany();
|
||||
|
||||
return await DriveFiles.packMany(files, { detail: true, withUser: true, self: true });
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { DriveFiles } from '@/models/index.js';
|
||||
import define from '../../../define.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DriveFilesRepository } from '@/models/index.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
@ -169,25 +171,33 @@ export const paramDef = {
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const file = ps.fileId ? await DriveFiles.findOneBy({ id: ps.fileId }) : await DriveFiles.findOne({
|
||||
where: [{
|
||||
url: ps.url,
|
||||
}, {
|
||||
thumbnailUrl: ps.url,
|
||||
}, {
|
||||
webpublicUrl: ps.url,
|
||||
}],
|
||||
});
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const file = ps.fileId ? await this.driveFilesRepository.findOneBy({ id: ps.fileId }) : await this.driveFilesRepository.findOne({
|
||||
where: [{
|
||||
url: ps.url,
|
||||
}, {
|
||||
thumbnailUrl: ps.url,
|
||||
}, {
|
||||
webpublicUrl: ps.url,
|
||||
}],
|
||||
});
|
||||
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
if (!me.isAdmin) {
|
||||
delete file.requestIp;
|
||||
delete file.requestHeaders;
|
||||
}
|
||||
|
||||
return file;
|
||||
});
|
||||
}
|
||||
|
||||
if (!me.isAdmin) {
|
||||
delete file.requestIp;
|
||||
delete file.requestHeaders;
|
||||
}
|
||||
|
||||
return file;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user