-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutes.php
More file actions
107 lines (90 loc) · 3.37 KB
/
Copy pathroutes.php
File metadata and controls
107 lines (90 loc) · 3.37 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
<?php
function getRequestHeaders() {
$headers = array();
foreach($_SERVER as $key => $value) {
if (substr($key, 0, 5) <> 'HTTP_') {
continue;
}
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
$headers[$header] = $value;
}
return $headers;
}
// أزل التعليقات من أجل تفعيل مفتاح واجهة برمجة التطبيقات
/* Flight::before('start', function() {
// تخطي المصادقة لمسارات معينة إذا لزم الأمر
if (Flight::request()->url == '/api/health') {
return;
}
$headers = getRequestHeaders();
$apiKey = isset($headers['Apikey']) ? $headers['Apikey'] : '';
if (empty($apiKey) || $apiKey != 'YOUR_API_KEY') {
Flight::halt(401);
}
}); */
// إضافة نقطة نهاية للتحقق من الحالة
Flight::route('GET /api/health', function() {
Flight::json(['status' => 'ok']);
});
// التحقق من الكلمات المكتوبة بشكل خاطئ في النص
Flight::route('POST /api/spell/check', function() {
$request = Flight::request();
$Arabic = Flight::get('arabic');
// الحصول على النص من جسم الطلب
$text = $request->data->text;
if (empty($text)) {
Flight::json(['error' => 'لم يتم تقديم نص'], 400);
return;
}
try {
$misspelledWords = $Arabic->spellGetMisspelled($text);
Flight::json([
'status' => 'success',
'misspelled_words' => $misspelledWords
]);
} catch (Exception $e) {
Flight::json(['error' => $e->getMessage()], 500);
}
});
// الحصول على اقتراحات للكلمات المكتوبة بشكل خاطئ
Flight::route('POST /api/spell/suggest', function() {
$request = Flight::request();
$Arabic = Flight::get('arabic');
// الحصول على النص من جسم الطلب
$text = $request->data->text;
if (empty($text)) {
Flight::json(['error' => 'لم يتم تقديم نص'], 400);
return;
}
try {
$suggestions = $Arabic->spellSuggestCorrections($text);
Flight::json([
'status' => 'success',
'suggestions' => $suggestions
]);
} catch (Exception $e) {
Flight::json(['error' => $e->getMessage()], 500);
}
});
// الحصول على الكلمات المكتوبة بشكل خاطئ والاقتراحات في طلب واحد
Flight::route('POST /api/spell/check-and-suggest', function() {
$request = Flight::request();
$Arabic = Flight::get('arabic');
// الحصول على النص من جسم الطلب
$text = $request->data->text;
if (empty($text)) {
Flight::json(['error' => 'لم يتم تقديم نص'], 400);
return;
}
try {
$misspelledWords = $Arabic->spellGetMisspelled($text);
$suggestions = $Arabic->spellSuggestCorrections($text);
Flight::json([
'status' => 'success',
'misspelled_words' => $misspelledWords,
'suggestions' => $suggestions
]);
} catch (Exception $e) {
Flight::json(['error' => $e->getMessage()], 500);
}
});