forked from soruly/trace.moe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.php
38 lines (36 loc) · 1.09 KB
/
info.php
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
<?php
ini_set("display_errors", 0);
header('Content-Type: application/json');
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) ){
//request from AJAX, continue
//}
//else if( isset( $_SERVER['HTTP_REFERER'] ) && ( $_SERVER['HTTP_REFERER'] == 'https://trace.moe/' ) ){
//request from original site, continue
}
else{
header("HTTP/1.0 404 Not Found");
}
if(isset($_GET['anilist_id'])){
$request = array(
"size" => 1,
"query" => array(
"ids" => array(
"values" => array(intval($_GET['anilist_id']))
)
)
);
$payload = json_encode($request);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://127.0.0.1:9200/anilist/anime/_search");
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
$result = json_decode($res);
foreach($result->hits->hits as $hit){
$hits[] = $hit->_source;
}
curl_close($curl);
echo(json_encode($hits));
}
?>