Skip to content

Commit

Permalink
Merge pull request #68 from Moros1138/fix-patreon
Browse files Browse the repository at this point in the history
Fix patreon
  • Loading branch information
Moros1138 authored May 18, 2024
2 parents adea50b + 8a1e506 commit ab1a71b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ It is a summary of changes that would be pertinent to the end user of the PGEtin

- Added support to deploy on subpaths
- Added updated version of PGE, Extensions, and Utlities
- Fixed patreon supporters not updated after PGEtinker upgrades

## 2024-05-14

Expand Down
27 changes: 26 additions & 1 deletion app/Http/Controllers/PatreonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ function update(Request $request)
return [];
}

function get_supporters(Request $request)
{
if(empty(env("PATREON_ACCESS_TOKEN")) || empty(env("PATREON_WEBHOOK_SECRET")))
{
return response([
"statusCode" => 500,
"message" => "Missing Patreon Access Token or Webhook Secret.",
"supporters" => [],
], 500);
}

$supporters = Redis::get("supporters");

if(isset($supporters))
{
$supporters = json_decode($supporters);
return $supporters;
}

return $this->getPatreonNames();
}

function getPatreonNames()
{
Log::info("Getting Patreon Supporters");
Expand Down Expand Up @@ -91,7 +113,10 @@ function getPatreonNames()
}
}

Redis::set("supporters", json_encode(["supporters" => $supporters], JSON_PRETTY_PRINT));
$supporters = ["supporters" => $supporters];
Redis::set("supporters", json_encode($supporters, JSON_PRETTY_PRINT));

return $supporters;
}
}

Expand Down
86 changes: 46 additions & 40 deletions resources/js/lib/supportersDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,62 @@ export default function supportersDialog()
supportersDialog.dispatchEvent(new Event("close-dialog"));
}

return new Promise((resolve) =>
function renderSupportersDialog(supporters)
{
let supportersDialog = document.createElement("div");

supportersDialog.classList.toggle("dialog", true);
supportersDialog.classList.toggle("supporters", true);

axios.get("/api/supporters").then((response) =>
{

let entries = [];

let entries = [];
if(supporters.length > 0)
{
// sort biggest first
supporters.sort((a, b) => b.amount - a.amount);

if(response.data.supporters.length > 0)
{
// sort biggest first
response.data.supporters.sort((a, b) => b.amount - a.amount);

response.data.supporters.forEach((entry) =>
{
entries.push(`<div class="name">◀ ${entry.name} ▶</div>`);
});
}
else
supporters.forEach((entry) =>
{
entries.push(`<div class="name">◀ No Supporters Yet ▶</div>`);
}

supportersDialog.innerHTML = `
<div class="window">
<div class="header">Patreon Supporters!</div>
<div class="content">
<h3>PGEtinker would not exist without the support of:</h3>
<div class="names">
${entries.join('')}
</div>
<a target="_blank" href="https://patreon.com/PGEtinker">
Become a Supporter
</a>
entries.push(`<div class="name">◀ ${entry.name} ▶</div>`);
});
}
else
{
entries.push(`<div class="name">◀ No Supporters Yet ▶</div>`);
}

supportersDialog.innerHTML = `
<div class="window">
<div class="header">Patreon Supporters!</div>
<div class="content">
<h3>PGEtinker would not exist without the support of:</h3>
<div class="names">
${entries.join('')}
</div>
</div>`;
<a target="_blank" href="https://patreon.com/PGEtinker">
Become a Supporter
</a>
</div>
</div>`;

supportersDialog.addEventListener("close-dialog", (event) =>
{
setTimeout(() => window.removeEventListener("click", supportersClickAnywhereHandler), 500);
supportersDialog.remove();
resolve();
});

setTimeout(() => window.addEventListener("click", supportersClickAnywhereHandler), 500);
document.body.appendChild(supportersDialog);
supportersDialog.addEventListener("close-dialog", (event) =>
{
setTimeout(() => window.removeEventListener("click", supportersClickAnywhereHandler), 500);
supportersDialog.remove();
});

setTimeout(() => window.addEventListener("click", supportersClickAnywhereHandler), 500);
document.body.appendChild(supportersDialog);
}

return new Promise(() =>
{
axios.get("/api/supporters").then((response) =>
{
renderSupportersDialog(response.data.supporters);
}).catch((reason) =>
{
renderSupportersDialog(reason.response.data.supporters);
});

});
Expand Down
18 changes: 1 addition & 17 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
use App\Http\Controllers\CodeController;
use App\Http\Controllers\PatreonController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;

Route::post("/share", [CodeController::class, "Share" ]);
Route::post("/compile", [CodeController::class, "Compile" ]);
Expand Down Expand Up @@ -84,17 +80,5 @@
return $changeLog;
});

Route::get("/supporters", function(Request $request)
{
$supporters = Redis::get("supporters");

if(isset($supporters))
{
$supporters = json_decode($supporters);
return $supporters;
}

return ["supporters" => []];
});

Route::get("/supporters", [PatreonController::class, "get_supporters" ]);
Route::post("/update-supporters", [PatreonController::class, "update" ]);

0 comments on commit ab1a71b

Please sign in to comment.