Upgrade to Laravel 13
This commit is contained in:
parent
e8e2bff5e4
commit
9f012b01e4
117 changed files with 1878 additions and 2215 deletions
|
|
@ -39,9 +39,9 @@ class DownloadWebMention implements ShouldQueue
|
|||
// Laravel should catch and retry these automatically.
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$filesystem = new FileSystem;
|
||||
$filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source);
|
||||
$filename = storage_path('HTML').'/'.$this->createFilenameFromURL($this->source);
|
||||
// backup file first
|
||||
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
|
||||
$filenameBackup = $filename.'.'.date('Y-m-d').'.backup';
|
||||
if ($filesystem->exists($filename)) {
|
||||
$filesystem->copy($filename, $filenameBackup);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ declare(strict_types=1);
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Like;
|
||||
use Codebird\Codebird;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -39,35 +37,6 @@ class ProcessLike implements ShouldQueue
|
|||
*/
|
||||
public function handle(Client $client, Authorship $authorship): int
|
||||
{
|
||||
if ($this->isTweet($this->like->url)) {
|
||||
$codebird = resolve(Codebird::class);
|
||||
|
||||
$tweet = $codebird->statuses_oembed(['url' => $this->like->url]);
|
||||
|
||||
$this->like->author_name = $tweet->author_name;
|
||||
$this->like->author_url = $tweet->author_url;
|
||||
$this->like->content = $tweet->html;
|
||||
$this->like->save();
|
||||
|
||||
// POSSE like
|
||||
try {
|
||||
$client->request(
|
||||
'POST',
|
||||
'https://brid.gy/publish/webmention',
|
||||
[
|
||||
'form_params' => [
|
||||
'source' => $this->like->url,
|
||||
'target' => 'https://brid.gy/publish/twitter',
|
||||
],
|
||||
]
|
||||
);
|
||||
} catch (RequestException) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$response = $client->request('GET', $this->like->url);
|
||||
$mf2 = \Mf2\parse((string) $response->getBody(), $this->like->url);
|
||||
if (Arr::has($mf2, 'items.0.properties.content')) {
|
||||
|
|
@ -91,15 +60,4 @@ class ProcessLike implements ShouldQueue
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given URL is that of a Tweet.
|
||||
*/
|
||||
private function isTweet(string $url): bool
|
||||
{
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
$parts = array_reverse(explode('.', $host));
|
||||
|
||||
return $parts[0] === 'com' && $parts[1] === 'twitter';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@ class ProcessMedia implements ShouldQueue
|
|||
$basename = trim(implode('.', $filenameParts), '.');
|
||||
|
||||
$medium = $image->resize(width: 1000);
|
||||
Storage::disk('public')->put($basename . '-medium.' . $extension, (string) $medium->encode());
|
||||
Storage::disk('public')->put($basename.'-medium.'.$extension, (string) $medium->encode());
|
||||
|
||||
$small = $image->resize(width: 500);
|
||||
Storage::disk('public')->put($basename . '-small.' . $extension, (string) $small->encode());
|
||||
Storage::disk('public')->put($basename.'-small.'.$extension, (string) $small->encode());
|
||||
}
|
||||
|
||||
// Now we can delete the locally saved image
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class ProcessWebMention implements ShouldQueue
|
|||
if (str_ends_with($url, '/')) {
|
||||
$filenameFromURL .= 'index.html';
|
||||
}
|
||||
$path = storage_path() . '/HTML/' . $filenameFromURL;
|
||||
$path = storage_path().'/HTML/'.$filenameFromURL;
|
||||
$parts = explode('/', $path);
|
||||
$name = array_pop($parts);
|
||||
$dir = implode('/', $parts);
|
||||
|
|
|
|||
|
|
@ -62,13 +62,13 @@ class SaveProfileImage implements ShouldQueue
|
|||
$image = $response->getBody();
|
||||
} catch (RequestException) {
|
||||
// we are opening and reading the default image so that
|
||||
$default = public_path() . '/assets/profile-images/default-image';
|
||||
$default = public_path().'/assets/profile-images/default-image';
|
||||
$handle = fopen($default, 'rb');
|
||||
$image = fread($handle, filesize($default));
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
$path = public_path() . '/assets/profile-images/' . parse_url($home, PHP_URL_HOST) . '/image';
|
||||
$path = public_path().'/assets/profile-images/'.parse_url($home, PHP_URL_HOST).'/image';
|
||||
$parts = explode('/', $path);
|
||||
$name = array_pop($parts);
|
||||
$dir = implode('/', $parts);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class SaveScreenshot implements ShouldQueue
|
|||
// First request that CloudConvert takes a screenshot of the URL
|
||||
$takeScreenshotJobResponse = $client->request('POST', 'https://api.cloudconvert.com/v2/capture-website', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('services.cloudconvert.token'),
|
||||
'Authorization' => 'Bearer '.config('services.cloudconvert.token'),
|
||||
],
|
||||
'json' => [
|
||||
'url' => $this->bookmark->url,
|
||||
|
|
@ -56,9 +56,9 @@ class SaveScreenshot implements ShouldQueue
|
|||
$taskId = json_decode($takeScreenshotJobResponse->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->data->id;
|
||||
|
||||
// Now wait till the status job is finished
|
||||
$screenshotJobStatusResponse = $retryClient->request('GET', 'https://api.cloudconvert.com/v2/tasks/' . $taskId, [
|
||||
$screenshotJobStatusResponse = $retryClient->request('GET', 'https://api.cloudconvert.com/v2/tasks/'.$taskId, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('services.cloudconvert.token'),
|
||||
'Authorization' => 'Bearer '.config('services.cloudconvert.token'),
|
||||
],
|
||||
'query' => [
|
||||
'include' => 'payload',
|
||||
|
|
@ -70,7 +70,7 @@ class SaveScreenshot implements ShouldQueue
|
|||
// Now we can create a new job to request thst the screenshot is exported to a temporary URL we can download the screenshot from
|
||||
$exportImageJob = $client->request('POST', 'https://api.cloudconvert.com/v2/export/url', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('services.cloudconvert.token'),
|
||||
'Authorization' => 'Bearer '.config('services.cloudconvert.token'),
|
||||
],
|
||||
'json' => [
|
||||
'input' => $finishedCaptureId,
|
||||
|
|
@ -81,9 +81,9 @@ class SaveScreenshot implements ShouldQueue
|
|||
$exportImageJobId = json_decode($exportImageJob->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->data->id;
|
||||
|
||||
// Again, wait till the status of this export job is finished
|
||||
$finalImageUrlResponse = $retryClient->request('GET', 'https://api.cloudconvert.com/v2/tasks/' . $exportImageJobId, [
|
||||
$finalImageUrlResponse = $retryClient->request('GET', 'https://api.cloudconvert.com/v2/tasks/'.$exportImageJobId, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('services.cloudconvert.token'),
|
||||
'Authorization' => 'Bearer '.config('services.cloudconvert.token'),
|
||||
],
|
||||
'query' => [
|
||||
'include' => 'payload',
|
||||
|
|
@ -95,7 +95,7 @@ class SaveScreenshot implements ShouldQueue
|
|||
|
||||
$finalImageUrlContent = $client->request('GET', $finalImageUrl);
|
||||
|
||||
Storage::disk('public')->put('/assets/img/bookmarks/' . $taskId . '.png', $finalImageUrlContent->getBody()->getContents());
|
||||
Storage::disk('public')->put('/assets/img/bookmarks/'.$taskId.'.png', $finalImageUrlContent->getBody()->getContents());
|
||||
|
||||
$this->bookmark->screenshot = $taskId;
|
||||
$this->bookmark->save();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Str;
|
||||
use Mf2\Parser;
|
||||
|
||||
class SendWebMentions implements ShouldQueue
|
||||
{
|
||||
|
|
@ -83,7 +84,11 @@ class SendWebMentions implements ShouldQueue
|
|||
// failed to find a header so parse HTML
|
||||
$html = (string) $response->getBody();
|
||||
|
||||
$mf2 = new \Mf2\Parser($html, $url);
|
||||
if ($html === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$mf2 = new Parser($html, $url);
|
||||
$rels = $mf2->parseRelsAndAlternates();
|
||||
if (array_key_exists('webmention', $rels[0])) {
|
||||
$endpoint = $rels[0]['webmention'][0];
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SyndicateNoteToBluesky implements ShouldQueue
|
|||
'https://brid.gy/micropub',
|
||||
[
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('bridgy.bluesky_token'),
|
||||
'Authorization' => 'Bearer '.config('bridgy.bluesky_token'),
|
||||
],
|
||||
'json' => [
|
||||
'type' => ['h-entry'],
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SyndicateNoteToMastodon implements ShouldQueue
|
|||
'https://brid.gy/micropub',
|
||||
[
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('bridgy.mastodon_token'),
|
||||
'Authorization' => 'Bearer '.config('bridgy.mastodon_token'),
|
||||
],
|
||||
'json' => [
|
||||
'type' => ['h-entry'],
|
||||
|
|
|
|||
Loading…
Reference in a new issue