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 diff --git a/app/Http/Controllers/DownloadController.php b/app/Http/Controllers/DownloadController.php index acec2659..1674d6c7 100644 --- a/app/Http/Controllers/DownloadController.php +++ b/app/Http/Controllers/DownloadController.php @@ -7,6 +7,10 @@ use App\External; use App\Services\LilypondPartsService; use App\Services\LilypondClientService; +use Illuminate\Support\Facades\DB; +use App\SongLyric; +use ZipStream\ZipStream; +use Symfony\Component\HttpFoundation\StreamedResponse; class DownloadController extends Controller { @@ -32,6 +36,37 @@ public function downloadFile(Request $request, $filename) return response()->file($path); } + + public function downloadLilyponds(Request $request) { + $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/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"); } 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 () {