From b541edd96744a1d76823d1bbbc40d01ae7eb01ce Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 5 May 2024 19:43:10 -0400 Subject: [PATCH 01/18] add cloudflare web analytics --- .env.example | 1 + resources/views/disagree.blade.php | 3 +++ resources/views/home.blade.php | 4 +++- resources/views/shared/analytics.blade.php | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 resources/views/shared/analytics.blade.php diff --git a/.env.example b/.env.example index 201eb93..60f40c9 100644 --- a/.env.example +++ b/.env.example @@ -67,3 +67,4 @@ AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" +CLOUDFLARE_ANALYTICS_TOKEN= diff --git a/resources/views/disagree.blade.php b/resources/views/disagree.blade.php index 500b34c..59d91d6 100644 --- a/resources/views/disagree.blade.php +++ b/resources/views/disagree.blade.php @@ -54,5 +54,8 @@ + + @include("shared.analytics") + \ No newline at end of file diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 8ea3e89..c5de12b 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -13,7 +13,6 @@ @vite('resources/js/app.js') -
+ + @include("shared.analytics") + \ No newline at end of file diff --git a/resources/views/shared/analytics.blade.php b/resources/views/shared/analytics.blade.php new file mode 100644 index 0000000..790425f --- /dev/null +++ b/resources/views/shared/analytics.blade.php @@ -0,0 +1,4 @@ + +@if( !empty(env("CLOUDFLARE_ANALYTICS_TOKEN"))) + +@endif From 57a3eae826fce4642886dfa4b061cffc8019b900 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 5 May 2024 19:43:38 -0400 Subject: [PATCH 02/18] remove unused variables --- .env.example | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/.env.example b/.env.example index 60f40c9..9ed15e8 100644 --- a/.env.example +++ b/.env.example @@ -12,9 +12,7 @@ APP_FAKER_LOCALE=en_US APP_MAINTENANCE_DRIVER=file APP_MAINTENANCE_STORE=database -# compiler environment: nsjail, or local (default) COMPILER_ENVIRONMENT=nsjail -# compiler caching: true or false (default) COMPILER_CACHING=true BCRYPT_ROUNDS=12 @@ -25,11 +23,6 @@ LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug DB_CONNECTION=sqlite -# DB_HOST=127.0.0.1 -# DB_PORT=3306 -# DB_DATABASE=laravel -# DB_USERNAME=root -# DB_PASSWORD= SESSION_DRIVER=database SESSION_LIFETIME=120 @@ -44,22 +37,6 @@ QUEUE_CONNECTION=database CACHE_STORE=database CACHE_PREFIX= -MEMCACHED_HOST=127.0.0.1 - -REDIS_CLIENT=phpredis -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_MAILER=log -MAIL_HOST=127.0.0.1 -MAIL_PORT=2525 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS="hello@example.com" -MAIL_FROM_NAME="${APP_NAME}" - AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 From 61d1719a2d7c1bc790a4a51ed8b645eb3fea4f0a Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 5 May 2024 19:43:50 -0400 Subject: [PATCH 03/18] add patreon token to example env --- .env.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.example b/.env.example index 9ed15e8..4c3ab3e 100644 --- a/.env.example +++ b/.env.example @@ -44,4 +44,6 @@ AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" + +PATREON_ACCESS_TOKEN= CLOUDFLARE_ANALYTICS_TOKEN= From d11625469955faca15e9b888d23a4f25917100e9 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 5 May 2024 19:55:40 -0400 Subject: [PATCH 04/18] disclose analytics --- resources/js/lib/agreeDialog.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/js/lib/agreeDialog.js b/resources/js/lib/agreeDialog.js index 2007866..de245f4 100644 --- a/resources/js/lib/agreeDialog.js +++ b/resources/js/lib/agreeDialog.js @@ -41,7 +41,13 @@ export default function agreeDialog()
  • Share your code worldwide. This only applies if you use the "Share" functionality. -
  • + +
  • + To use + passive monitoring analytics for the purpose + of identifying problems with the app and improving + the overall experience. +
  • `; From 83775c6c523f355b127a586f8985c54b10bed8ae Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 5 May 2024 22:19:19 -0400 Subject: [PATCH 12/18] supporter dialog styles --- resources/css/dialog.scss | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/resources/css/dialog.scss b/resources/css/dialog.scss index e487139..c3eb543 100644 --- a/resources/css/dialog.scss +++ b/resources/css/dialog.scss @@ -129,6 +129,29 @@ content: "✔ Fixed: "; color: rgb(252, 252, 170); } + +.dialog.supporters h3 { + text-align: center; + font-size: 2rem; + // text-decoration: underline; + padding-bottom: 1rem; + border-bottom: 4px solid var(--dialog-text-color); +} + +.dialog.supporters .names { + display: flex; + width: 100%; + flex-direction: column; + justify-content: center; + // justify-items: center; + align-items: center; +} + +.dialog.supporters .names .name { + padding: .5rem 2rem; + font-size: 2.5rem; +} + .dialog.supporters a { display: block; text-align: center; From a18fc4af62044ece0c72571f2c9748de9963c214 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 5 May 2024 22:19:42 -0400 Subject: [PATCH 13/18] support empty list of subscribers --- resources/js/lib/supportersDialog.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/js/lib/supportersDialog.js b/resources/js/lib/supportersDialog.js index b860fd2..9a35887 100644 --- a/resources/js/lib/supportersDialog.js +++ b/resources/js/lib/supportersDialog.js @@ -24,9 +24,17 @@ export default function supportersDialog() let entries = []; - response.data.supporters.forEach((entry) => + if(response.data.supporters.length > 0) { - }); + response.data.supporters.forEach((entry) => + { + entries.push(`
    ◀ ${entry} ▶
    `); + }); + } + else + { + entries.push(`
    ◀ No Supporters Yet ▶
    `); + } supportersDialog.innerHTML = `
    From 55bc5c8d0c6d490d965904386ce16e993e9f5c5d Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Mon, 6 May 2024 09:06:02 -0400 Subject: [PATCH 14/18] console command to get names from patreon --- app/Console/Commands/Patreon.php | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 app/Console/Commands/Patreon.php diff --git a/app/Console/Commands/Patreon.php b/app/Console/Commands/Patreon.php new file mode 100644 index 0000000..487987c --- /dev/null +++ b/app/Console/Commands/Patreon.php @@ -0,0 +1,78 @@ +get("https://www.patreon.com/api/oauth2/v2/campaigns") + ->json()["data"][0]["id"]; + + $members = Http::withToken(env("PATREON_ACCESS_TOKEN")) + ->withQueryParameters([ + "include" => "currently_entitled_tiers", + "fields[member]" => "full_name,last_charge_date,last_charge_status,currently_entitled_amount_cents,patron_status", + // "fields[tier]" => "amount_cents", + ]) + ->get("https://www.patreon.com/api/oauth2/v2/campaigns/{$campaign}/members") + ->json(); + + $supporters = []; + if(count($members["data"]) > 0) + { + foreach($members["data"] as $member) + { + if($member["attributes"]["currently_entitled_amount_cents"] >= 500) + { + if(!empty($member["attributes"]["full_name"])) + { + $supporters[] = [ + "amount" => $member["attributes"]["currently_entitled_amount_cents"], + "name" => $member["attributes"]["full_name"], + ]; + } + } + } + } + + if($disk->exists("supporters.json")) + $disk->delete("supporters.json"); + + $disk->put("supporters.json", json_encode(["supporters" => $supporters])); + + } +} From d079f076c314970cd0118a4ddffd3b28b4b4fbd9 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Mon, 6 May 2024 10:32:42 -0400 Subject: [PATCH 15/18] move api into a controller --- .env.example | 2 + app/Http/Controllers/PatreonController.php | 101 +++++++++++++++++++++ routes/api.php | 5 + 3 files changed, 108 insertions(+) create mode 100644 app/Http/Controllers/PatreonController.php diff --git a/.env.example b/.env.example index 4c3ab3e..aed6c0f 100644 --- a/.env.example +++ b/.env.example @@ -46,4 +46,6 @@ AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" PATREON_ACCESS_TOKEN= +PATREON_WEBHOOK_SECRET= + CLOUDFLARE_ANALYTICS_TOKEN= diff --git a/app/Http/Controllers/PatreonController.php b/app/Http/Controllers/PatreonController.php new file mode 100644 index 0000000..34914fa --- /dev/null +++ b/app/Http/Controllers/PatreonController.php @@ -0,0 +1,101 @@ + 500, + "message" => "Missing Patreon Access Token or Webhook Secret.", + ], 500); + } + + $signature = hash_hmac("md5", $request->getContent(), env("PATREON_WEBHOOK_SECRET")); + if($request->header("X-Patreon-Signature") != $signature) + { + Log::alert("Unauthorized webhook request"); + return response([ + "statusCode" => 401, + "message" => "unauthorized" + ]); + } + + $this->getPatreonNames(); + + return []; + } + + function getPatreonNames() + { + $disk = (!empty(env("AWS_BUCKET"))) ? Storage::disk("s3") : Storage::disk("local"); + + Log::info("Getting Patreon Supporters"); + + $campaign = Http::withToken(env("PATREON_ACCESS_TOKEN")) + ->get("https://www.patreon.com/api/oauth2/v2/campaigns") + ->json()["data"][0]["id"]; + + $cursor = null; + $keepGoing = true; + + $supporters = []; + while($keepGoing) + { + $membersRequest = Http::withToken(env("PATREON_ACCESS_TOKEN")); + $membersRequest->withQueryParameters([ + "page[count]" => 25, + "include" => "currently_entitled_tiers", + "fields[member]" => "full_name,last_charge_date,last_charge_status,currently_entitled_amount_cents,patron_status", + ]); + if($cursor != null) + { + $membersRequest->withQueryParameters([ + "page[cursor]" => $cursor, + ]); + } + + $members = $membersRequest->get("https://www.patreon.com/api/oauth2/v2/campaigns/{$campaign}/members")->json(); + + if(count($members["data"]) > 0) + { + foreach($members["data"] as $member) + { + if($member["attributes"]["currently_entitled_amount_cents"] >= 500) + { + if(!empty($member["attributes"]["full_name"])) + { + $supporters[] = [ + "amount" => $member["attributes"]["currently_entitled_amount_cents"], + "name" => $member["attributes"]["full_name"], + ]; + } + } + } + } + + $cursor = $members["meta"]["pagination"]["cursors"]["next"]; + if(empty($cursor)) + { + $keepGoing = false; + } + } + + $disk->put("supporters.json", json_encode(["supporters" => $supporters])); + } +} + + diff --git a/routes/api.php b/routes/api.php index 5b7d774..e0ef33e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,7 +1,10 @@ Date: Mon, 6 May 2024 10:32:49 -0400 Subject: [PATCH 16/18] use controller function instead --- app/Console/Commands/Patreon.php | 42 +++----------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/app/Console/Commands/Patreon.php b/app/Console/Commands/Patreon.php index 487987c..6b2b6f1 100644 --- a/app/Console/Commands/Patreon.php +++ b/app/Console/Commands/Patreon.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Http\Controllers\PatreonController; use Illuminate\Console\Command; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -28,51 +29,14 @@ class MoveDatabase extends Command */ public function handle() { - $disk = (!empty(env("AWS_BUCKET"))) ? Storage::disk("s3") : Storage::disk("local"); - if(empty(env("PATREON_ACCESS_TOKEN"))) { Log::error("Error: missing Patreon Access Token... aborted."); return; } - Log::info("Updating Patreon Supporters"); - - $campaign = Http::withToken(env("PATREON_ACCESS_TOKEN")) - ->get("https://www.patreon.com/api/oauth2/v2/campaigns") - ->json()["data"][0]["id"]; - - $members = Http::withToken(env("PATREON_ACCESS_TOKEN")) - ->withQueryParameters([ - "include" => "currently_entitled_tiers", - "fields[member]" => "full_name,last_charge_date,last_charge_status,currently_entitled_amount_cents,patron_status", - // "fields[tier]" => "amount_cents", - ]) - ->get("https://www.patreon.com/api/oauth2/v2/campaigns/{$campaign}/members") - ->json(); - - $supporters = []; - if(count($members["data"]) > 0) - { - foreach($members["data"] as $member) - { - if($member["attributes"]["currently_entitled_amount_cents"] >= 500) - { - if(!empty($member["attributes"]["full_name"])) - { - $supporters[] = [ - "amount" => $member["attributes"]["currently_entitled_amount_cents"], - "name" => $member["attributes"]["full_name"], - ]; - } - } - } - } - - if($disk->exists("supporters.json")) - $disk->delete("supporters.json"); - - $disk->put("supporters.json", json_encode(["supporters" => $supporters])); + $controller = new PatreonController(); + $controller->getPatreonNames(); } } From 5b0aa00e8b6bb6c6eaf990d6858297bf78a917d0 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Mon, 6 May 2024 10:35:43 -0400 Subject: [PATCH 17/18] change class name of new console command --- app/Console/Commands/Patreon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/Patreon.php b/app/Console/Commands/Patreon.php index 6b2b6f1..d37699d 100644 --- a/app/Console/Commands/Patreon.php +++ b/app/Console/Commands/Patreon.php @@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; -class MoveDatabase extends Command +class Patreon extends Command { /** * The name and signature of the console command. From a2805bf2d3867adff467ef9919159401be446383 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Mon, 6 May 2024 10:36:11 -0400 Subject: [PATCH 18/18] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e3b0bc..95ed5d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. Each batch It is a summary of changes that would be pertinent to the end user of the PGEtinker website. For a comprehensive history of changes made to the project, please refer to the repository's commit history. -## unpublished +## 2024-05-06 - Added cloudflare analytics and disclosure - Added supporter wall