/
kodi.ts
57 lines (53 loc) · 1.68 KB
/
kodi.ts
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
import { Operation } from 'express-openapi';
import { RecordedModelInterface } from '../../../../Model/Api/RecordedModel';
import factory from '../../../../Model/ModelFactory';
import * as api from '../../../api';
export const post: Operation = async(req, res) => {
const recordeds = <RecordedModelInterface> factory.get('RecordedModel');
try {
await recordeds.sendToKodi(req.headers.host!, req.header('x-forwarded-proto') === 'https', req.body.kodi, req.params.id, req.body.encodedId);
api.responseJSON(res, 200, { code: 200, result: 'ok' });
} catch (err) {
if (err.message === RecordedModelInterface.NotFoundRecordedFileError) {
api.responseError(res, { code: 404, message: 'Recorded file is not Found' });
} else {
api.responseServerError(res, err.message);
}
}
};
post.apiDoc = {
summary: '録画済みファイルを kodi へ送信',
tags: ['recorded'],
description: '録画済みファイルを kodi へ送信する',
parameters: [
{
name: 'id',
in: 'path',
description: 'recorded id',
required: true,
type: 'integer',
},
{
name: 'body',
in: 'body',
required: true,
schema: {
$ref: '#/definitions/RecordedSendToKodi',
},
},
],
responses: {
200: {
description: 'ok',
},
404: {
description: 'Not found',
},
default: {
description: '予期しないエラー',
schema: {
$ref: '#/definitions/Error',
},
},
},
};