Skip to content

Commit 4c8f828

Browse files
committed
Fixed GitHub API rate limit
For Theme Updater
1 parent 1c6f9d1 commit 4c8f828

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

app/Http/Controllers/AdminController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,19 @@ public function updateThemes()
390390
preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE);
391391
$sourceURL = substr($matches[0][0],13);
392392

393-
$replaced = str_replace("https://github.com/", "https://api.github.com/repos/", trim($sourceURL));
394-
$replaced = $replaced . "/releases/latest";
393+
$replaced = str_replace("https://github.com/", "https://raw.githubusercontent.com/", trim($sourceURL));
394+
$replaced = $replaced . "/main/readme.md";
395395

396396
if (strpos($sourceURL, 'github.com')){
397397

398398
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)');
399399
try{
400-
$jsont = file_get_contents($replaced);
401-
$myObjt = json_decode($jsont);
402-
$Vgitt = $myObjt->tag_name;
403-
$verNrv = 'v' . $verNr;
400+
$textGit = file_get_contents($replaced);
401+
$patternGit = '/Theme Version:.*/';
402+
preg_match($patternGit, $textGit, $matches, PREG_OFFSET_CAPTURE);
403+
$sourceURLGit = substr($matches[0][0],15);
404+
$Vgitt = 'v' . $sourceURLGit;
405+
$verNrv = 'v' . $verNr;
404406
}catch(Exception $ex){
405407
$themeVe = "error";
406408
$Vgitt = NULL;
@@ -410,7 +412,7 @@ public function updateThemes()
410412
if(trim($Vgitt) > trim($verNrv)){
411413

412414

413-
$fileUrl = trim($sourceURL) . '/archive/refs/tags/' . trim($verNrv) . '.zip';
415+
$fileUrl = trim($sourceURL) . '/archive/refs/tags/' . trim($Vgitt) . '.zip';
414416

415417

416418
file_put_contents(base_path('themes/theme.zip'), fopen($fileUrl, 'r'));

resources/views/studio/theme.blade.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,18 @@
156156
preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE);
157157
$sourceURL = substr($matches[0][0],13);
158158
159-
$replaced = str_replace("https://github.com/", "https://api.github.com/repos/", trim($sourceURL));
160-
$replaced = $replaced . "/releases/latest";
159+
$replaced = str_replace("https://github.com/", "https://raw.githubusercontent.com/", trim($sourceURL));
160+
$replaced = $replaced . "/main/readme.md";
161161
162162
if (strpos($sourceURL, 'github.com')){
163163
164164
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)');
165165
try{
166-
$jsont = file_get_contents($replaced);
167-
$myObjt = json_decode($jsont);
168-
$Vgitt = $myObjt->tag_name;
166+
$textGit = file_get_contents($replaced);
167+
$patternGit = '/Theme Version:.*/';
168+
preg_match($patternGit, $textGit, $matches, PREG_OFFSET_CAPTURE);
169+
$sourceURLGit = substr($matches[0][0],15);
170+
$Vgitt = 'v' . $sourceURLGit;
169171
$verNrv = 'v' . $verNr;
170172
}catch(Exception $ex){
171173
$themeVe = "error";

0 commit comments

Comments
 (0)