Ver código fonte

Update ap helpers

Daniel Supernault 4 anos atrás
pai
commit
e73b2f8373
1 arquivos alterados com 17 adições e 5 exclusões
  1. 17 5
      app/Util/ActivityPub/Helpers.php

+ 17 - 5
app/Util/ActivityPub/Helpers.php

@@ -6,6 +6,7 @@ use DB, Cache, Purify, Storage, Request, Validator;
 use App\{
 use App\{
 	Activity,
 	Activity,
 	Follower,
 	Follower,
+	Instance,
 	Like,
 	Like,
 	Media,
 	Media,
 	Notification,
 	Notification,
@@ -174,6 +175,14 @@ class Helpers {
 				}
 				}
 			}
 			}
 
 
+			$bannedInstances = Cache::remember('instances:banned:domains', now()->addHours(12), function() {
+				return Instance::whereBanned(true)->pluck('domain')->toArray();
+			});
+
+			if(in_array($host, $bannedInstances)) {
+				return false;
+			}
+
 			if(in_array($host, $localhosts)) {
 			if(in_array($host, $localhosts)) {
 				return false;
 				return false;
 			}
 			}
@@ -472,21 +481,24 @@ class Helpers {
 
 
 			$profile = Profile::whereRemoteUrl($res['id'])->first();
 			$profile = Profile::whereRemoteUrl($res['id'])->first();
 			if(!$profile) {
 			if(!$profile) {
+				Instance::firstOrCreate([
+					'domain' => $domain
+				]);
 				$profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']);
 				$profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']);
 				$profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) {
 				$profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) {
 					return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
 					return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
 						$profile = new Profile();
 						$profile = new Profile();
 						$profile->domain = strtolower($domain);
 						$profile->domain = strtolower($domain);
-						$profile->username = strtolower(Purify::clean($webfinger));
+						$profile->username = Purify::clean($webfinger);
 						$profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user';
 						$profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user';
 						$profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null;
 						$profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null;
 						$profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null;
 						$profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null;
-						$profile->inbox_url = strtolower($res['inbox']);
-						$profile->outbox_url = strtolower($res['outbox']);
-						$profile->remote_url = strtolower($res['id']);
+						$profile->inbox_url = $res['inbox'];
+						$profile->outbox_url = $res['outbox'];
+						$profile->remote_url = $res['id'];
 						$profile->public_key = $res['publicKey']['publicKeyPem'];
 						$profile->public_key = $res['publicKey']['publicKeyPem'];
 						$profile->key_id = $res['publicKey']['id'];
 						$profile->key_id = $res['publicKey']['id'];
-						$profile->webfinger = strtolower(Purify::clean($webfinger));
+						$profile->webfinger = Purify::clean($webfinger);
 						$profile->last_fetched_at = now();
 						$profile->last_fetched_at = now();
 						$profile->save();
 						$profile->save();
 						if(config('pixelfed.cloud_storage') == true) {
 						if(config('pixelfed.cloud_storage') == true) {