Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions app/Http/Controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
{
Expand Down
8 changes: 7 additions & 1 deletion app/Services/RenderedScoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down