summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/drive/files/find-by-hash.ts
blob: 336c85c4441195b47b1191087b8a497e11cac853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import $ from 'cafy';
import define from '../../../define';
import { DriveFiles } from '../../../../../models';

export const meta = {
	desc: {
		'ja-JP': '与えられたMD5ハッシュ値を持つファイルを取得します。',
	},

	tags: ['drive'],

	requireCredential: true as const,

	kind: 'read:drive',

	params: {
		md5: {
			validator: $.str,
			desc: {
				'ja-JP': 'ファイルのMD5ハッシュ'
			}
		}
	},

	res: {
		type: 'array' as const,
		optional: false as const, nullable: false as const,
		items: {
			type: 'object' as const,
			optional: false as const, nullable: false as const,
			ref: 'DriveFile',
		}
	},
};

export default define(meta, async (ps, user) => {
	const files = await DriveFiles.find({
		md5: ps.md5,
		userId: user.id,
	});

	return await DriveFiles.packMany(files, { self: true });
});