2023-07-27 14:31:52 +09:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2023-09-15 14:28:29 +09:00
|
|
|
import type { DriveFilesRepository } from '@/models/_.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2018-10-07 16:51:46 +09:00
|
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['drive'],
|
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2018-10-07 16:51:46 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
kind: 'read:drive',
|
2018-10-07 16:51:46 +09:00
|
|
|
|
2022-06-10 07:25:20 +02:00
|
|
|
description: 'Check if a given file exists.',
|
|
|
|
|
|
2019-02-24 18:13:11 +09:00
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'boolean',
|
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 18:13:11 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2018-10-07 16:51:46 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
md5: { type: 'string' },
|
|
|
|
|
},
|
|
|
|
|
required: ['md5'],
|
|
|
|
|
} as const;
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-08-17 21:20:58 +09:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.driveFilesRepository)
|
|
|
|
|
private driveFilesRepository: DriveFilesRepository,
|
|
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
2023-07-11 14:58:58 +09:00
|
|
|
const exist = await this.driveFilesRepository.exist({
|
|
|
|
|
where: {
|
|
|
|
|
md5: ps.md5,
|
|
|
|
|
userId: me.id,
|
|
|
|
|
},
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
|
|
|
|
|
2023-07-11 14:58:58 +09:00
|
|
|
return exist;
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|