From 75d0a579dc46ee835c72712d650c14b44367c7a6 Mon Sep 17 00:00:00 2001 From: Bigsk <1332540+bigskcode@user.noreply.gitee.com> Date: Mon, 10 Aug 2020 17:28:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=BD=A2=E5=BC=8F=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?Fabric=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 105 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/index.php b/index.php index dc4c962..078217f 100644 --- a/index.php +++ b/index.php @@ -1,22 +1,9 @@ array( 'timeout'=>3, @@ -46,9 +33,15 @@ function get_online_url($file,$id){ $str='http://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'.get_file_path($file); return $str; } -function check_file_update($file,$dir,$url){ +function get_online_domain($file,$id){ + global $type; + $str='http://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'; + return $str; +} +function check_file_update($file,$dir,$url,$time){ + header('Content-Disposition: attachment; filename="'.basename($file).'"'); $time=time()-@filemtime($file); - if($time<86400){//检查文件是否超出过期期限(1天,86400秒) + if($time<$time){//检查文件是否超出过期期限(1天,86400秒) echo file_get_contents($file); }else{ if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件 @@ -56,7 +49,7 @@ function check_file_update($file,$dir,$url){ echo file_get_contents($file); }else{ echo file_get_contents($url.'/'.str_replace($dir,'',$file)); - $jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.date("Y-m-d h:i:s").'"}'); + $jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.time().'"}'); fwrite($jsonwrite,file_get_contents($url.'/'.str_replace($dir,'',$file))); fclose($jsonwrite); } @@ -65,17 +58,39 @@ function check_file_update($file,$dir,$url){ } } } +function check_file_update_json($file,$dir,$url,$time){ + header('Content-Disposition: attachment; filename="'.basename($file).'"'); + $time=time()-@filemtime($file.'/index.json'); + if($time<$time){//检查文件是否超出过期期限(1天,86400秒) + echo file_get_contents($file.'/index.json'); + }else{ + if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件 + if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.json')){ + echo file_get_contents($file); + }else{ + echo file_get_contents($url.'/'.str_replace($dir,'',$file)); + $jsonwrite = fopen($file.'/index.json', "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.time().'"}'); + fwrite($jsonwrite,file_get_contents($url.'/'.str_replace($dir,'',$file))); + fclose($jsonwrite); + } + }else{ + echo file_get_contents($file.'/index.json'); + } + } +} function check_file_update_adv($file,$url,$check_url){ + header('Content-Disposition: attachment; filename="'.basename($file).'"'); $time=time()-@filemtime($file); if($time<86400){//检查文件是否超出过期期限(1天,86400秒) echo file_get_contents($file); }else{ - if(url_exists_2($check_url)){//防止源无法访问而损坏文件 + if(url_exists($check_url)){//防止源无法访问而损坏文件 if(file_get_contents($url)==@file_get_contents($file)){ echo file_get_contents($file); }else{ echo @file_get_contents($url); - $jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.date("Y-m-d h:i:s").'"}'); + + $jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.time().'"}'); fwrite($jsonwrite,file_get_contents($url)); fclose($jsonwrite); } @@ -88,42 +103,49 @@ function check_file_update_adv($file,$url,$check_url){ function download_file($url,$file,$other){//下载文件 system('python download.py --url "'.$url.'" --file "'.$file.'" --other "'.$other.'"'); } +if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾 + $id=0; +}elseif(get_main_domain($_GET['path'])=='fabricmc'){ + $id=1; +} if($_GET['error']!=""){ - echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":"'.date("Y-m-d h:i:s").'"}'; + echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":"'.time().'"}'; }elseif($_GET['path']==""){ - echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":"'.date("Y-m-d h:i:s").'"}'; + echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":"'.time().'"}'; }else{ if(is_file($_GET['path'])){ //文件存在 if(in_array($_GET['path'],$active)){//判断是否为需要保持最新的文件 if(strstr($_GET['path'],'mojang/')!=False){//目录分组 if(strstr($_GET['path'],'mojang/launchermeta/')!=False){ - $dir='mojang/launchermeta/'; - check_file_update('mojang/launchermeta/mc/game/version_manifest.json',$dir,'http://launchermeta.mojang.com'); + check_file_update('mojang/launchermeta/mc/game/version_manifest.json',get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/','http://launchermeta.mojang.com',86400); } }elseif(strstr($_GET['path'],'forge/')!=False){//目录分组 if(strstr($_GET['path'],'forge/last')!=False){ check_file_update_adv('forge/last','https://download.mcbbs.net/forge/last','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar'); } } - }else{//无需更新的文件,直接重定向 - if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊返回目录 - echo @file_get_contents($_GET['path']); + }else{//无需频繁更新的文件 + if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){ + check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000); }else{ - header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']); + check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000); } } }elseif(is_dir($_GET['path'])){ //目录存在 if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊目录返回 check_file_update_adv('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar'); + }elseif(is_file($_GET['path'].'/index.json')){ + check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),86400); }else{ - header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']); + header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"'); + echo file_get_contents($_GET['path']); } }else{ //目录或文件不存在 - if(strstr($_GET['path'],'forge/')!=False){//特殊Forge,采用二级源 - if(url_exists_2('https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar')){ + if(strstr($_GET['path'],'forge/')!=False){//特殊Forge,采用二级源 BMCLAPI + if(url_exists('https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar')){ if(strstr($_GET['path'],'forge/minecraft')!=False){//forge/minecraft目录特殊同步 if($_GET['path']=='forge/minecraft'){ check_file_update_adv('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar'); @@ -132,21 +154,26 @@ if($_GET['error']!=""){ } }else{ download_file('https://download.mcbbs.net/'.$_GET['path'],$_GET['path'],''); - header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']); + header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"'); + echo file_get_contents($_GET['path']); } }else{ - echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.date("Y-m-d h:i:s").'"}'; + echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.time().'"}'; header('HTTP/1.1 404 Not Found'); } }else{ - if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾 - $id=0; - } if(url_exists(get_online_url($_GET['path'],$id))){ - download_file(get_online_url($_GET['path'],$id),$_GET['path'],''); - header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']); + if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){ + download_file(get_online_url($_GET['path'],$id),$_GET['path'],''); + header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"'); + echo file_get_contents($_GET['path']); + }else{ + download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.json',''); + header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"'); + echo file_get_contents($_GET['path'].'/index.json'); + } }else{ - echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.date("Y-m-d h:i:s").'"}'; + echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.time().'"}'; header('HTTP/1.1 404 Not Found'); } }