Skip to content

Commit

Permalink
added song hashes to API responses
Browse files Browse the repository at this point in the history
converted API search responses to API format
  • Loading branch information
Byorun committed Jul 11, 2018
1 parent 7c74cd3 commit f042ac2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
16 changes: 11 additions & 5 deletions app/SongComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
];
}
Expand Down Expand Up @@ -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,
];
}

Expand Down Expand Up @@ -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'],
];
}
}

0 comments on commit f042ac2

Please sign in to comment.