forked from matecat/MateCat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
182 lines (146 loc) · 5.21 KB
/
router.php
File metadata and controls
182 lines (146 loc) · 5.21 KB
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
<?php
require_once './inc/Bootstrap.php' ;
require_once './lib/Model/queries.php' ;
Bootstrap::start();
$klein = new \Klein\Klein();
function route($path, $method, $controller, $action) {
global $klein;
$klein->respond($method, $path, function() use ($controller, $action) {
$reflect = new ReflectionClass($controller);
$instance = $reflect->newInstanceArgs(func_get_args());
$instance->respond( $action );
});
}
Features::loadRoutes( $klein );
$klein->onError(function ($klein, $err_msg, $err_type, $exception) {
// TODO still need to catch fatal errors here with 500 code
switch( $err_type ) {
case 'API\V2\AuthenticationError':
$klein->response()->code(401);
break;
case 'API\V2\AuthorizationError':
$klein->response()->code(403);
break;
case 'API\V2\ValidationError':
$klein->response()->code(400);
$klein->response()->json( array('error' => $err_msg ));
break;
case 'Exceptions_RecordNotFound':
case 'Exceptions\NotFoundError':
\Log::doLog('Not found error for URI: ' . $_SERVER['REQUEST_URI']);
$klein->response()->code(404);
$klein->response()->body('not found');
$klein->response()->send();
break;
default:
$klein->response()->code(500);
\Utils::sendErrMailReport( $exception->getMessage() . "" . $exception->getTraceAsString(), 'Generic error' );
\Log::doLog("Error: {$exception->getMessage()} ");
\Log::doLog( $exception->getTraceAsString() );
break;
}
});
// This is unreleased APIs. I'm no longer fond of the [i:id_job] in the path,
// so before releasing change it use a querystring.
//
route(
'/api/v2/jobs/[i:id_job]/revision-data', 'GET',
'API_V2_JobRevisionData', 'revisionData'
);
route(
'/api/v2/jobs/[i:id_job]/revision-data/segments', 'GET',
'API_V2_JobRevisionData', 'segments'
);
route(
'/api/v2/project-completion-status/[i:id_project]', 'GET',
'\API\V2\ProjectCompletionStatus', 'status'
);
route(
'/api/v2/project-translation/[i:id_project]', 'GET',
'API_V2_ProjectTranslation', 'status'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/translation-issues', 'GET',
'API\V2\ChunkTranslationIssueController', 'index'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/translation-versions', 'GET',
'\API\V2\ChunkTranslationVersionController', 'index'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-versions', 'GET',
'\API\V2\SegmentVersion', 'index'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-versions/[:version_number]', 'GET',
'API_V2_SegmentVersion', 'detail'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-issues', 'POST',
'API\V2\SegmentTranslationIssueController', 'create'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-issues/[:id_issue]', 'DELETE',
'API\V2\SegmentTranslationIssueController', 'delete'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-issues/[:id_issue]', 'POST',
'API\V2\SegmentTranslationIssueController', 'update'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-issues/[:id_issue]/comments', 'POST',
'API\V2\TranslationIssueComment', 'create'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation-issues/[:id_issue]/comments', 'GET',
'API\V2\TranslationIssueComment', 'index'
);
route(
'/api/v2/jobs/[:id_job]/[:password]/segments/[:id_segment]/translation', 'GET',
'API\V2\TranslationController', 'index'
);
$klein->respond('GET', '/utils/pee', function() {
$reflect = new ReflectionClass('peeViewController');
$instance = $reflect->newInstanceArgs(func_get_args());
$instance->doAction();
$instance->finalize();
});
route(
'/api/v2/projects/[:id_project]/[:password]/jobs/[:id_job]/merge', 'POST',
'API\V2\JobMergeController', 'merge'
);
route( '/api/v1/jobs/[:id_job]/[:password]/stats', 'GET', 'API\V1\StatsController', 'stats' );
route( '/api/v2/jobs/[:id_job]/[:password]/segments-filter', 'GET',
'Features\SegmentFilter\Controller\API\FilterController', 'index'
);
route( '/api/v2/jobs/[:id_job]/[:password]/options', 'POST', 'API\V2\ChunkOptionsController', 'update' );
$klein->with('/api/v2/jobs/[:id_job]/[:password]', function() {
route( '/comments', 'GET', 'API\V2\CommentsController', 'index' );
/**
* This should be moved in plugin space
*/
route( '/quality-report', 'GET',
'Features\ReviewImproved\Controller\API\QualityReportController', 'show'
);
});
route(
'/webhooks/gdrive/open', 'GET',
'GDriveController', 'open'
);
route(
'/gdrive/list', 'GET',
'GDriveController', 'listImportedFiles'
);
route(
'/gdrive/change/[:sourceLanguage]', 'GET',
'GDriveController', 'changeSourceLanguage'
);
route(
'/gdrive/delete/[:fileId]', 'GET',
'GDriveController', 'deleteImportedFile'
);
route(
'/gdrive/verify', 'GET',
'GDriveController', 'isGDriveAccessible'
);
$klein->dispatch();