mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 22:47:59 +01:00
Added the ability to the API to include cover art with a track upload.
This commit is contained in:
parent
93b76d1954
commit
454411b24b
4 changed files with 31 additions and 7 deletions
|
@ -25,8 +25,8 @@ use Poniverse\Ponyfm\Image;
|
|||
use Poniverse\Ponyfm\Track;
|
||||
use Poniverse\Ponyfm\TrackType;
|
||||
use Poniverse\Ponyfm\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Auth;
|
||||
use DB;
|
||||
|
||||
class EditTrackCommand extends CommandBase
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ use Input;
|
|||
use Poniverse\Ponyfm\Album;
|
||||
use Poniverse\Ponyfm\Exceptions\InvalidEncodeOptionsException;
|
||||
use Poniverse\Ponyfm\Genre;
|
||||
use Poniverse\Ponyfm\Image;
|
||||
use Poniverse\Ponyfm\Jobs\EncodeTrackFile;
|
||||
use Poniverse\Ponyfm\Track;
|
||||
use Poniverse\Ponyfm\TrackFile;
|
||||
|
@ -149,6 +150,7 @@ class UploadTrackCommand extends CommandBase
|
|||
'is_explicit' => 'boolean',
|
||||
'is_downloadable' => 'boolean',
|
||||
'is_listed' => 'boolean',
|
||||
'cover' => 'image|mimes:png,jpeg|min_width:350|min_height:350',
|
||||
'metadata' => 'json',
|
||||
]);
|
||||
|
||||
|
@ -176,6 +178,10 @@ class UploadTrackCommand extends CommandBase
|
|||
|
||||
$track->source = $this->_customTrackSource ?? 'direct_upload';
|
||||
|
||||
if (Input::hasFile('cover')) {
|
||||
$track->cover_id = Image::upload(Input::file('cover'), $track->user_id)->id;
|
||||
}
|
||||
|
||||
// If json_decode() isn't called here, Laravel will surround the JSON
|
||||
// string with quotes when storing it in the database, which breaks things.
|
||||
$track->metadata = json_decode(Input::get('metadata', null));
|
||||
|
|
|
@ -84,6 +84,8 @@ class ApiTest extends TestCase {
|
|||
'is_downloadable' => false,
|
||||
'is_listed' => false,
|
||||
'metadata' => $track->metadata
|
||||
], [
|
||||
'cover' => $this->getTestFileForUpload('ponyfm-transparent-cover-art.png')
|
||||
]);
|
||||
|
||||
$this->seeInDatabase('genres', [
|
||||
|
@ -94,8 +96,14 @@ class ApiTest extends TestCase {
|
|||
'title' => $track->album
|
||||
]);
|
||||
|
||||
$this->seeInDatabase('images', [
|
||||
'id' => 1,
|
||||
'uploaded_by' => $this->user->id
|
||||
]);
|
||||
|
||||
$this->seeInDatabase('tracks', [
|
||||
'title' => $track->title,
|
||||
'user_id' => $this->user->id,
|
||||
'track_type_id' => $track->track_type_id,
|
||||
'released_at' => "2015-01-01 01:01:01",
|
||||
'description' => $track->description,
|
||||
|
@ -104,6 +112,7 @@ class ApiTest extends TestCase {
|
|||
'is_explicit' => true,
|
||||
'is_downloadable' => false,
|
||||
'is_listed' => false,
|
||||
'cover_id' => 1,
|
||||
'metadata' => $track->metadata
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,13 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||
*/
|
||||
protected $baseUrl = 'http://ponyfm-testing.poni';
|
||||
|
||||
/**
|
||||
* The Pony.fm user used in tests.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
protected static $initializedFiles = false;
|
||||
|
||||
/**
|
||||
|
@ -57,7 +64,8 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||
// and add them here with their last-modified date as a Unix
|
||||
// timestamp.
|
||||
$files = [
|
||||
'ponyfm-test.flac' => 1450965707
|
||||
'ponyfm-test.flac' => 1450965707,
|
||||
'ponyfm-transparent-cover-art.png' => 1451211579
|
||||
];
|
||||
|
||||
foreach ($files as $filename => $lastModifiedTimestamp) {
|
||||
|
@ -121,15 +129,16 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||
* Helper function for testing file uploads to the API.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $files
|
||||
*/
|
||||
protected function callUploadWithParameters(array $parameters) {
|
||||
protected function callUploadWithParameters(array $parameters, array $files = []) {
|
||||
$this->expectsJobs(Poniverse\Ponyfm\Jobs\EncodeTrackFile::class);
|
||||
$user = factory(User::class)->create();
|
||||
$this->user = factory(User::class)->create();
|
||||
|
||||
$file = $this->getTestFileForUpload('ponyfm-test.flac');
|
||||
|
||||
$this->actingAs($user)
|
||||
->call('POST', '/api/v1/tracks', $parameters, [], ['track' => $file]);
|
||||
$this->actingAs($this->user)
|
||||
->call('POST', '/api/v1/tracks', $parameters, [], array_merge(['track' => $file], $files));
|
||||
|
||||
$this->assertResponseStatus(202);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue