From f042ac21060006e9d0bdbf517b0fa267e0e1a0a8 Mon Sep 17 00:00:00 2001 From: Byorun Date: Wed, 11 Jul 2018 21:46:09 +0200 Subject: [PATCH] added song hashes to API responses converted API search responses to API format --- app/Http/Controllers/ApiController.php | 2 +- app/SongComposer.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 0f0a3b4..88f1dab 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -125,7 +125,7 @@ public function search(string $type, string $key, SongListComposer $composer) } $parameter = [strtolower($type) => $key]; - $songs = $composer->search($parameter); + $songs = $composer->search($parameter, 0, SongListComposer::DEFAULT_LIMIT, true); $total = count($songs); return Response::json(['songs' => $songs, 'total' => $total]); } diff --git a/app/SongComposer.php b/app/SongComposer.php index e30aa2a..3038576 100644 --- a/app/SongComposer.php +++ b/app/SongComposer.php @@ -194,11 +194,13 @@ public function createOrUpdate(array $metadata, string $file): array 'upVotesTotal' => 0, 'downVotes' => 0, 'downVotesTotal' => 0, - 'version' => $song->details->count(), //@todo fix version if $detailId is specified - 'createdAt' => $songDetails->created_at, - 'linkUrl' => route('browse.detail', ['key' => $song->id . '-' . $songDetails->id]), - 'downloadUrl' => route('download', ['key' => $song->id . '-' . $songDetails->id]), - 'coverUrl' => asset("storage/songs/{$song->id}/{$song->id}-{$songDetails->id}.$songDetails->cover"), + 'version' => $song->details->count(), //@todo fix version if $detailId is specified + 'createdAt' => $songDetails->created_at, + 'linkUrl' => route('browse.detail', ['key' => $song->id . '-' . $songDetails->id]), + 'downloadUrl' => route('download', ['key' => $song->id . '-' . $songDetails->id]), + 'coverUrl' => asset("storage/songs/{$song->id}/{$song->id}-{$songDetails->id}.$songDetails->cover"), + 'hashMd5' => $songDetails->hash_md5, + 'hashSha1' => $songDetails->hash_sha1, ] ]; } @@ -391,6 +393,8 @@ protected function compose(string $key): array 'linkUrl' => route('browse.detail', ['key' => $song->id . '-' . $detail->id]), 'downloadUrl' => route('download', ['key' => $song->id . '-' . $detail->id]), 'coverUrl' => asset("storage/songs/{$song->id}/{$song->id}-{$detail->id}.$detail->cover"), + 'hashMd5' => $detail->hash_md5, + 'hashSha1' => $detail->hash_sha1, ]; } @@ -476,6 +480,8 @@ protected function convertSongToApiFormat(array $song): array 'linkUrl' => $song['version'][$song['key']]['linkUrl'], 'downloadUrl' => $song['version'][$song['key']]['downloadUrl'], 'coverUrl' => $song['version'][$song['key']]['coverUrl'], + 'hashMd5' => $song['version'][$song['key']]['hashMd5'], + 'hashSha1' => $song['version'][$song['key']]['hashSha1'], ]; } } \ No newline at end of file