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