mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Update AP helpers, remove cache lock from profileUpdateOrCreate method
This commit is contained in:
parent
2c20d9e398
commit
bc2bbc14ac
1 changed files with 57 additions and 66 deletions
|
@ -720,16 +720,8 @@ class Helpers {
|
||||||
|
|
||||||
public static function profileUpdateOrCreate($url)
|
public static function profileUpdateOrCreate($url)
|
||||||
{
|
{
|
||||||
$hash = base64_encode($url);
|
|
||||||
$key = 'ap:profile:by_url:' . $hash;
|
|
||||||
$lock = Cache::lock($key, 30);
|
|
||||||
$profile = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$lock->block(5);
|
|
||||||
|
|
||||||
$res = self::fetchProfileFromUrl($url);
|
$res = self::fetchProfileFromUrl($url);
|
||||||
if(isset($res['id']) == false) {
|
if(!$res || isset($res['id']) == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$domain = parse_url($res['id'], PHP_URL_HOST);
|
$domain = parse_url($res['id'], PHP_URL_HOST);
|
||||||
|
@ -743,8 +735,12 @@ class Helpers {
|
||||||
$remoteUsername = $username;
|
$remoteUsername = $username;
|
||||||
$webfinger = "@{$username}@{$domain}";
|
$webfinger = "@{$username}@{$domain}";
|
||||||
|
|
||||||
abort_if(!self::validateUrl($res['inbox']), 400);
|
if(!self::validateUrl($res['inbox'])) {
|
||||||
abort_if(!self::validateUrl($res['id']), 400);
|
return;
|
||||||
|
}
|
||||||
|
if(!self::validateUrl($res['id'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$profile = DB::transaction(function() use($domain, $webfinger, $res) {
|
$profile = DB::transaction(function() use($domain, $webfinger, $res) {
|
||||||
$instance = Instance::updateOrCreate([
|
$instance = Instance::updateOrCreate([
|
||||||
|
@ -759,6 +755,8 @@ class Helpers {
|
||||||
'domain' => strtolower($domain),
|
'domain' => strtolower($domain),
|
||||||
'username' => Purify::clean($webfinger),
|
'username' => Purify::clean($webfinger),
|
||||||
'remote_url' => $res['id'],
|
'remote_url' => $res['id'],
|
||||||
|
'webfinger' => Purify::clean($webfinger),
|
||||||
|
'key_id' => $res['publicKey']['id'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => isset($res['name']) ? Purify::clean($res['name']) : 'user',
|
'name' => isset($res['name']) ? Purify::clean($res['name']) : 'user',
|
||||||
|
@ -767,8 +765,6 @@ class Helpers {
|
||||||
'inbox_url' => $res['inbox'],
|
'inbox_url' => $res['inbox'],
|
||||||
'outbox_url' => isset($res['outbox']) ? $res['outbox'] : null,
|
'outbox_url' => isset($res['outbox']) ? $res['outbox'] : null,
|
||||||
'public_key' => $res['publicKey']['publicKeyPem'],
|
'public_key' => $res['publicKey']['publicKeyPem'],
|
||||||
'key_id' => $res['publicKey']['id'],
|
|
||||||
'webfinger' => Purify::clean($webfinger),
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -783,12 +779,7 @@ class Helpers {
|
||||||
});
|
});
|
||||||
|
|
||||||
return $profile;
|
return $profile;
|
||||||
} catch (LockTimeoutException $e) {
|
|
||||||
} finally {
|
|
||||||
optional($lock)->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $profile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function profileFetch($url)
|
public static function profileFetch($url)
|
||||||
|
|
Loading…
Add table
Reference in a new issue