Update ap helpers

This commit is contained in:
Daniel Supernault 2021-04-20 22:29:52 -06:00
parent 7066e19d0e
commit e73b2f8373
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 17 additions and 5 deletions

View File

@ -6,6 +6,7 @@ use DB, Cache, Purify, Storage, Request, Validator;
use App\{
Activity,
Follower,
Instance,
Like,
Media,
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)) {
return false;
}
@ -472,21 +481,24 @@ class Helpers {
$profile = Profile::whereRemoteUrl($res['id'])->first();
if(!$profile) {
Instance::firstOrCreate([
'domain' => $domain
]);
$profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']);
$profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) {
return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
$profile = new Profile();
$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->bio = isset($res['summary']) ? Purify::clean($res['summary']) : 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->key_id = $res['publicKey']['id'];
$profile->webfinger = strtolower(Purify::clean($webfinger));
$profile->webfinger = Purify::clean($webfinger);
$profile->last_fetched_at = now();
$profile->save();
if(config('pixelfed.cloud_storage') == true) {