From 657cb2d7c4944ab4db33cbd363763424335b1d6a Mon Sep 17 00:00:00 2001 From: Mira Date: Sat, 1 Mar 2025 20:06:59 +0100 Subject: [PATCH 1/4] wat.. don't create zip of svgs hourly --- app/Console/Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 27e9ddd5..74e8a0b2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -35,7 +35,7 @@ protected function schedule(Schedule $schedule) $scores_zip = Storage::path(config('lilypond.rendered_scores_zip')); // create a zip of rendered svg scores - $schedule->exec("cd $scores_dir && find -name \"*.svg\" -printf '%f\n' | tar -zcf $scores_zip -T -")->hourly(); + // $schedule->exec("cd $scores_dir && find -name \"*.svg\" -printf '%f\n' | tar -zcf $scores_zip -T -")->hourly(); // update elastic data // todo: make elastic update automatically after data edit From 8e7608ad45eb5323e50c53684afd9609c921cfa6 Mon Sep 17 00:00:00 2001 From: Mira Date: Sat, 1 Mar 2025 20:54:01 +0100 Subject: [PATCH 2/4] automatic gzipping of rendered scores --- app/Services/RenderedScoreService.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Services/RenderedScoreService.php b/app/Services/RenderedScoreService.php index 5cd68b12..d34e8ce3 100644 --- a/app/Services/RenderedScoreService.php +++ b/app/Services/RenderedScoreService.php @@ -29,7 +29,13 @@ public function makeFile($contents, string $extension, ?string $filename = null) $filename = isset($filename) ? $filename : uniqid(); - $res = Storage::put($this->dir . "/$filename.$extension", $contents); + $filename_full = "/$filename.$extension"; + + $res = Storage::put($this->dir . $filename_full, $contents); + + logger("Gzipping file $filename_full"); + shell_exec("gzip $path/$filename_full"); + if (!$res) { throw new Exception("Storing of the rendered file $filename.$extension was not successful"); } From 75a85b7ff5aca666ba471cc97276332d04790fbe Mon Sep 17 00:00:00 2001 From: Mira Date: Sat, 1 Mar 2025 20:59:28 +0100 Subject: [PATCH 3/4] TODO --- app/Http/Controllers/DownloadController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Controllers/DownloadController.php b/app/Http/Controllers/DownloadController.php index acec2659..eb8dbf20 100644 --- a/app/Http/Controllers/DownloadController.php +++ b/app/Http/Controllers/DownloadController.php @@ -7,6 +7,7 @@ use App\External; use App\Services\LilypondPartsService; use App\Services\LilypondClientService; +use ZipStream; class DownloadController extends Controller { @@ -32,6 +33,10 @@ public function downloadFile(Request $request, $filename) return response()->file($path); } + + public function downloadLilyponds(Request $request) { + // TODO: use zipstream to create a zip with files of sheet music updated after some date + } public function proxyExternal(External $external) { From c2cd0002cde74ff5a0d1551e9e613af969b7b9eb Mon Sep 17 00:00:00 2001 From: Mira Date: Sun, 2 Mar 2025 07:40:24 +0100 Subject: [PATCH 4/4] add donwload svgs route --- app/Http/Controllers/DownloadController.php | 34 +++++++++++++++++++-- routes/web.php | 2 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DownloadController.php b/app/Http/Controllers/DownloadController.php index eb8dbf20..1674d6c7 100644 --- a/app/Http/Controllers/DownloadController.php +++ b/app/Http/Controllers/DownloadController.php @@ -7,7 +7,10 @@ use App\External; use App\Services\LilypondPartsService; use App\Services\LilypondClientService; -use ZipStream; +use Illuminate\Support\Facades\DB; +use App\SongLyric; +use ZipStream\ZipStream; +use Symfony\Component\HttpFoundation\StreamedResponse; class DownloadController extends Controller { @@ -35,7 +38,34 @@ public function downloadFile(Request $request, $filename) } public function downloadLilyponds(Request $request) { - // TODO: use zipstream to create a zip with files of sheet music updated after some date + $updated_after = $request->get('updated_after'); + + $result = DB::table('song_lyrics') + ->select('song_lyrics.id', 'rendered_scores.filename') + ->join('lilypond_parts_sheet_music', 'song_lyrics.id', '=', 'lilypond_parts_sheet_music.song_lyric_id') + ->join('rendered_scores', 'lilypond_parts_sheet_music.id', '=', 'rendered_scores.lilypond_parts_sheet_music_id') + ->where('song_lyrics.updated_at', '>', $updated_after) + ->where('rendered_scores.filetype', 'svg') + ->where('render_config_hash', '491ed726') // {"hide_voices": ["muzi", "tenor", "bas", "zeny", "sopran", "alt"]} + ->get(); + + $response = new StreamedResponse(function () use ($result) { + $zip = new ZipStream( + outputName: 'svgs.zip', + sendHttpHeaders: true, + ); + + foreach ($result as $row) { + $zip->addFileFromPath( + fileName: "$row->id.svg.gz", // name the files according to the song lyric IDs + path: Storage::path("rendered_scores/$row->filename.svg.gz"), + ); + } + + $zip->finish(); + }); + + return $response; } public function proxyExternal(External $external) diff --git a/routes/web.php b/routes/web.php index 39e7a2e5..4907ad41 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,6 +29,8 @@ Route::get('/soubor/{filename}', 'DownloadController@downloadFile')->name('file.download')->where('filename', '.*'); Route::get('/material/{external}', 'DownloadController@proxyExternal')->name('external.proxy'); +Route::get('/download-svgs', 'DownloadController@downloadLilyponds')->name('download.lilyponds'); + Route::group(['prefix' => 'admin', 'as' => 'admin.', 'middleware' => 'auth'], function () {