Refactor and fix code styles

This commit is contained in:
Phan An 2017-06-03 17:35:08 +01:00
parent 12265c0a5f
commit 7d80f1d143
9 changed files with 19 additions and 21 deletions

View file

@ -58,7 +58,8 @@ class SongController extends Controller
*/
public function remove(RemoveSongRequest $request)
{
abort_unless($song = Song::byPath("s3://{$request->bucket}/{$request->key}"), 404);
$song = Song::byPath("s3://{$request->bucket}/{$request->key}");
abort_unless((bool) $song, 404);
$song->delete();
event(new LibraryChanged());

View file

@ -7,6 +7,7 @@ use App\Http\Requests\API\ObjectStorage\S3\Request as BaseRequest;
/**
* @property string bucket
* @property array tags
* @property string key
*/
class PutSongRequest extends BaseRequest
{

View file

@ -4,6 +4,10 @@ namespace App\Http\Requests\API\ObjectStorage\S3;
use App\Http\Requests\API\ObjectStorage\S3\Request as BaseRequest;
/**
* @property string bucket
* @property string key
*/
class RemoveSongRequest extends BaseRequest
{
public function rules()

View file

@ -169,7 +169,7 @@ class File
$props['albumartist'] = html_entity_decode(trim($albumArtist));
$props['lyrics'] = html_entity_decode(trim($lyrics));
// A "compilation" property can is determined by:
// A "compilation" property can be determined by:
// - "part_of_a_compilation" tag (used by iTunes), or
// - "albumartist" (used by non-retarded applications).
$props['compilation'] = (bool) (
@ -206,8 +206,6 @@ class File
$force = false;
}
$artist = null;
if ($this->isChanged() || $force) {
// This is a changed file, or the user is forcing updates.
// In such a case, the user must have specified a list of tags to sync.

View file

@ -5,6 +5,7 @@ namespace App\Providers;
use App\Models\Album;
use App\Models\File;
use App\Models\Song;
use Exception;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
@ -44,7 +45,9 @@ class EventServiceProvider extends ServiceProvider
// Remove the cover file if the album is deleted
Album::deleted(function ($album) {
if ($album->hasCover) {
@unlink(app()->publicPath().'/public/img/covers/'.$album->cover);
try {
unlink(app()->publicPath()."/public/img/covers/{$album->cover}");
} catch (Exception $e) {}
}
});
}

View file

@ -128,9 +128,8 @@ class Media
* Sync media using a watch record.
*
* @param WatchRecordInterface $record The watch record.
* @param SyncMedia|null $syncCommand The SyncMedia command object, to log to console if executed by artisan.
*/
public function syncByWatchRecord(WatchRecordInterface $record, SyncMedia $syncCommand = null)
public function syncByWatchRecord(WatchRecordInterface $record)
{
Log::info("New watch record received: '$record'");
$path = $record->getPath();

View file

@ -37,14 +37,6 @@ class TranscodingStreamer extends Streamer implements StreamerInterface
$bitRate = filter_var($this->bitRate, FILTER_SANITIZE_NUMBER_INT);
// Since we can't really know the content length of a file while it's still being transcoded,
// "calculating" it (like below) will be much likely to result in net::ERR_CONTENT_LENGTH_MISMATCH errors.
// Better comment these for now.
//
// header('Accept-Ranges: bytes');
// $bytes = round(($this->song->length * $bitRate * 1024) / 8);
// header("Content-Length: $bytes");
header('Content-Type: audio/mpeg');
header('Content-Disposition: attachment; filename="'.basename($this->song->path).'"');

View file

@ -6,11 +6,11 @@ class Util
{
public function __construct()
{
defined('UTF8_BOM') or define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
defined('UTF16_LITTLE_ENDIAN_BOM') or define('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF).chr(0xFE));
defined('UTF16_BIG_ENDIAN_BOM') or define('UTF16_BIG_ENDIAN_BOM', chr(0xFE).chr(0xFF));
defined('UTF32_LITTLE_ENDIAN_BOM') or define('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF).chr(0xFE).chr(0x00).chr(0x00));
defined('UTF32_BIG_ENDIAN_BOM') or define('UTF32_BIG_ENDIAN_BOM', chr(0x00).chr(0x00).chr(0xFE).chr(0xFF));
defined('UTF8_BOM') || define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
defined('UTF16_LITTLE_ENDIAN_BOM') || define('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF).chr(0xFE));
defined('UTF16_BIG_ENDIAN_BOM') || define('UTF16_BIG_ENDIAN_BOM', chr(0xFE).chr(0xFF));
defined('UTF32_LITTLE_ENDIAN_BOM') || define('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF).chr(0xFE).chr(0x00).chr(0x00));
defined('UTF32_BIG_ENDIAN_BOM') || define('UTF32_BIG_ENDIAN_BOM', chr(0x00).chr(0x00).chr(0xFE).chr(0xFF));
}
/**

View file

@ -57,7 +57,7 @@ trait SupportsDeleteWhereIDsNotIn
{
DB::beginTransaction();
try {
foreach (array_chunk($ids, 65535) as $chunk) {
foreach (array_chunk($ids, $chunkSize) as $chunk) {
static::whereIn($key, $chunk)->delete();
}
DB::commit();