-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
398 changed files
with
9,813 additions
and
1,277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\ConvertArticleToSpeech; | ||
use App\Models\Article; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class GenerateAudioFileForArticle extends Command | ||
{ | ||
protected $signature = 'articles:generate-audio-file | ||
{id? : ID of the article} | ||
{--from= : ID of the starting article} | ||
{--to= : ID of the ending article} | ||
{--missing : Only query articles that have never had audio file generated} | ||
'; | ||
|
||
protected $description = 'Regenerate audio file for the article with the given ID'; | ||
|
||
public function handle(): int | ||
{ | ||
if (! ConvertArticleToSpeech::$enabled || ! (bool) config('dashbrd.text_to_speech.enabled')) { | ||
$this->warn('Article text-to-speech is currently disabled.'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
$articles = $this->articles() | ||
->isPublished() | ||
->when($this->option('missing'), static fn ($query) => $query->whereNull('audio_file_url')) | ||
->get(); | ||
|
||
if ($articles->isEmpty()) { | ||
$this->warn('No articles found.'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
$articles->each(static function ($article) { | ||
ConvertArticleToSpeech::dispatch($article); | ||
}); | ||
|
||
$this->info('Regenerating audio files for '.$articles->count().' articles.'); | ||
|
||
$chars = $articles->sum(static fn ($article) => strlen($article->content)); | ||
|
||
$this->info('Total number of characters sent to AWS: '.number_format($chars).' (could be less because this also includes markdown characters).'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
/** | ||
* @return Builder<Article> | ||
*/ | ||
private function articles(): Builder | ||
{ | ||
if ($this->argument('id') !== null) { | ||
return Article::where('id', $this->argument('id')); | ||
} | ||
|
||
return Article::query() | ||
->orderBy('id', 'asc') | ||
->limit(500) | ||
->when($this->option('from'), static fn ($query, $from) => $query->where('id', '>=', $from)) | ||
->when($this->option('to'), static fn ($query, $to) => $query->where('id', '<=', $to)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Article; | ||
use App\Support\Queues; | ||
use Illuminate\Console\Command; | ||
|
||
class UpdateArticlesViewCount extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'articles:update-view-count'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Updates view count of the articles'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
dispatch(static function () { | ||
Article::updateViewCounts(); | ||
})->onQueue(Queues::SCHEDULED_DEFAULT); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Contracts; | ||
|
||
use App\Enums\TextToSpeechConversionStatus; | ||
use App\Models\Article; | ||
|
||
interface TextToSpeechProvider | ||
{ | ||
public function convert(Article $article): string; | ||
|
||
public function status(string $conversionId): TextToSpeechConversionStatus; | ||
|
||
public function url(string $conversionId): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.