summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/admin/drive/show-file.ts
blob: cfe25306c267a4e0ea93463037e36d181ac5775f (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { DriveFiles } from '../../../../../models';

export const meta = {
	tags: ['admin'],

	requireCredential: true as const,
	requireModerator: true,

	params: {
		fileId: {
			validator: $.optional.type(ID),
		},

		url: {
			validator: $.optional.str,
		},
	},

	errors: {
		noSuchFile: {
			message: 'No such file.',
			code: 'NO_SUCH_FILE',
			id: 'caf3ca38-c6e5-472e-a30c-b05377dcc240'
		}
	},

	res: {
		type: 'object' as const,
		optional: false as const, nullable: false as const,
		properties: {
			id: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				format: 'id',
				description: 'The unique identifier for this Drive file.',
				example: 'xxxxxxxxxx',
			},
			createdAt: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				format: 'date-time',
				description: 'The date that the Drive file was created on Misskey.'
			},
			userId: {
				type: 'string' as const,
				optional: false as const, nullable: true as const,
				format: 'id',
				description: 'Owner ID of this Drive file.',
				example: 'xxxxxxxxxx',
			},
			userHost: {
				type: 'string' as const,
				optional: false as const, nullable: true as const
			},
			md5: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				format: 'md5',
				description: 'The MD5 hash of this Drive file.',
				example: '15eca7fba0480996e2245f5185bf39f2'
			},
			name: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'The file name with extension.',
				example: 'lenna.jpg'
			},
			type: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'The MIME type of this Drive file.',
				example: 'image/jpeg'
			},
			size: {
				type: 'number' as const,
				optional: false as const, nullable: false as const,
				description: 'The size of this Drive file. (bytes)',
				example: 51469
			},
			comment: {
				type: 'string' as const,
				optional: false as const, nullable: true as const
			},
			blurhash: {
				type: 'string' as const,
				optional: false as const, nullable: true as const
			},
			properties: {
				type: 'object' as const,
				optional: false as const, nullable: false as const,
				properties: {
					width: {
						type: 'number' as const,
						optional: false as const, nullable: false as const,
						example: 1280
					},
					height: {
						type: 'number' as const,
						optional: false as const, nullable: false as const,
						example: 720
					},
					avgColor: {
						type: 'string' as const,
						optional: true as const, nullable: false as const,
						example: 'rgb(40,65,87)'
					}
				}
			},
			storedInternal: {
				type: 'boolean' as const,
				optional: false as const, nullable: true as const,
				description: 'Indicates whether this file is stored in the same location as Misskey itself',
				example: true
			},
			url: {
				type: 'string' as const,
				optional: false as const, nullable: true as const,
				format: 'url',
				description: 'The URL of this Drive file.',
			},
			thumbnailUrl: {
				type: 'string' as const,
				optional: false as const, nullable: true as const,
				format: 'url',
				description: 'The thumbnail URL of this Drive file.',
			},
			webpublicUrl: {
				type: 'string' as const,
				optional: false as const, nullable: true as const,
				format: 'url',
				description: 'The public URL of this Drive file.',
			},
			accessKey: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'Access key to access this file'
			},
			thumbnailAccessKey: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'Access key to access this file for thumbnail'
			},
			webpublicAccessKey: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'Access key to access this file for webpublic'
			},
			uri: {
				type: 'string' as const,
				optional: false as const, nullable: true as const
			},
			src: {
				type: 'string' as const,
				optional: false as const, nullable: true as const
			},
			folderId: {
				type: 'string' as const,
				optional: false as const, nullable: true as const,
				format: 'id',
				description: 'The parent folder ID of this Drive file.',
				example: 'xxxxxxxxxx',
			},
			isSensitive: {
				type: 'boolean' as const,
				optional: false as const, nullable: false as const,
				description: 'Whether this Drive file is sensitive.',
			},
			isLink: {
				type: 'boolean' as const,
				optional: false as const, nullable: false as const
			}
		}
	}
};

export default define(meta, async (ps, me) => {
	const file = ps.fileId ? await DriveFiles.findOne(ps.fileId) : await DriveFiles.findOne({
		where: [{
			url: ps.url
		}, {
			thumbnailUrl: ps.url
		}, {
			webpublicUrl: ps.url
		}]
	});

	if (file == null) {
		throw new ApiError(meta.errors.noSuchFile);
	}

	return file;
});