From aebbad964b17da46eac232bae6a44fda91b6855a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Apr 2023 05:15:38 -0600 Subject: [PATCH] Update MediaPathService, fix story path --- app/Services/HashidService.php | 9 +++++++-- app/Services/MediaPathService.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Services/HashidService.php b/app/Services/HashidService.php index aa1211af2..914d24321 100644 --- a/app/Services/HashidService.php +++ b/app/Services/HashidService.php @@ -9,11 +9,16 @@ class HashidService { public const MIN_LIMIT = 15; public const CMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; - public static function encode($id) + public static function encode($id, $minLimit = true) { - if(!is_numeric($id) || $id > PHP_INT_MAX || strlen($id) < self::MIN_LIMIT) { + if(!is_numeric($id) || $id > PHP_INT_MAX) { return null; } + + if($minLimit && strlen($id) < self::MIN_LIMIT) { + return null; + } + $key = "hashids:{$id}"; return Cache::remember($key, now()->hours(48), function() use($id) { $cmap = self::CMAP; diff --git a/app/Services/MediaPathService.php b/app/Services/MediaPathService.php index 09727f578..791b8998f 100644 --- a/app/Services/MediaPathService.php +++ b/app/Services/MediaPathService.php @@ -52,7 +52,7 @@ class MediaPathService { public static function story($account, $version = 1) { $mh = hash('sha256', date('Y').'-.-'.date('m')); - $monthHash = HashidService::encode(date('Y').date('m')); + $monthHash = HashidService::encode(date('Y').date('m'), false); $random = date('d').Str::random(32); if($account instanceOf User) {