なんかもうめっちゃ変えた
This commit is contained in:
parent
d9ab03f086
commit
b75184ec8e
946 changed files with 41219 additions and 28839 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import { DriveFile } from '@/models/entities/drive-file.js';
|
||||
import { DriveFiles, Users } from '@/models/index.js';
|
||||
import define from '../../../define.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type { DriveFile } from '@/models/entities/DriveFile.js';
|
||||
import { DriveFilesRepository } from '@/models/index.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
|
@ -52,34 +55,44 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
let file: DriveFile | null = null;
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
if (ps.fileId) {
|
||||
file = await DriveFiles.findOneBy({ id: ps.fileId });
|
||||
} else if (ps.url) {
|
||||
file = await DriveFiles.findOne({
|
||||
where: [{
|
||||
url: ps.url,
|
||||
}, {
|
||||
webpublicUrl: ps.url,
|
||||
}, {
|
||||
thumbnailUrl: ps.url,
|
||||
}],
|
||||
private driveFileEntityService: DriveFileEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
let file: DriveFile | null = null;
|
||||
|
||||
if (ps.fileId) {
|
||||
file = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
|
||||
} else if (ps.url) {
|
||||
file = await this.driveFilesRepository.findOne({
|
||||
where: [{
|
||||
url: ps.url,
|
||||
}, {
|
||||
webpublicUrl: ps.url,
|
||||
}, {
|
||||
thumbnailUrl: ps.url,
|
||||
}],
|
||||
});
|
||||
}
|
||||
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
if ((!me.isAdmin && !me.isModerator) && (file.userId !== me.id)) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
return await this.driveFileEntityService.pack(file, {
|
||||
detail: true,
|
||||
withUser: true,
|
||||
self: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
return await DriveFiles.pack(file, {
|
||||
detail: true,
|
||||
withUser: true,
|
||||
self: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue