feat(plugin): add subscribe.url hook

This commit is contained in:
xboard 2025-02-06 18:17:16 +08:00
parent 667e02460c
commit 7c0434d182
2 changed files with 10 additions and 5 deletions

View File

@ -45,9 +45,9 @@ class HookManager
* @param mixed ...$args 其他参数 * @param mixed ...$args 其他参数
* @return mixed * @return mixed
*/ */
public static function filter(string $hook, mixed $value, mixed ...$args): mixed public static function filter(string $hook, mixed $value): mixed
{ {
return Eventy::filter($hook, $value, ...$args); return Eventy::filter($hook, $value);
} }
/** /**

View File

@ -2,6 +2,9 @@
namespace App\Utils; namespace App\Utils;
use App\Services\Plugin\HookManager;
use Illuminate\Support\Arr;
class Helper class Helper
{ {
public static function uuidToBase64($uuid, $length) public static function uuidToBase64($uuid, $length)
@ -111,12 +114,14 @@ class Helper
public static function getSubscribeUrl(string $token, $subscribeUrl = null) public static function getSubscribeUrl(string $token, $subscribeUrl = null)
{ {
$path = route('client.subscribe', ['token' => $token], false); $path = route('client.subscribe', ['token' => $token], false);
if(!$subscribeUrl){ if (!$subscribeUrl) {
$subscribeUrls = explode(',', admin_setting('subscribe_url')); $subscribeUrls = explode(',', admin_setting('subscribe_url'));
$subscribeUrl = \Arr::random($subscribeUrls); $subscribeUrl = Arr::random($subscribeUrls);
$subscribeUrl = self::replaceByPattern($subscribeUrl); $subscribeUrl = self::replaceByPattern($subscribeUrl);
} }
return $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path);
$finalUrl = $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path);
return HookManager::filter('subscribe.url', [$finalUrl, $token]);
} }
public static function randomPort($range): int { public static function randomPort($range): int {