mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-04-10 21:17:39 +02:00
Merge 8df8f73b32
into 80146696f3
This commit is contained in:
commit
89b5dc911f
693 changed files with 15911 additions and 65320 deletions
.dockerignore.env.example
.github/workflows
.gitignoreDOCKER-README.mdDockerfileDockerfile.devapp
AlbumDownloader.php
Commands
AddTrackToPlaylistCommand.phpCommandBase.phpCommandResponse.phpCreateAlbumCommand.phpCreateAnnouncementCommand.phpCreateCommentCommand.phpCreateGenreCommand.phpCreatePlaylistCommand.phpCreateShowSongCommand.phpCreateUserCommand.phpDeleteAlbumCommand.phpDeleteGenreCommand.phpDeletePlaylistCommand.phpDeleteShowSongCommand.phpDeleteTrackCommand.phpEditAlbumCommand.phpEditPlaylistCommand.phpEditTrackCommand.phpGenerateTrackFilesCommand.phpMergeAccountsCommand.phpParseTrackTagsCommand.phpRemoveTrackFromPlaylistCommand.phpRenameGenreCommand.phpRenameShowSongCommand.phpSaveAccountSettingsCommand.phpToggleFavouriteCommand.phpToggleFollowingCommand.phpUploadTrackCommand.php
Console
Commands
BootstrapLocalEnvironment.phpClassifyMLPMA.phpClearTrackCache.phpFixMLPMAImages.phpImportEQBeats.phpMergeAccounts.phpMigrateOldData.phpPoniverseApiSetup.phpRebuildArtists.phpRebuildFilesizes.phpRebuildImages.phpRebuildSearchIndex.phpRebuildTags.phpRebuildTrack.phpRebuildTrackCache.phpRefreshCache.phpSyncPoniverseAccounts.phpVersionFiles.php
Kernel.phpContracts
Exceptions
Facades
Http/Controllers
AccountController.phpAdminController.phpAlbumsController.phpApiControllerBase.phpArtistsController.phpAuthController.phpContentController.phpController.phpHomeController.phpImagesController.phpNotificationsController.phpPlaylistsController.phpStatsController.phpTracksController.phpUploaderController.php
Api
Mobile
V1
Web
AccountController.phpAlbumsController.phpAlexaController.phpAnnouncementsController.phpArtistsController.phpAuthController.phpCommentsController.phpDashboardController.phpFavouritesController.phpFollowController.phpGenresController.phpImagesController.phpNotificationsController.phpPlaylistsController.phpSearchController.phpShowSongsController.phpStatsController.phpTaxonomiesController.phpTracksController.php
2
.dockerignore
Normal file
2
.dockerignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
vendor/
|
49
.env.example
Normal file
49
.env.example
Normal file
|
@ -0,0 +1,49 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailhog
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS=null
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
57
.github/workflows/ci.yml
vendored
Normal file
57
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'upgrade'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare
|
||||
id: prep
|
||||
run: |
|
||||
DOCKER_IMAGE=ghcr.io/poniverse/pony.fm
|
||||
VERSION=edge
|
||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/}
|
||||
elif [[ $GITHUB_REF == refs/heads/* ]]; then
|
||||
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
|
||||
elif [[ $GITHUB_REF == refs/pull/* ]]; then
|
||||
VERSION=pr-${{ github.event.number }}
|
||||
fi
|
||||
TAGS="${DOCKER_IMAGE}:${VERSION}"
|
||||
if [ "${{ github.event_name }}" = "push" ]; then
|
||||
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
|
||||
fi
|
||||
echo ::set-output name=version::${VERSION}
|
||||
echo ::set-output name=tags::${TAGS}
|
||||
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.CR_PAT }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.prep.outputs.tags }}
|
||||
cache-from: type=registry,ref=ghcr.io/poniverse/pony.fm:master
|
||||
cache-to: type=inline
|
||||
labels: |
|
||||
org.opencontainers.image.source=${{ github.event.repository.html_url }}
|
||||
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ resources/views/emails/html
|
|||
npm-debug.log
|
||||
yarn-error.log
|
||||
/composer.phar
|
||||
.phpstorm.meta.php
|
||||
|
|
66
DOCKER-README.md
Normal file
66
DOCKER-README.md
Normal file
|
@ -0,0 +1,66 @@
|
|||
# Pony.fm Docker README
|
||||
|
||||
So, Pony.fm is being converted to run within a container on some new servers where it is hosted, thus it is now gaining
|
||||
support for docker in the project.
|
||||
|
||||
This guide is going to be an attempt to document how to run things in the new docker environment, until it's merged into
|
||||
the main README expect things to be a WIP, and probably be partially documented or undocumented.
|
||||
|
||||
## Environment Setups
|
||||
|
||||
It is my aim to allow Pony.fm to be run in the following types of environments:
|
||||
|
||||
- App is run on the host with dependencies running in docker.
|
||||
- App is run in docker, alongside all dependencies.
|
||||
|
||||
### App on host
|
||||
|
||||
In this the general idea is that you'd need to do the following
|
||||
|
||||
In your .env file you will refer to localhost for pretty much all services.
|
||||
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
```
|
||||
cd public; php -c ../docker/php/php.ini -S localhost:8000 ../serve.php
|
||||
```
|
||||
|
||||
TODO: Figure out if I can change the path that the local php server uses
|
||||
|
||||
Notes:
|
||||
- `php artisan serve` cannot be configured to change ini settings, so max file upload is a problem.
|
||||
- You can change the `FFMPEG_PREFIX` env var to `docker run -v \"$(pwd):$(pwd)\" -w \"$(pwd)\" jrottenberg/ffmpeg:4.3-alpine312` and that'll work as expected. (TODO: Same thing, but for AtomicParsley)
|
||||
|
||||
### App on docker
|
||||
|
||||
You need to install https://docker-sync.readthedocs.io/en/latest/getting-started/installation.html
|
||||
|
||||
** This method is primarily optimised for macOS **
|
||||
|
||||
In your .env file you will refer to the container names for all services. (I.E `DB_HOST=postgresd`, `ELASTICSEARCH_HOST=elasticsearch`)
|
||||
|
||||
Bring everything up
|
||||
```
|
||||
docker build . -t ponyfm
|
||||
docker-sync start
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Notes:
|
||||
- Initial sync is super slow, but watching is pretty fast
|
||||
- You could skip docker-sync and change `appcode-sync` to `./` but expect request time to go from the `ms` to the many `s`'s.
|
||||
|
||||
Once everything is up and running
|
||||
|
||||
Create an alias to interact with the `artisan` cli tool:
|
||||
|
||||
```
|
||||
alias p="docker compose exec web php artisan"
|
||||
```
|
||||
|
||||
Then migrate and seed the app, and you should be good to go!
|
||||
|
||||
```
|
||||
p migrate --seed
|
||||
```
|
83
Dockerfile
Normal file
83
Dockerfile
Normal file
|
@ -0,0 +1,83 @@
|
|||
FROM jrottenberg/ffmpeg:4.3-alpine312 as ffmpeg
|
||||
|
||||
FROM alpine:3.12 as atomicparsley_builder
|
||||
|
||||
RUN apk add --no-cache make cmake linux-headers g++ git
|
||||
RUN git clone https://github.com/wez/atomicparsley.git /tmp/atomicparsley
|
||||
|
||||
RUN cd /tmp/atomicparsley \
|
||||
&& cmake . \
|
||||
&& cmake --build . --config Release
|
||||
|
||||
FROM node:12-alpine as assets_builder
|
||||
|
||||
# To handle 'not get uid/gid'
|
||||
RUN npm config set unsafe-perm true
|
||||
|
||||
RUN npm install -g gulp
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json /app
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY gulpfile.js /app
|
||||
COPY webpack.base.config.js /app
|
||||
COPY webpack.dev.config.js /app
|
||||
COPY webpack.production.config.js /app
|
||||
COPY public /app/public/
|
||||
COPY resources /app/resources/
|
||||
|
||||
RUN gulp build
|
||||
|
||||
FROM php:8.0-fpm-alpine
|
||||
|
||||
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
|
||||
|
||||
COPY --from=ffmpeg /usr/local /usr/local
|
||||
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/install-php-extensions
|
||||
COPY --from=atomicparsley_builder /tmp/atomicparsley/AtomicParsley /usr/local/bin/AtomicParsley
|
||||
|
||||
RUN apk update
|
||||
|
||||
## Common libraries required for ffmpeg & atomicparsley` to work
|
||||
RUN apk add libgcc libstdc++ ca-certificates libcrypto1.1 libssl1.1 libgomp expat git
|
||||
RUN apk add nginx sudo
|
||||
|
||||
# Install php extensions
|
||||
RUN install-php-extensions mysqli pgsql pdo_mysql pdo_pgsql gmp gmagick redis
|
||||
|
||||
# not sure why but this needs to be after the php extensions otherwise some kind of dependency issue occurs
|
||||
RUN apk add imagemagick
|
||||
|
||||
RUN mkdir /app && chown -R www-data: /app
|
||||
|
||||
USER www-data
|
||||
WORKDIR /app
|
||||
|
||||
COPY --chown=www-data composer.json /app
|
||||
COPY --chown=www-data composer.lock /app
|
||||
|
||||
RUN composer install --no-scripts --no-autoloader --ignore-platform-reqs
|
||||
|
||||
COPY --chown=www-data --from=assets_builder /app /app
|
||||
COPY --chown=www-data . /app
|
||||
|
||||
RUN composer dump-autoload -o
|
||||
RUN php artisan optimize
|
||||
|
||||
USER root
|
||||
|
||||
# Remove files no longer needed on the host
|
||||
RUN rm /usr/bin/composer /usr/bin/install-php-extensions
|
||||
|
||||
COPY docker/nginx/site.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
COPY docker/php/php.ini /usr/local/etc/php/conf.d/php.ini
|
||||
COPY docker/php/php.ini /usr/local/etc/php-fpm.d/php.ini
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
ENTRYPOINT ["docker/entrypoint.sh"]
|
13
Dockerfile.dev
Normal file
13
Dockerfile.dev
Normal file
|
@ -0,0 +1,13 @@
|
|||
FROM ponyfm
|
||||
|
||||
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/install-php-extensions
|
||||
|
||||
RUN install-php-extensions xdebug
|
||||
|
||||
RUN echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||
&& echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||
&& echo "xdebug.idekey=phpstorm" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||
&& echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -45,8 +45,8 @@ class AlbumDownloader
|
|||
public function download()
|
||||
{
|
||||
// Check whether the format is lossless yet not all master files are lossless
|
||||
$isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats)
|
||||
&& !$this->_album->hasLosslessTracksOnly()
|
||||
$isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats)
|
||||
&& ! $this->_album->hasLosslessTracksOnly()
|
||||
&& $this->_album->hasLosslessTracks();
|
||||
|
||||
$zip = new ZipStream($this->_album->user->display_name.' - '.$this->_album->title.'.zip');
|
||||
|
@ -71,7 +71,7 @@ class AlbumDownloader
|
|||
"\r\n";
|
||||
|
||||
foreach ($this->_album->tracks as $track) {
|
||||
if (!$track->is_downloadable) {
|
||||
if (! $track->is_downloadable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -79,12 +79,12 @@ class AlbumDownloader
|
|||
$masterFormatName = $track->getMasterFormatName();
|
||||
$zip->addLargeFile(
|
||||
$track->getFileFor($masterFormatName),
|
||||
$directory . $track->getDownloadFilenameFor($masterFormatName)
|
||||
$directory.$track->getDownloadFilenameFor($masterFormatName)
|
||||
);
|
||||
} else {
|
||||
$zip->addLargeFile(
|
||||
$track->getFileFor($this->_format),
|
||||
$directory . $track->getDownloadFilenameFor($this->_format)
|
||||
$directory.$track->getDownloadFilenameFor($this->_format)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,9 +22,9 @@ namespace App\Commands;
|
|||
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Track;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class AddTrackToPlaylistCommand extends CommandBase
|
||||
{
|
||||
|
@ -59,20 +59,19 @@ class AddTrackToPlaylistCommand extends CommandBase
|
|||
// check if this track is already in the playlist
|
||||
$validator = Validator::make(
|
||||
['track_id' => $this->_track->id],
|
||||
['track_id' => "unique:playlist_track,track_id,null,id,playlist_id,{$this->_playlist->id}", ]
|
||||
['track_id' => "unique:playlist_track,track_id,null,id,playlist_id,{$this->_playlist->id}"]
|
||||
);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
||||
|
||||
$songIndex = $this->_playlist->trackCount() + 1;
|
||||
$this->_playlist->tracks()->attach($this->_track, ['position' => $songIndex]);
|
||||
$this->_playlist->touch();
|
||||
|
||||
Playlist::where('id', $this->_playlist->id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')'),
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Track added!']);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -37,7 +37,7 @@ class CommandResponse
|
|||
|
||||
public static function fail($validatorOrMessages, int $statusCode = 400)
|
||||
{
|
||||
$response = new CommandResponse();
|
||||
$response = new self();
|
||||
$response->_didFail = true;
|
||||
$response->_statusCode = $statusCode;
|
||||
|
||||
|
@ -53,7 +53,7 @@ class CommandResponse
|
|||
|
||||
public static function succeed($response = null, int $statusCode = 200)
|
||||
{
|
||||
$cmdResponse = new CommandResponse();
|
||||
$cmdResponse = new self();
|
||||
$cmdResponse->_didFail = false;
|
||||
$cmdResponse->_response = $response;
|
||||
$cmdResponse->_statusCode = $statusCode;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use App\Models\Album;
|
||||
use App\Models\Image;
|
||||
use Auth;
|
||||
use App\Models\User;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CreateAlbumCommand extends CommandBase
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ class CreateAlbumCommand extends CommandBase
|
|||
'cover' => 'image|mimes:png|min_width:350|min_height:350',
|
||||
'cover_id' => 'exists:images,id',
|
||||
'track_ids' => 'exists:tracks,id',
|
||||
'user_id' => 'exists:users,id'
|
||||
'user_id' => 'exists:users,id',
|
||||
];
|
||||
|
||||
$validator = Validator::make($this->_input, $rules);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,9 +20,9 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use App\Models\Announcement;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CreateAnnouncementCommand extends CommandBase
|
||||
{
|
||||
|
@ -48,7 +48,6 @@ class CreateAnnouncementCommand extends CommandBase
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
|
||||
$rules = [
|
||||
'name' => 'required|max:50',
|
||||
];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,14 +20,14 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Notification;
|
||||
use App\Facades\Notification;
|
||||
use App\Models\Album;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Auth;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CreateCommentCommand extends CommandBase
|
||||
{
|
||||
|
@ -88,7 +88,7 @@ class CreateCommentCommand extends CommandBase
|
|||
if ($this->_type == 'playlist') {
|
||||
$column = 'playlist_id';
|
||||
} else {
|
||||
App::abort(500);
|
||||
abort(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,12 +107,12 @@ class CreateCommentCommand extends CommandBase
|
|||
} elseif ($this->_type === 'user') {
|
||||
$entity = User::find($this->_id);
|
||||
} else {
|
||||
App::abort(400, 'This comment is being added to an invalid entity!');
|
||||
abort(400, 'This comment is being added to an invalid entity!');
|
||||
}
|
||||
|
||||
$entity->comment_count = Comment::where($column, $this->_id)->count();
|
||||
$entity->save();
|
||||
|
||||
|
||||
Notification::newComment($comment);
|
||||
|
||||
return CommandResponse::succeed(Comment::mapPublic($comment));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Genre;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateGenreCommand extends CommandBase
|
||||
{
|
||||
|
@ -53,12 +53,12 @@ class CreateGenreCommand extends CommandBase
|
|||
|
||||
$rules = [
|
||||
'name' => 'required|unique:genres,name,NULL,id,deleted_at,NULL|max:50',
|
||||
'slug' => 'required|unique:genres,slug,NULL,id,deleted_at,NULL'
|
||||
'slug' => 'required|unique:genres,slug,NULL,id,deleted_at,NULL',
|
||||
];
|
||||
|
||||
$validator = Validator::make([
|
||||
'name' => $this->_genreName,
|
||||
'slug' => $slug
|
||||
'slug' => $slug,
|
||||
], $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -67,7 +67,7 @@ class CreateGenreCommand extends CommandBase
|
|||
|
||||
Genre::create([
|
||||
'name' => $this->_genreName,
|
||||
'slug' => $slug
|
||||
'slug' => $slug,
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Genre created!']);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Notification;
|
||||
use App\Facades\Notification;
|
||||
use App\Models\Playlist;
|
||||
use Auth;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CreatePlaylistCommand extends CommandBase
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class CreatePlaylistCommand extends CommandBase
|
|||
$rules = [
|
||||
'title' => 'required|min:3|max:50',
|
||||
'is_public' => 'required',
|
||||
'is_pinned' => 'required'
|
||||
'is_pinned' => 'required',
|
||||
];
|
||||
|
||||
$validator = Validator::make($this->_input, $rules);
|
||||
|
@ -69,7 +69,7 @@ class CreatePlaylistCommand extends CommandBase
|
|||
$playlist->is_public = $this->_input['is_public'] == 'true';
|
||||
|
||||
$playlist->save();
|
||||
|
||||
|
||||
Notification::publishedNewPlaylist($playlist);
|
||||
|
||||
if ($this->_input['is_pinned'] == 'true') {
|
||||
|
@ -84,7 +84,7 @@ class CreatePlaylistCommand extends CommandBase
|
|||
'description' => $playlist->description,
|
||||
'url' => $playlist->url,
|
||||
'is_pinned' => $this->_input['is_pinned'] == 'true',
|
||||
'is_public' => $this->_input['is_public'] == 'true'
|
||||
'is_public' => $this->_input['is_public'] == 'true',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\ShowSong;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateShowSongCommand extends CommandBase
|
||||
{
|
||||
|
@ -53,12 +53,12 @@ class CreateShowSongCommand extends CommandBase
|
|||
|
||||
$rules = [
|
||||
'title' => 'required|unique:show_songs,title,NULL,id,deleted_at,NULL|max:250',
|
||||
'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL'
|
||||
'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL',
|
||||
];
|
||||
|
||||
$validator = Validator::make([
|
||||
'title' => $this->_songName,
|
||||
'slug' => $slug
|
||||
'slug' => $slug,
|
||||
], $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -68,7 +68,7 @@ class CreateShowSongCommand extends CommandBase
|
|||
ShowSong::create([
|
||||
'title' => $this->_songName,
|
||||
'slug' => $slug,
|
||||
'lyrics' => ''
|
||||
'lyrics' => '',
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Song created!']);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,9 +20,9 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use App\Models\User;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CreateUserCommand extends CommandBase
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ class CreateUserCommand extends CommandBase
|
|||
private $displayName;
|
||||
private $email;
|
||||
private $createArchivedUser;
|
||||
|
||||
|
||||
public function __construct(
|
||||
string $username,
|
||||
string $displayName,
|
||||
|
@ -72,7 +72,7 @@ class CreateUserCommand extends CommandBase
|
|||
if ($validator->fails()) {
|
||||
return CommandResponse::fail([
|
||||
'message' => $validator->getMessageBag()->first(),
|
||||
'user' => null
|
||||
'user' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -81,12 +81,12 @@ class CreateUserCommand extends CommandBase
|
|||
if ($user->wasRecentlyCreated) {
|
||||
return CommandResponse::succeed([
|
||||
'message' => 'New user successfully created!',
|
||||
'user' => User::mapPublicUserSummary($user)
|
||||
'user' => User::mapPublicUserSummary($user),
|
||||
], 201);
|
||||
} else {
|
||||
return CommandResponse::fail([
|
||||
'message' => 'A user with that username already exists.',
|
||||
'user' => User::mapPublicUserSummary($user)
|
||||
'user' => User::mapPublicUserSummary($user),
|
||||
], 409);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,9 +20,9 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use App\Models\Album;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class DeleteAlbumCommand extends CommandBase
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,17 +20,16 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Models\Genre;
|
||||
use App\Jobs\DeleteGenre;
|
||||
use Validator;
|
||||
use App\Models\Genre;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class DeleteGenreCommand extends CommandBase
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
|
||||
/** @var Genre */
|
||||
private $_genreToDelete;
|
||||
private $_destinationGenre;
|
||||
|
@ -67,7 +66,6 @@ class DeleteGenreCommand extends CommandBase
|
|||
'destination_genre' => $this->_destinationGenre,
|
||||
], $rules);
|
||||
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,7 +21,7 @@
|
|||
namespace App\Commands;
|
||||
|
||||
use App\Models\Playlist;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DeletePlaylistCommand extends CommandBase
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,17 +20,16 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Models\ShowSong;
|
||||
use App\Jobs\DeleteShowSong;
|
||||
use Validator;
|
||||
use App\Models\ShowSong;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class DeleteShowSongCommand extends CommandBase
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
|
||||
/** @var ShowSong */
|
||||
private $_songToDelete;
|
||||
private $_destinationSong;
|
||||
|
@ -67,7 +66,6 @@ class DeleteShowSongCommand extends CommandBase
|
|||
'destination_song' => $this->_destinationSong,
|
||||
], $rules);
|
||||
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use App\Models\Track;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class DeleteTrackCommand extends CommandBase
|
||||
{
|
||||
/** @var int */
|
||||
/** @var int */
|
||||
private $_trackId;
|
||||
|
||||
/** @var Track */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -23,10 +23,10 @@ namespace App\Commands;
|
|||
use App\Models\Album;
|
||||
use App\Models\Image;
|
||||
use App\Models\User;
|
||||
use Auth;
|
||||
use Gate;
|
||||
use DB;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class EditAlbumCommand extends CommandBase
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ class EditAlbumCommand extends CommandBase
|
|||
'title' => 'required|min:3|max:50',
|
||||
'cover' => 'image|mimes:png|min_width:350|min_height:350',
|
||||
'cover_id' => 'exists:images,id',
|
||||
'username' => 'exists:users,username'
|
||||
'username' => 'exists:users,username',
|
||||
];
|
||||
|
||||
$validator = Validator::make($this->_input, $rules);
|
||||
|
@ -77,7 +77,7 @@ class EditAlbumCommand extends CommandBase
|
|||
$trackDbCount = DB::table('tracks')->whereIn('id', $trackIds)->count();
|
||||
|
||||
if ($trackDbCount != $trackIdsCount) {
|
||||
return CommandResponse::fail("Track IDs invalid");
|
||||
return CommandResponse::fail('Track IDs invalid');
|
||||
}
|
||||
|
||||
$this->_album->title = $this->_input['title'];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,8 +22,8 @@ namespace App\Commands;
|
|||
|
||||
use App\Models\PinnedPlaylist;
|
||||
use App\Models\Playlist;
|
||||
use Auth;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class EditPlaylistCommand extends CommandBase
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ class EditPlaylistCommand extends CommandBase
|
|||
$rules = [
|
||||
'title' => 'required|min:3|max:50',
|
||||
'is_public' => 'required',
|
||||
'is_pinned' => 'required'
|
||||
'is_pinned' => 'required',
|
||||
];
|
||||
|
||||
$validator = Validator::make($this->_input, $rules);
|
||||
|
@ -76,7 +76,7 @@ class EditPlaylistCommand extends CommandBase
|
|||
if ($pin && $this->_input['is_pinned'] != 'true') {
|
||||
$pin->delete();
|
||||
} else {
|
||||
if (!$pin && $this->_input['is_pinned'] == 'true') {
|
||||
if (! $pin && $this->_input['is_pinned'] == 'true') {
|
||||
$this->_playlist->pin(Auth::user()->id);
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class EditPlaylistCommand extends CommandBase
|
|||
'description' => $this->_playlist->description,
|
||||
'url' => $this->_playlist->url,
|
||||
'is_pinned' => $this->_input['is_pinned'] == 'true',
|
||||
'is_public' => $this->_input['is_public'] == 'true'
|
||||
'is_public' => $this->_input['is_public'] == 'true',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,15 +20,15 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Notification;
|
||||
use App\Facades\Notification;
|
||||
use App\Models\Album;
|
||||
use App\Models\Image;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Track;
|
||||
use App\Models\TrackType;
|
||||
use App\Models\User;
|
||||
use App\Models\Playlist;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class EditTrackCommand extends CommandBase
|
||||
{
|
||||
|
@ -65,9 +65,9 @@ class EditTrackCommand extends CommandBase
|
|||
|
||||
$rules = [
|
||||
'title' => 'required|min:3|max:80',
|
||||
'released_at' => 'before:' .
|
||||
(date('Y-m-d', time() + (86400 * 2))) . (
|
||||
isset($this->_input['released_at']) && $this->_input['released_at'] != ""
|
||||
'released_at' => 'before:'.
|
||||
(date('Y-m-d', time() + (86400 * 2))).(
|
||||
isset($this->_input['released_at']) && $this->_input['released_at'] != ''
|
||||
? '|date'
|
||||
: ''),
|
||||
'license_id' => 'required|exists:licenses,id',
|
||||
|
@ -76,7 +76,7 @@ class EditTrackCommand extends CommandBase
|
|||
'track_type_id' => 'required|exists:track_types,id|not_in:'.TrackType::UNCLASSIFIED_TRACK,
|
||||
'cover_id' => 'exists:images,id',
|
||||
'album_id' => 'exists:albums,id',
|
||||
'username' => 'exists:users,username'
|
||||
'username' => 'exists:users,username',
|
||||
];
|
||||
|
||||
if (isset($this->_input['track_type_id']) && $this->_input['track_type_id'] == TrackType::OFFICIAL_TRACK_REMIX) {
|
||||
|
@ -92,7 +92,7 @@ class EditTrackCommand extends CommandBase
|
|||
|
||||
$track = $this->_track;
|
||||
$track->title = $this->_input['title'];
|
||||
$track->released_at = isset($this->_input['released_at']) && $this->_input['released_at'] != "" ? strtotime($this->_input['released_at']) : null;
|
||||
$track->released_at = isset($this->_input['released_at']) && $this->_input['released_at'] != '' ? strtotime($this->_input['released_at']) : null;
|
||||
$track->description = isset($this->_input['description']) ? $this->_input['description'] : '';
|
||||
$track->lyrics = isset($this->_input['lyrics']) ? $this->_input['lyrics'] : '';
|
||||
$track->license_id = $this->_input['license_id'];
|
||||
|
@ -163,26 +163,26 @@ class EditTrackCommand extends CommandBase
|
|||
$track->save();
|
||||
|
||||
User::whereId($this->_track->user_id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $this->_track->user_id . ')')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = '.$this->_track->user_id.')'),
|
||||
]);
|
||||
|
||||
if ($oldid != null) {
|
||||
User::whereId($oldid)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $oldid . ')')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = '.$oldid.')'),
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime("2016-12-20 23:59:59")) {
|
||||
if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime('2016-12-20 23:59:59')) {
|
||||
$playlist = Playlist::where('user_id', 22549)->first();
|
||||
|
||||
if ($this->_input['hwc_submit'] == 'true') {
|
||||
if (!$playlist->tracks()->get()->contains($track)) {
|
||||
if (! $playlist->tracks()->get()->contains($track)) {
|
||||
$songIndex = $playlist->trackCount() + 1;
|
||||
$playlist->tracks()->attach($track, ['position' => $songIndex]);
|
||||
$playlist->touch();
|
||||
|
||||
Playlist::where('id', $playlist->id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')'),
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
|
@ -190,11 +190,12 @@ class EditTrackCommand extends CommandBase
|
|||
$playlist->tracks()->detach($track);
|
||||
|
||||
Playlist::whereId($playlist->id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CommandResponse::succeed(['real_cover_url' => $track->getCoverUrl(Image::NORMAL)]);
|
||||
}
|
||||
|
||||
|
@ -215,7 +216,7 @@ class EditTrackCommand extends CommandBase
|
|||
}
|
||||
|
||||
Album::whereId($album->id)->update([
|
||||
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count()
|
||||
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -230,7 +231,7 @@ class EditTrackCommand extends CommandBase
|
|||
$track->save();
|
||||
|
||||
$album->update([
|
||||
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count()
|
||||
'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,23 +20,21 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use AudioCache;
|
||||
use FFmpegMovie;
|
||||
use File;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Exceptions\InvalidEncodeOptionsException;
|
||||
use App\Jobs\EncodeTrackFile;
|
||||
use App\Models\Track;
|
||||
use App\Models\TrackFile;
|
||||
use AudioCache;
|
||||
use FFmpegMovie;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use SplFileInfo;
|
||||
|
||||
/**
|
||||
* This command is the "second phase" of the upload process - once metadata has
|
||||
* been parsed and the track object is created, this generates the track's
|
||||
* corresponding TrackFile objects and ensures that all of them have been encoded.
|
||||
*
|
||||
* @package App\Commands
|
||||
*/
|
||||
class GenerateTrackFilesCommand extends CommandBase
|
||||
{
|
||||
|
@ -53,7 +51,7 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
'flac',
|
||||
'pcm',
|
||||
'adpcm',
|
||||
'alac'
|
||||
'alac',
|
||||
];
|
||||
|
||||
public function __construct(Track $track, SplFileInfo $sourceFile, bool $autoPublish = false, bool $isForUpload = false, bool $isReplacingTrack = false, int $version = 1)
|
||||
|
@ -78,25 +76,26 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
// Lossy uploads need to be identified and set as the master file
|
||||
// without being re-encoded.
|
||||
$audioObject = AudioCache::get($source);
|
||||
$isLossyUpload = !$this->isLosslessFile($audioObject);
|
||||
$isLossyUpload = ! $this->isLosslessFile($audioObject);
|
||||
$codecString = $audioObject->getAudioCodec();
|
||||
|
||||
if ($isLossyUpload) {
|
||||
if ($codecString === 'mp3') {
|
||||
$masterFormat = 'MP3';
|
||||
} else if (Str::startsWith($codecString, 'aac')) {
|
||||
} elseif (Str::startsWith($codecString, 'aac')) {
|
||||
$masterFormat = 'AAC';
|
||||
} else if ($codecString === 'vorbis') {
|
||||
} elseif ($codecString === 'vorbis') {
|
||||
$masterFormat = 'OGG Vorbis';
|
||||
} else {
|
||||
$this->track->delete();
|
||||
|
||||
return CommandResponse::fail(['track' => "The track does not contain audio in a known lossy format. The format read from the file is: {$codecString}"]);
|
||||
}
|
||||
|
||||
// Sanity check: skip creating this TrackFile if it already exists.
|
||||
$trackFile = $this->trackFileExists($masterFormat);
|
||||
|
||||
if (!$trackFile) {
|
||||
if (! $trackFile) {
|
||||
$trackFile = new TrackFile();
|
||||
$trackFile->is_master = true;
|
||||
$trackFile->format = $masterFormat;
|
||||
|
@ -109,7 +108,6 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
File::copy($source, $trackFile->getFile());
|
||||
}
|
||||
|
||||
|
||||
$trackFiles = [];
|
||||
|
||||
foreach (Track::$Formats as $name => $format) {
|
||||
|
@ -132,7 +130,7 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
$trackFile->status = TrackFile::STATUS_PROCESSING_PENDING;
|
||||
$trackFile->version = $this->version;
|
||||
|
||||
if (in_array($name, Track::$CacheableFormats) && !$trackFile->is_master) {
|
||||
if (in_array($name, Track::$CacheableFormats) && ! $trackFile->is_master) {
|
||||
$trackFile->is_cacheable = true;
|
||||
} else {
|
||||
$trackFile->is_cacheable = false;
|
||||
|
@ -148,7 +146,7 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
try {
|
||||
foreach ($trackFiles as $trackFile) {
|
||||
// Don't re-encode master files when replacing tracks with an already-uploaded version
|
||||
if ($trackFile->is_master && !$this->isForUpload && $this->isReplacingTrack) {
|
||||
if ($trackFile->is_master && ! $this->isForUpload && $this->isReplacingTrack) {
|
||||
continue;
|
||||
}
|
||||
$this->dispatch(new EncodeTrackFile($trackFile, false, false, $this->isForUpload, $this->isReplacingTrack));
|
||||
|
@ -161,6 +159,7 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
} else {
|
||||
$this->track->delete();
|
||||
}
|
||||
|
||||
return CommandResponse::fail(['track' => [$e->getMessage()]]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
@ -176,6 +175,7 @@ class GenerateTrackFilesCommand extends CommandBase
|
|||
// This ensures that any updates to the track record, like from parsed
|
||||
// tags, are reflected in the command's response.
|
||||
$this->track = $this->track->fresh();
|
||||
|
||||
return CommandResponse::succeed([
|
||||
'id' => $this->track->id,
|
||||
'name' => $this->track->name,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,8 +20,6 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use App\Models\Album;
|
||||
use App\Models\Comment;
|
||||
use App\Models\EmailSubscription;
|
||||
|
@ -35,6 +33,8 @@ use App\Models\ResourceLogItem;
|
|||
use App\Models\ResourceUser;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MergeAccountsCommand extends CommandBase
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ class MergeAccountsCommand extends CommandBase
|
|||
}
|
||||
|
||||
/** @var EmailSubscription $emailSubscription */
|
||||
foreach($this->sourceAccount->emailSubscriptions()->withTrashed()->get() as $emailSubscription) {
|
||||
foreach ($this->sourceAccount->emailSubscriptions()->withTrashed()->get() as $emailSubscription) {
|
||||
// This keeps emails from being sent to disabled accounts.
|
||||
$emailSubscription->delete();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,18 +20,18 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use getID3;
|
||||
use App\Models\Album;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Image;
|
||||
use App\Models\Track;
|
||||
use AudioCache;
|
||||
use File;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\TrackType;
|
||||
use App\Models\User;
|
||||
use AudioCache;
|
||||
use Carbon\Carbon;
|
||||
use getID3;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
|
@ -58,15 +58,14 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
list($parsedTags, $rawTags) = $this->parseOriginalTags($this->fileToParse, $this->track->user, $audio->getAudioCodec());
|
||||
$this->track->original_tags = ['parsed_tags' => $parsedTags, 'raw_tags' => $rawTags];
|
||||
|
||||
|
||||
if ($this->input['cover'] !== null) {
|
||||
$this->track->cover_id = Image::upload($this->input['cover'], $this->track->user_id)->id;
|
||||
} else {
|
||||
$this->track->cover_id = $parsedTags['cover_id'];
|
||||
}
|
||||
|
||||
$this->track->title = $this->input['title'] ?? $parsedTags['title'] ?? $this->track->title;
|
||||
$this->track->track_type_id = $this->input['track_type_id'] ?? TrackType::UNCLASSIFIED_TRACK;
|
||||
$this->track->title = $this->input['title'] ?? $parsedTags['title'] ?? $this->track->title;
|
||||
$this->track->track_type_id = $this->input['track_type_id'] ?? TrackType::UNCLASSIFIED_TRACK;
|
||||
|
||||
$this->track->genre_id = isset($this->input['genre'])
|
||||
? $this->getGenreId($this->input['genre'])
|
||||
|
@ -89,26 +88,27 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
? Carbon::createFromFormat(Carbon::ISO8601, $this->input['released_at'])
|
||||
: $parsedTags['release_date'];
|
||||
|
||||
$this->track->description = $this->input['description'] ?? $parsedTags['comments'];
|
||||
$this->track->lyrics = $this->input['lyrics'] ?? $parsedTags['lyrics'];
|
||||
$this->track->description = $this->input['description'] ?? $parsedTags['comments'];
|
||||
$this->track->lyrics = $this->input['lyrics'] ?? $parsedTags['lyrics'];
|
||||
|
||||
$this->track->is_vocal = $this->input['is_vocal'] ?? $parsedTags['is_vocal'];
|
||||
$this->track->is_explicit = $this->input['is_explicit'] ?? false;
|
||||
$this->track->is_vocal = $this->input['is_vocal'] ?? $parsedTags['is_vocal'];
|
||||
$this->track->is_explicit = $this->input['is_explicit'] ?? false;
|
||||
$this->track->is_downloadable = $this->input['is_downloadable'] ?? true;
|
||||
$this->track->is_listed = $this->input['is_listed'] ?? true;
|
||||
$this->track->is_listed = $this->input['is_listed'] ?? true;
|
||||
|
||||
$this->track = $this->unsetNullVariables($this->track);
|
||||
|
||||
$this->track->save();
|
||||
|
||||
return CommandResponse::succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* If a value is null, remove it! Helps prevent weird SQL errors
|
||||
* If a value is null, remove it! Helps prevent weird SQL errors.
|
||||
*
|
||||
* @param Track
|
||||
* @return Track
|
||||
*/
|
||||
*/
|
||||
private function unsetNullVariables($track)
|
||||
{
|
||||
$vars = $track->getAttributes();
|
||||
|
@ -138,7 +138,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
|
||||
return Genre::create([
|
||||
'name' => $genreName,
|
||||
'slug' => Str::slug($genreName)
|
||||
'slug' => Str::slug($genreName),
|
||||
])->id;
|
||||
} else {
|
||||
// Exists in db, has it been deleted?
|
||||
|
@ -150,6 +150,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
// instead of creating a new one
|
||||
|
||||
$existingGenre->restore();
|
||||
|
||||
return $existingGenre->id;
|
||||
} else {
|
||||
// It's fine, just return the ID
|
||||
|
@ -166,7 +167,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
*
|
||||
* @param int $artistId
|
||||
* @param string|null $albumName
|
||||
* @param integer|null $coverId
|
||||
* @param int|null $coverId
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getAlbumId(int $artistId, $albumName, $coverId = null)
|
||||
|
@ -174,7 +175,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
if (null !== $albumName) {
|
||||
$album = Album::firstOrNew([
|
||||
'user_id' => $artistId,
|
||||
'title' => $albumName
|
||||
'title' => $albumName,
|
||||
]);
|
||||
|
||||
if (null === $album->id) {
|
||||
|
@ -249,7 +250,6 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
//==========================================================================================================
|
||||
$parsedTags['is_vocal'] = $parsedTags['lyrics'] !== null;
|
||||
|
||||
|
||||
//==========================================================================================================
|
||||
// Determine the genre.
|
||||
//==========================================================================================================
|
||||
|
@ -278,7 +278,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
}
|
||||
|
||||
// write temporary image file
|
||||
$tmpPath = Config::get('ponyfm.files_directory').'/tmp';
|
||||
$tmpPath = config('ponyfm.files_directory').'/tmp';
|
||||
|
||||
$filename = $file->getFilename().".cover.${extension}";
|
||||
$imageFilePath = "${tmpPath}/${filename}";
|
||||
|
@ -294,7 +294,6 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
|
||||
$parsedTags['cover_id'] = $coverId;
|
||||
|
||||
|
||||
//==========================================================================================================
|
||||
// Is this part of an album?
|
||||
//==========================================================================================================
|
||||
|
@ -307,11 +306,9 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
|
||||
$parsedTags['album_id'] = $albumId;
|
||||
|
||||
|
||||
return [$parsedTags, $rawTags];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $rawTags
|
||||
* @return array
|
||||
|
@ -326,7 +323,6 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
$tags = [];
|
||||
}
|
||||
|
||||
|
||||
$comment = null;
|
||||
|
||||
if (isset($tags['comment'])) {
|
||||
|
@ -361,7 +357,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
'comments' => $comment,
|
||||
'lyrics' => isset($tags['unsynchronised_lyric']) ? $tags['unsynchronised_lyric'][0] : null,
|
||||
],
|
||||
$tags
|
||||
$tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -405,7 +401,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
|
||||
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
|
||||
],
|
||||
$tags
|
||||
$tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -441,7 +437,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
|
||||
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
|
||||
],
|
||||
$tags
|
||||
$tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -474,7 +470,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
// YYYY-MM
|
||||
case 7:
|
||||
try {
|
||||
return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString))
|
||||
return Carbon::createFromFormat('Y m', str_replace('-', ' ', $dateString))
|
||||
->day(1);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
|
@ -483,7 +479,7 @@ class ParseTrackTagsCommand extends CommandBase
|
|||
// YYYY-MM-DD
|
||||
case 10:
|
||||
try {
|
||||
return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString));
|
||||
return Carbon::createFromFormat('Y m d', str_replace('-', ' ', $dateString));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,8 +22,8 @@ namespace App\Commands;
|
|||
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Track;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RemoveTrackFromPlaylistCommand extends CommandBase
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ class RemoveTrackFromPlaylistCommand extends CommandBase
|
|||
{
|
||||
$this->_playlist->tracks()->detach($this->_track);
|
||||
Playlist::whereId($this->_playlist->id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')'),
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Track removed!']);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Jobs\UpdateTagsForRenamedGenre;
|
||||
use App\Models\Genre;
|
||||
use Validator;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RenameGenreCommand extends CommandBase
|
||||
{
|
||||
|
@ -59,15 +59,14 @@ class RenameGenreCommand extends CommandBase
|
|||
|
||||
$rules = [
|
||||
'name' => 'required|unique:genres,name,'.$this->_genre->id.',id,deleted_at,NULL|max:50',
|
||||
'slug' => 'required|unique:genres,slug,'.$this->_genre->id.',id,deleted_at,NULL'
|
||||
'slug' => 'required|unique:genres,slug,'.$this->_genre->id.',id,deleted_at,NULL',
|
||||
];
|
||||
|
||||
$validator = Validator::make([
|
||||
'name' => $this->_newName,
|
||||
'slug' => $slug
|
||||
'slug' => $slug,
|
||||
], $rules);
|
||||
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Jobs\UpdateTagsForRenamedShowSong;
|
||||
use App\Models\ShowSong;
|
||||
use Validator;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RenameShowSongCommand extends CommandBase
|
||||
{
|
||||
|
@ -59,15 +59,14 @@ class RenameShowSongCommand extends CommandBase
|
|||
|
||||
$rules = [
|
||||
'title' => 'required|unique:show_songs,title,'.$this->_song->id.',id|max:250',
|
||||
'slug' => 'required|unique:show_songs,slug,'.$this->_song->id.',id'
|
||||
'slug' => 'required|unique:show_songs,slug,'.$this->_song->id.',id',
|
||||
];
|
||||
|
||||
$validator = Validator::make([
|
||||
'title' => $this->_newName,
|
||||
'slug' => $slug
|
||||
'slug' => $slug,
|
||||
], $rules);
|
||||
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,11 +20,11 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Models\Image;
|
||||
use App\Models\User;
|
||||
use Gate;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class SaveAccountSettingsCommand extends CommandBase
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ class SaveAccountSettingsCommand extends CommandBase
|
|||
'unique:users,slug,'.$this->_user->id,
|
||||
'min:'.config('ponyfm.user_slug_minimum_length'),
|
||||
'regex:/^[a-z\d-]+$/',
|
||||
'is_not_reserved_slug'
|
||||
'is_not_reserved_slug',
|
||||
],
|
||||
'notifications.*.activity_type' => 'required|exists:activity_types,activity_type',
|
||||
'notifications.*.receive_emails' => 'present|boolean',
|
||||
|
@ -77,21 +77,20 @@ class SaveAccountSettingsCommand extends CommandBase
|
|||
}
|
||||
|
||||
$validator = Validator::make($this->_input, $rules, [
|
||||
'slug.regex' => 'Slugs can only contain numbers, lowercase letters, and dashes.'
|
||||
'slug.regex' => 'Slugs can only contain numbers, lowercase letters, and dashes.',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
||||
|
||||
$this->_user->bio = $this->_input['bio'];
|
||||
$this->_user->display_name = $this->_input['display_name'];
|
||||
$this->_user->slug = $this->_input['slug'];
|
||||
$this->_user->can_see_explicit_content = $this->_input['can_see_explicit_content'] == 'true';
|
||||
$this->_user->uses_gravatar = $this->_input['uses_gravatar'] == 'true';
|
||||
|
||||
if ($this->_user->uses_gravatar && !empty($this->_input['gravatar'])) {
|
||||
if ($this->_user->uses_gravatar && ! empty($this->_input['gravatar'])) {
|
||||
$this->_user->avatar_id = null;
|
||||
$this->_user->gravatar = $this->_input['gravatar'];
|
||||
} else {
|
||||
|
@ -106,21 +105,19 @@ class SaveAccountSettingsCommand extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
DB::transaction(function() {
|
||||
DB::transaction(function () {
|
||||
$this->_user->save();
|
||||
|
||||
// Sync email subscriptions
|
||||
$emailSubscriptions = $this->_user->emailSubscriptions->keyBy('activity_type');
|
||||
foreach ($this->_input['notifications'] as $notificationSetting) {
|
||||
|
||||
if (
|
||||
$notificationSetting['receive_emails'] &&
|
||||
!$emailSubscriptions->offsetExists($notificationSetting['activity_type'])
|
||||
! $emailSubscriptions->offsetExists($notificationSetting['activity_type'])
|
||||
) {
|
||||
$this->_user->emailSubscriptions()->create(['activity_type' => $notificationSetting['activity_type']]);
|
||||
|
||||
} elseif (
|
||||
!$notificationSetting['receive_emails'] &&
|
||||
! $notificationSetting['receive_emails'] &&
|
||||
$emailSubscriptions->offsetExists($notificationSetting['activity_type'])
|
||||
) {
|
||||
$emailSubscriptions->get($notificationSetting['activity_type'])->delete();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,15 +20,15 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Notification;
|
||||
use App\Contracts\Favouritable;
|
||||
use App\Models\Favourite;
|
||||
use App\Models\Track;
|
||||
use App\Facades\Notification;
|
||||
use App\Models\Album;
|
||||
use App\Models\Favourite;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\ResourceUser;
|
||||
use Auth;
|
||||
use DB;
|
||||
use App\Models\Track;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ToggleFavouriteCommand extends CommandBase
|
||||
{
|
||||
|
@ -98,14 +98,13 @@ class ToggleFavouriteCommand extends CommandBase
|
|||
// for the same resource at the same time, the cached values will still be correct with this method.
|
||||
|
||||
DB::table($resourceTable)->whereId($this->_resourceId)->update([
|
||||
'favourite_count' =>
|
||||
DB::raw('(
|
||||
'favourite_count' => DB::raw('(
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
favourites
|
||||
WHERE ' .
|
||||
$typeId.' = '.$this->_resourceId.')')
|
||||
WHERE '.
|
||||
$typeId.' = '.$this->_resourceId.')'),
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['is_favourited' => $isFavourited]);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Facades\Notification;
|
||||
use App\Models\Follower;
|
||||
use App\Models\ResourceUser;
|
||||
use Auth;
|
||||
use Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ToggleFollowingCommand extends CommandBase
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ class ToggleFollowingCommand extends CommandBase
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$typeId = $this->_resourceType . '_id';
|
||||
$typeId = $this->_resourceType.'_id';
|
||||
$existing = Follower::where($typeId, '=', $this->_resourceId)->whereUserId(Auth::user()->id)->first();
|
||||
$isFollowed = false;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,15 +20,13 @@
|
|||
|
||||
namespace App\Commands;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Gate;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Validator;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class UploadTrackCommand extends CommandBase
|
||||
{
|
||||
|
@ -106,7 +104,7 @@ class UploadTrackCommand extends CommandBase
|
|||
$trackFile = Request::file('track', null);
|
||||
}
|
||||
|
||||
if (!$this->_isReplacingTrack) {
|
||||
if (! $this->_isReplacingTrack) {
|
||||
$coverFile = Request::file('cover', null);
|
||||
}
|
||||
|
||||
|
@ -115,12 +113,13 @@ class UploadTrackCommand extends CommandBase
|
|||
$this->_track->version_upload_status = Track::STATUS_ERROR;
|
||||
$this->_track->update();
|
||||
}
|
||||
|
||||
return CommandResponse::fail(['track' => ['You must upload an audio file!']]);
|
||||
}
|
||||
|
||||
$audio = \AudioCache::get($trackFile->getPathname());
|
||||
|
||||
if (!$this->_isReplacingTrack) {
|
||||
if (! $this->_isReplacingTrack) {
|
||||
$this->_track = new Track();
|
||||
$this->_track->user_id = $this->_artist->id;
|
||||
// The title set here is a placeholder; it'll be replaced by ParseTrackTagsCommand
|
||||
|
@ -133,35 +132,34 @@ class UploadTrackCommand extends CommandBase
|
|||
}
|
||||
$this->_track->ensureDirectoryExists();
|
||||
|
||||
if (!is_dir(Config::get('ponyfm.files_directory').'/tmp')) {
|
||||
mkdir(Config::get('ponyfm.files_directory').'/tmp', 0755, true);
|
||||
if (! is_dir(config('ponyfm.files_directory').'/tmp')) {
|
||||
mkdir(config('ponyfm.files_directory').'/tmp', 0755, true);
|
||||
}
|
||||
|
||||
if (!is_dir(Config::get('ponyfm.files_directory').'/queued-tracks')) {
|
||||
mkdir(Config::get('ponyfm.files_directory').'/queued-tracks', 0755, true);
|
||||
if (! is_dir(config('ponyfm.files_directory').'/queued-tracks')) {
|
||||
mkdir(config('ponyfm.files_directory').'/queued-tracks', 0755, true);
|
||||
}
|
||||
|
||||
$trackFile = $trackFile->move(Config::get('ponyfm.files_directory') . '/queued-tracks', $this->_track->id . 'v' . $this->_version);
|
||||
$trackFile = $trackFile->move(config('ponyfm.files_directory').'/queued-tracks', $this->_track->id.'v'.$this->_version);
|
||||
|
||||
$input = Request::all();
|
||||
$input['track'] = $trackFile;
|
||||
|
||||
// Prevent the setting of the cover index for validation
|
||||
if (!$this->_isReplacingTrack && isset($coverFile)) {
|
||||
if (! $this->_isReplacingTrack && isset($coverFile)) {
|
||||
$input['cover'] = $coverFile;
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'track' =>
|
||||
'required|'
|
||||
. ($this->_allowLossy
|
||||
'track' => 'required|'
|
||||
.($this->_allowLossy
|
||||
? 'audio_format:flac,alac,pcm,adpcm,aac,mp3,vorbis|'
|
||||
: 'audio_format:flac,alac,pcm,adpcm|')
|
||||
. ($this->_allowShortTrack ? '' : 'min_duration:30|')
|
||||
. 'audio_channels:1,2',
|
||||
.($this->_allowShortTrack ? '' : 'min_duration:30|')
|
||||
.'audio_channels:1,2',
|
||||
];
|
||||
if (!$this->_isReplacingTrack) {
|
||||
array_merge($rules, [
|
||||
if (! $this->_isReplacingTrack) {
|
||||
$rules = array_merge($rules, [
|
||||
'cover' => 'image|mimes:png,jpeg|min_width:350|min_height:350',
|
||||
'auto_publish' => 'boolean',
|
||||
'title' => 'string',
|
||||
|
@ -169,14 +167,14 @@ class UploadTrackCommand extends CommandBase
|
|||
'genre' => 'string',
|
||||
'album' => 'string',
|
||||
'track_number' => 'integer',
|
||||
'released_at' => 'date_format:'.Carbon::ISO8601,
|
||||
'released_at' => 'date_format:'.CarbonInterface::ISO8601,
|
||||
'description' => 'string',
|
||||
'lyrics' => 'string',
|
||||
'is_vocal' => 'boolean',
|
||||
'is_explicit' => 'boolean',
|
||||
'is_downloadable' => 'boolean',
|
||||
'is_listed' => 'boolean',
|
||||
'metadata' => 'json'
|
||||
'metadata' => 'json',
|
||||
]);
|
||||
}
|
||||
$validator = \Validator::make($input, $rules);
|
||||
|
@ -188,15 +186,16 @@ class UploadTrackCommand extends CommandBase
|
|||
} else {
|
||||
$this->_track->delete();
|
||||
}
|
||||
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
||||
if (!$this->_isReplacingTrack) {
|
||||
if (! $this->_isReplacingTrack) {
|
||||
// If json_decode() isn't called here, Laravel will surround the JSON
|
||||
// string with quotes when storing it in the database, which breaks things.
|
||||
$this->_track->metadata = json_decode(Request::get('metadata', null));
|
||||
}
|
||||
$autoPublish = (bool)($input['auto_publish'] ?? $this->_autoPublishByDefault);
|
||||
$autoPublish = (bool) ($input['auto_publish'] ?? $this->_autoPublishByDefault);
|
||||
$this->_track->source = $this->_customTrackSource ?? $source;
|
||||
$this->_track->save();
|
||||
|
||||
|
@ -206,7 +205,7 @@ class UploadTrackCommand extends CommandBase
|
|||
$input['cover'] = null;
|
||||
}
|
||||
|
||||
if (!$this->_isReplacingTrack) {
|
||||
if (! $this->_isReplacingTrack) {
|
||||
// Parse any tags in the uploaded files.
|
||||
$parseTagsCommand = new ParseTrackTagsCommand($this->_track, $trackFile, $input);
|
||||
$result = $parseTagsCommand->execute();
|
||||
|
@ -215,11 +214,13 @@ class UploadTrackCommand extends CommandBase
|
|||
$this->_track->version_upload_status = Track::STATUS_ERROR;
|
||||
$this->_track->update();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$generateTrackFiles = new GenerateTrackFilesCommand($this->_track, $trackFile, $autoPublish, true, $this->_isReplacingTrack, $this->_version);
|
||||
|
||||
return $generateTrackFiles->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -40,7 +40,6 @@ class BootstrapLocalEnvironment extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -23,8 +23,8 @@ namespace App\Console\Commands;
|
|||
use App\Models\ShowSong;
|
||||
use App\Models\Track;
|
||||
use App\Models\TrackType;
|
||||
use DB;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ClassifyMLPMA extends Command
|
||||
|
@ -53,7 +53,6 @@ class ClassifyMLPMA extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -74,7 +73,7 @@ class ClassifyMLPMA extends Command
|
|||
|
||||
$this->comment('Importing tracks...');
|
||||
|
||||
$totalTracks = sizeof($tracks);
|
||||
$totalTracks = count($tracks);
|
||||
|
||||
$fileToStartAt = (int) $this->option('startAt') - 1;
|
||||
$this->comment("Skipping $fileToStartAt files...".PHP_EOL);
|
||||
|
@ -88,7 +87,6 @@ class ClassifyMLPMA extends Command
|
|||
|
||||
$parsedTags = json_decode($track->parsed_tags, true);
|
||||
|
||||
|
||||
//==========================================================================================================
|
||||
// Original, show song remix, fan song remix, show audio remix, or ponified song?
|
||||
//==========================================================================================================
|
||||
|
@ -103,7 +101,6 @@ class ClassifyMLPMA extends Command
|
|||
")
|
||||
->get();
|
||||
|
||||
|
||||
// If it has "Ingram" in the name, it's definitely an official song remix.
|
||||
if (Str::contains(Str::lower($track->filename), 'ingram')) {
|
||||
$this->info('This is an official song remix!');
|
||||
|
@ -115,8 +112,7 @@ class ClassifyMLPMA extends Command
|
|||
$parsedTags
|
||||
);
|
||||
|
||||
|
||||
// If it has "remix" in the name, it's definitely a remix.
|
||||
// If it has "remix" in the name, it's definitely a remix.
|
||||
} else {
|
||||
if (Str::contains(Str::lower($sanitizedTrackTitle), 'remix')) {
|
||||
$this->info('This is some kind of remix!');
|
||||
|
@ -128,7 +124,7 @@ class ClassifyMLPMA extends Command
|
|||
$parsedTags
|
||||
);
|
||||
|
||||
// No idea what this is. Have the pony at the terminal figure it out!
|
||||
// No idea what this is. Have the pony at the terminal figure it out!
|
||||
} else {
|
||||
list($trackType, $linkedSongIds) = $this->classifyTrack(
|
||||
$track->filename,
|
||||
|
@ -139,7 +135,6 @@ class ClassifyMLPMA extends Command
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================================================
|
||||
// Attach the data and publish the track!
|
||||
//==========================================================================================================
|
||||
|
@ -150,7 +145,7 @@ class ClassifyMLPMA extends Command
|
|||
$track->published_at = $parsedTags['released_at'];
|
||||
$track->save();
|
||||
|
||||
if (sizeof($linkedSongIds) > 0) {
|
||||
if (count($linkedSongIds) > 0) {
|
||||
$track->showSongs()->sync($linkedSongIds);
|
||||
}
|
||||
|
||||
|
@ -167,24 +162,22 @@ class ClassifyMLPMA extends Command
|
|||
* @param bool|false $isRemixOfOfficialTrack
|
||||
* @return array
|
||||
*/
|
||||
protected function classifyTrack($filename, $officialSongs, $isRemixOfOfficialTrack = false, $tags)
|
||||
protected function classifyTrack($filename, $officialSongs, $isRemixOfOfficialTrack, $tags)
|
||||
{
|
||||
$trackTypeId = null;
|
||||
$linkedSongIds = [];
|
||||
|
||||
|
||||
foreach ($officialSongs as $song) {
|
||||
$this->comment('=> Matched official song: ['.$song->id.'] '.$song->title);
|
||||
}
|
||||
|
||||
|
||||
if ($isRemixOfOfficialTrack && sizeof($officialSongs) === 1) {
|
||||
if ($isRemixOfOfficialTrack && count($officialSongs) === 1) {
|
||||
$linkedSongIds = [$officialSongs[0]->id];
|
||||
} else {
|
||||
if ($isRemixOfOfficialTrack && sizeof($officialSongs) > 1) {
|
||||
if ($isRemixOfOfficialTrack && count($officialSongs) > 1) {
|
||||
$this->question('Multiple official songs matched! Please enter the ID of the correct one.');
|
||||
} else {
|
||||
if (sizeof($officialSongs) > 0) {
|
||||
if (count($officialSongs) > 0) {
|
||||
$this->question('This looks like a remix of an official song!');
|
||||
$this->question('Press "r" if the match above is right!');
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Kelvin Zhang
|
||||
* Copyright (C) 2015 Kelvin Zhang.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\TrackFile;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class ClearTrackCache extends Command
|
||||
{
|
||||
|
@ -45,7 +45,6 @@ class ClearTrackCache extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -76,7 +75,7 @@ class ClearTrackCache extends Command
|
|||
if (count($trackFiles) === 0) {
|
||||
$this->info('No tracks found. Exiting.');
|
||||
} else {
|
||||
if ($this->option('force') || $this->confirm(count($trackFiles) . ' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) {
|
||||
if ($this->option('force') || $this->confirm(count($trackFiles).' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) {
|
||||
$count = 0;
|
||||
|
||||
foreach ($trackFiles as $trackFile) {
|
||||
|
@ -89,10 +88,10 @@ class ClearTrackCache extends Command
|
|||
$count++;
|
||||
File::delete($trackFile->getFile());
|
||||
|
||||
$this->info('Deleted ' . $trackFile->getFile());
|
||||
$this->info('Deleted '.$trackFile->getFile());
|
||||
}
|
||||
}
|
||||
$this->info($count . ' files deleted. Deletion complete. Exiting.');
|
||||
$this->info($count.' files deleted. Deletion complete. Exiting.');
|
||||
} else {
|
||||
$this->info('Deletion cancelled. Exiting.');
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Config;
|
||||
use DB;
|
||||
use File;
|
||||
use App\Models\Image;
|
||||
use getID3;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Image;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class FixMLPMAImages extends Command
|
||||
|
@ -47,7 +47,6 @@ class FixMLPMAImages extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -56,7 +55,6 @@ class FixMLPMAImages extends Command
|
|||
|
||||
protected $currentFile;
|
||||
|
||||
|
||||
/**
|
||||
* File extensions to ignore when importing the archive.
|
||||
*
|
||||
|
@ -69,7 +67,7 @@ class FixMLPMAImages extends Command
|
|||
'txt',
|
||||
'rtf',
|
||||
'wma',
|
||||
'wmv'
|
||||
'wmv',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -79,22 +77,21 @@ class FixMLPMAImages extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$mlpmaPath = Config::get('ponyfm.files_directory').'/mlpma';
|
||||
$tmpPath = Config::get('ponyfm.files_directory').'/tmp';
|
||||
$mlpmaPath = config('ponyfm.files_directory').'/mlpma';
|
||||
$tmpPath = config('ponyfm.files_directory').'/tmp';
|
||||
|
||||
$this->comment('Enumerating MLP Music Archive source files...');
|
||||
$files = File::allFiles($mlpmaPath);
|
||||
$this->info(sizeof($files).' files found!');
|
||||
$this->info(count($files).' files found!');
|
||||
|
||||
$this->comment('Importing tracks...');
|
||||
$totalFiles = sizeof($files);
|
||||
$totalFiles = count($files);
|
||||
$fileToStartAt = (int) $this->option('startAt') - 1;
|
||||
|
||||
$this->comment("Skipping $fileToStartAt files...".PHP_EOL);
|
||||
$files = array_slice($files, $fileToStartAt);
|
||||
$this->currentFile = $fileToStartAt;
|
||||
|
||||
|
||||
foreach ($files as $file) {
|
||||
$this->currentFile++;
|
||||
|
||||
|
@ -110,7 +107,6 @@ class FixMLPMAImages extends Command
|
|||
->first();
|
||||
$artistId = $importedTrack->user_id;
|
||||
|
||||
|
||||
//==========================================================================================================
|
||||
// Extract the original tags.
|
||||
//==========================================================================================================
|
||||
|
@ -119,7 +115,6 @@ class FixMLPMAImages extends Command
|
|||
// all tags read by getID3, including the cover art
|
||||
$allTags = $getId3->analyze($file->getPathname());
|
||||
|
||||
|
||||
//==========================================================================================================
|
||||
// Extract the cover art, if any exists.
|
||||
//==========================================================================================================
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use DB;
|
||||
use File;
|
||||
use Input;
|
||||
use getID3;
|
||||
use App\Commands\UploadTrackCommand;
|
||||
use App\Models\Album;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Image;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Album;
|
||||
use App\Commands\UploadTrackCommand;
|
||||
use Carbon\Carbon;
|
||||
use getID3;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Input;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class ImportEQBeats extends Command
|
||||
|
@ -69,7 +69,7 @@ class ImportEQBeats extends Command
|
|||
public function handleInterrupt($signo)
|
||||
{
|
||||
$this->error('Import aborted!');
|
||||
$this->error('Resume it from here using: --startAt=' . $this->currentFile);
|
||||
$this->error('Resume it from here using: --startAt='.$this->currentFile);
|
||||
$this->isInterrupted = true;
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,15 @@ class ImportEQBeats extends Command
|
|||
pcntl_signal(SIGINT, [$this, 'handleInterrupt']);
|
||||
|
||||
$archivePath = $this->argument('archiveFolder');
|
||||
$tmpPath = Config::get('ponyfm.files_directory').'/tmp';
|
||||
$tmpPath = config('ponyfm.files_directory').'/tmp';
|
||||
|
||||
if (!File::exists($tmpPath)) {
|
||||
if (! File::exists($tmpPath)) {
|
||||
File::makeDirectory($tmpPath);
|
||||
}
|
||||
|
||||
$UNKNOWN_GENRE = Genre::firstOrCreate([
|
||||
'name' => 'Unknown',
|
||||
'slug' => 'unknown'
|
||||
'slug' => 'unknown',
|
||||
]);
|
||||
|
||||
//==========================================================================================================
|
||||
|
@ -102,18 +102,18 @@ class ImportEQBeats extends Command
|
|||
//==========================================================================================================
|
||||
$this->comment('Enumerating files...');
|
||||
$files = File::allFiles($archivePath);
|
||||
$this->info(sizeof($files) . ' files found!');
|
||||
$this->info(count($files).' files found!');
|
||||
|
||||
$this->comment('Enumerating artists...');
|
||||
$artists = File::directories($archivePath);
|
||||
$this->info(sizeof($artists) . ' artists found!');
|
||||
$this->info(count($artists).' artists found!');
|
||||
|
||||
$this->comment('Importing tracks...');
|
||||
|
||||
$totalFiles = sizeof($files);
|
||||
$totalFiles = count($files);
|
||||
|
||||
$fileToStartAt = (int)$this->option('startAt') - 1;
|
||||
$this->comment("Skipping $fileToStartAt files..." . PHP_EOL);
|
||||
$fileToStartAt = (int) $this->option('startAt') - 1;
|
||||
$this->comment("Skipping $fileToStartAt files...".PHP_EOL);
|
||||
|
||||
$files = array_slice($files, $fileToStartAt);
|
||||
$this->currentFile = $fileToStartAt;
|
||||
|
@ -127,20 +127,20 @@ class ImportEQBeats extends Command
|
|||
break;
|
||||
}
|
||||
|
||||
$this->comment('[' . $this->currentFile . '/' . $totalFiles . '] Importing track [' . $file->getFilename() . ']...');
|
||||
$this->comment('['.$this->currentFile.'/'.$totalFiles.'] Importing track ['.$file->getFilename().']...');
|
||||
|
||||
if (!in_array($file->getExtension(), $this->allowedExtensions)) {
|
||||
$this->comment('This is not an audio file! Skipping...' . PHP_EOL);
|
||||
if (! in_array($file->getExtension(), $this->allowedExtensions)) {
|
||||
$this->comment('This is not an audio file! Skipping...'.PHP_EOL);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->info('Path to file: ' . $file->getRelativePath());
|
||||
$this->info('Path to file: '.$file->getRelativePath());
|
||||
$path_components = explode(DIRECTORY_SEPARATOR, $file->getRelativePath());
|
||||
$artist_name = $path_components[0];
|
||||
$album_name = array_key_exists(1, $path_components) ? $path_components[1] : null;
|
||||
|
||||
$this->info('Artist: ' . $artist_name);
|
||||
$this->info('Album: ' . $album_name);
|
||||
$this->info('Artist: '.$artist_name);
|
||||
$this->info('Album: '.$album_name);
|
||||
|
||||
//==========================================================================================================
|
||||
// Analyse the track so we can find the MIME type and album art
|
||||
|
@ -170,7 +170,7 @@ class ImportEQBeats extends Command
|
|||
$parsedTags['title'] = substr($fileName, strpos($fileName, $hyphen) + strlen($hyphen));
|
||||
}
|
||||
|
||||
$this->info('Title: ' . $parsedTags['title']);
|
||||
$this->info('Title: '.$parsedTags['title']);
|
||||
|
||||
//==========================================================================================================
|
||||
// Determine the release date.
|
||||
|
@ -183,11 +183,9 @@ class ImportEQBeats extends Command
|
|||
|
||||
if ($taggedYear !== null && $modifiedDate->year === $taggedYear) {
|
||||
$releasedAt = $modifiedDate;
|
||||
|
||||
} else if ($taggedYear !== null && $modifiedDate->year !== $taggedYear) {
|
||||
} elseif ($taggedYear !== null && $modifiedDate->year !== $taggedYear) {
|
||||
$this->warn('Release years don\'t match! Using the tagged year...');
|
||||
$releasedAt = Carbon::create($taggedYear);
|
||||
|
||||
} else {
|
||||
// $taggedYear is null
|
||||
$this->warn('This track isn\'t tagged with its release year! Using the track\'s last modified date...');
|
||||
|
@ -215,7 +213,6 @@ class ImportEQBeats extends Command
|
|||
$genre->restore();
|
||||
}
|
||||
$genreId = $genre->id;
|
||||
|
||||
} else {
|
||||
$genre = new Genre();
|
||||
$genre->name = $genreName;
|
||||
|
@ -224,10 +221,9 @@ class ImportEQBeats extends Command
|
|||
$genreId = $genre->id;
|
||||
$this->comment('Created a new genre!');
|
||||
}
|
||||
|
||||
} else {
|
||||
$genreId = $UNKNOWN_GENRE->id; // "Unknown" genre ID
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================================================
|
||||
// Check to see if we have this track already, if so, compare hashes of the two files
|
||||
|
@ -236,7 +232,7 @@ class ImportEQBeats extends Command
|
|||
$artist = User::where('display_name', '=', $artist_name)->first();
|
||||
$artistId = null;
|
||||
|
||||
$this->comment("Checking for duplicates");
|
||||
$this->comment('Checking for duplicates');
|
||||
|
||||
if ($artist) {
|
||||
$artistId = $artist->id;
|
||||
|
@ -254,7 +250,7 @@ class ImportEQBeats extends Command
|
|||
$importFormat = $this->getFormat($file->getExtension());
|
||||
if ($importFormat == null) {
|
||||
// No idea what this is, skip file
|
||||
$this->comment(sprintf("Not an audio file (%s), skipping...", $importFormat));
|
||||
$this->comment(sprintf('Not an audio file (%s), skipping...', $importFormat));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -273,7 +269,7 @@ class ImportEQBeats extends Command
|
|||
// Source is lossless, is the existing track lossy?
|
||||
if ($existingFile->isMasterLossy()) {
|
||||
// Cool! Let's replace it
|
||||
$this->comment('Replacing (' . $existingTrack->id . ') ' . $existingTrack->title);
|
||||
$this->comment('Replacing ('.$existingTrack->id.') '.$existingTrack->title);
|
||||
|
||||
$this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']);
|
||||
|
||||
|
@ -282,16 +278,15 @@ class ImportEQBeats extends Command
|
|||
}
|
||||
|
||||
continue;
|
||||
|
||||
} else {
|
||||
$this->comment("Found existing file");
|
||||
$this->comment('Found existing file');
|
||||
|
||||
// Found a matching format, are they the same?
|
||||
// Before we check it, see if it came from MLPMA
|
||||
// We're only replacing tracks with the same format if they're archived
|
||||
$mlpmaTrack = DB::table('mlpma_tracks')->where('track_id', '=', $existingTrack->id)->first();
|
||||
|
||||
if (!is_null($mlpmaTrack)) {
|
||||
if (! is_null($mlpmaTrack)) {
|
||||
$getId3_source = new getID3;
|
||||
|
||||
$getId3_source->option_md5_data = true;
|
||||
|
@ -307,8 +302,8 @@ class ImportEQBeats extends Command
|
|||
$importHash = array_key_exists('md5_data_source', $sourceWithMd5) ? $sourceWithMd5['md5_data_source'] : $sourceWithMd5['md5_data'];
|
||||
$targetHash = array_key_exists('md5_data_source', $existingFileTags) ? $existingFileTags['md5_data_source'] : $existingFileTags['md5_data'];
|
||||
|
||||
$this->info("Archive hash: " . $importHash);
|
||||
$this->info("Pony.fm hash: " . $targetHash);
|
||||
$this->info('Archive hash: '.$importHash);
|
||||
$this->info('Pony.fm hash: '.$targetHash);
|
||||
|
||||
if ($importHash == $targetHash) {
|
||||
// Audio is identical, no need to reupload
|
||||
|
@ -319,28 +314,30 @@ class ImportEQBeats extends Command
|
|||
if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) {
|
||||
$existingTrack->description = $parsedTags['comments'];
|
||||
$changedMetadata = true;
|
||||
$this->comment("Updated description");
|
||||
$this->comment('Updated description');
|
||||
}
|
||||
|
||||
if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) {
|
||||
$existingTrack->lyrics = $parsedTags['lyrics'];
|
||||
$changedMetadata = true;
|
||||
$this->comment("Updated lyrics");
|
||||
$this->comment('Updated lyrics');
|
||||
}
|
||||
|
||||
if ($changedMetadata) $existingTrack->save();
|
||||
if ($changedMetadata) {
|
||||
$existingTrack->save();
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
// Audio is different, let's replace it
|
||||
$this->comment('Replacing (' . $existingTrack->id . ') ' . $existingTrack->title);
|
||||
$this->comment('Replacing ('.$existingTrack->id.') '.$existingTrack->title);
|
||||
|
||||
$this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']);
|
||||
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$this->comment("Not replacing, user uploaded");
|
||||
$this->comment('Not replacing, user uploaded');
|
||||
|
||||
// We can update the metadata though
|
||||
$changedMetadata = false;
|
||||
|
@ -348,28 +345,30 @@ class ImportEQBeats extends Command
|
|||
if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) {
|
||||
$existingTrack->description = $parsedTags['comments'];
|
||||
$changedMetadata = true;
|
||||
$this->comment("Updated description");
|
||||
$this->comment('Updated description');
|
||||
}
|
||||
|
||||
if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) {
|
||||
$existingTrack->lyrics = $parsedTags['lyrics'];
|
||||
$changedMetadata = true;
|
||||
$this->comment("Updated lyrics");
|
||||
$this->comment('Updated lyrics');
|
||||
}
|
||||
|
||||
if ($changedMetadata) $existingTrack->save();
|
||||
if ($changedMetadata) {
|
||||
$existingTrack->save();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->comment("No duplicates");
|
||||
$this->comment('No duplicates');
|
||||
}
|
||||
|
||||
//==========================================================================================================
|
||||
// Create new user for the artist if one doesn't exist
|
||||
//==========================================================================================================
|
||||
|
||||
if (!$artist) {
|
||||
if (! $artist) {
|
||||
$artist = new User;
|
||||
$artist->display_name = $artist_name;
|
||||
$artist->email = null;
|
||||
|
@ -379,8 +378,8 @@ class ImportEQBeats extends Command
|
|||
|
||||
$slugExists = User::where('slug', '=', $artist->slug)->first();
|
||||
if ($slugExists) {
|
||||
$this->error('Horsefeathers! The slug ' . $artist->slug . ' is already taken!');
|
||||
$artist->slug = $artist->slug . '-' . Str::random(4);
|
||||
$this->error('Horsefeathers! The slug '.$artist->slug.' is already taken!');
|
||||
$artist->slug = $artist->slug.'-'.Str::random(4);
|
||||
}
|
||||
|
||||
$artist->save();
|
||||
|
@ -396,7 +395,7 @@ class ImportEQBeats extends Command
|
|||
|
||||
if (array_key_exists('comments', $allTags) && array_key_exists('picture', $allTags['comments'])) {
|
||||
$image = $allTags['comments']['picture'][0];
|
||||
} else if (array_key_exists('id3v2', $allTags) && array_key_exists('APIC', $allTags['id3v2'])) {
|
||||
} elseif (array_key_exists('id3v2', $allTags) && array_key_exists('APIC', $allTags['id3v2'])) {
|
||||
$image = $allTags['id3v2']['APIC'][0];
|
||||
}
|
||||
|
||||
|
@ -415,8 +414,8 @@ class ImportEQBeats extends Command
|
|||
}
|
||||
}
|
||||
// write temporary image file
|
||||
$imageFilename = $file->getFilename() . ".cover.$extension";
|
||||
$imageFilePath = "$tmpPath/" . $imageFilename;
|
||||
$imageFilename = $file->getFilename().".cover.$extension";
|
||||
$imageFilePath = "$tmpPath/".$imageFilename;
|
||||
File::put($imageFilePath, $image['data']);
|
||||
|
||||
$imageFile = new UploadedFile($imageFilePath, $imageFilename, $image['image_mime'], null, null, true);
|
||||
|
@ -437,13 +436,13 @@ class ImportEQBeats extends Command
|
|||
->where('title', '=', $albumName)
|
||||
->first();
|
||||
|
||||
if (!$album) {
|
||||
if (! $album) {
|
||||
$album = new Album;
|
||||
|
||||
$album->title = $albumName;
|
||||
$album->user_id = $artist->id;
|
||||
$album->cover_id = $coverId;
|
||||
$album->description = "";
|
||||
$album->description = '';
|
||||
|
||||
$album->save();
|
||||
}
|
||||
|
@ -460,8 +459,8 @@ class ImportEQBeats extends Command
|
|||
|
||||
$mime = $allTags['mime_type'];
|
||||
|
||||
File::copy($file->getPathname(), "$tmpPath/" . $file->getFilename());
|
||||
$trackFile = new UploadedFile("$tmpPath/" . $file->getFilename(), $file->getFilename(), $mime, null, null, true);
|
||||
File::copy($file->getPathname(), "$tmpPath/".$file->getFilename());
|
||||
$trackFile = new UploadedFile("$tmpPath/".$file->getFilename(), $file->getFilename(), $mime, null, null, true);
|
||||
|
||||
$upload = new UploadTrackCommand(true);
|
||||
$upload->_file = $trackFile;
|
||||
|
@ -479,18 +478,18 @@ class ImportEQBeats extends Command
|
|||
$track->is_downloadable = true;
|
||||
$track->is_vocal = $isVocal;
|
||||
$track->license_id = 2;
|
||||
$track->description = "";
|
||||
$track->lyrics = "";
|
||||
$track->description = '';
|
||||
$track->lyrics = '';
|
||||
|
||||
if (!is_null($parsedTags['comments'])) {
|
||||
if (! is_null($parsedTags['comments'])) {
|
||||
$track->description = $parsedTags['comments'];
|
||||
}
|
||||
|
||||
if (!is_null($parsedTags['lyrics'])) {
|
||||
if (! is_null($parsedTags['lyrics'])) {
|
||||
$track->lyrics = $parsedTags['lyrics'];
|
||||
}
|
||||
|
||||
if (!is_null($parsedTags['title'])) {
|
||||
if (! is_null($parsedTags['title'])) {
|
||||
$track->title = $parsedTags['title'];
|
||||
}
|
||||
|
||||
|
@ -501,7 +500,7 @@ class ImportEQBeats extends Command
|
|||
->insert([
|
||||
'track_id' => $result->getResponse()['id'],
|
||||
'path' => $file->getRelativePath(),
|
||||
'filename' => iconv("UTF-8", "ISO-8859-1//TRANSLIT", $file->getFilename()),
|
||||
'filename' => iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $file->getFilename()),
|
||||
'extension' => $file->getExtension(),
|
||||
'imported_at' => Carbon::now(),
|
||||
'parsed_tags' => json_encode($parsedTags),
|
||||
|
@ -509,18 +508,21 @@ class ImportEQBeats extends Command
|
|||
]);
|
||||
}
|
||||
|
||||
echo PHP_EOL . PHP_EOL;
|
||||
echo PHP_EOL.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
protected function hashAudio($filepath) {
|
||||
protected function hashAudio($filepath)
|
||||
{
|
||||
$hash = hash_file('crc32b', $filepath);
|
||||
$array = unpack('N', pack('H*', $hash));
|
||||
|
||||
return $array[1];
|
||||
}
|
||||
|
||||
protected function getFormat($extension) {
|
||||
foreach(Track::$Formats as $name => $format) {
|
||||
protected function getFormat($extension)
|
||||
{
|
||||
foreach (Track::$Formats as $name => $format) {
|
||||
if ($format['extension'] == $extension) {
|
||||
return $name;
|
||||
}
|
||||
|
@ -565,7 +567,6 @@ class ImportEQBeats extends Command
|
|||
$rawTags = [];
|
||||
}
|
||||
|
||||
|
||||
return [$parsedTags, $rawTags];
|
||||
}
|
||||
|
||||
|
@ -623,7 +624,7 @@ class ImportEQBeats extends Command
|
|||
'comments' => $comment,
|
||||
'lyrics' => isset($tags['unsynchronised_lyric']) ? $tags['unsynchronised_lyric'][0] : null,
|
||||
],
|
||||
$tags
|
||||
$tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -667,7 +668,7 @@ class ImportEQBeats extends Command
|
|||
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
|
||||
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
|
||||
],
|
||||
$tags
|
||||
$tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -703,7 +704,7 @@ class ImportEQBeats extends Command
|
|||
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
|
||||
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
|
||||
],
|
||||
$tags
|
||||
$tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -736,7 +737,7 @@ class ImportEQBeats extends Command
|
|||
// YYYY-MM
|
||||
case 7:
|
||||
try {
|
||||
return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString))
|
||||
return Carbon::createFromFormat('Y m', str_replace('-', ' ', $dateString))
|
||||
->day(1);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
|
@ -745,7 +746,7 @@ class ImportEQBeats extends Command
|
|||
// YYYY-MM-DD
|
||||
case 10:
|
||||
try {
|
||||
return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString));
|
||||
return Carbon::createFromFormat('Y m d', str_replace('-', ' ', $dateString));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -762,7 +763,8 @@ class ImportEQBeats extends Command
|
|||
}
|
||||
}
|
||||
|
||||
protected function replaceTrack($toBeUploaded, $targetTrack, $artist, $mime) {
|
||||
protected function replaceTrack($toBeUploaded, $targetTrack, $artist, $mime)
|
||||
{
|
||||
Auth::loginUsingId($artist->id);
|
||||
|
||||
$trackFile = new UploadedFile($toBeUploaded->getPathname(), $toBeUploaded->getFilename(), $mime, null, null, true);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,6 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Commands\MergeAccountsCommand;
|
||||
use App\Models\Album;
|
||||
use App\Models\Comment;
|
||||
|
@ -36,6 +32,10 @@ use App\Models\ResourceLogItem;
|
|||
use App\Models\ResourceUser;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MergeAccounts extends Command
|
||||
{
|
||||
|
@ -57,7 +57,6 @@ class MergeAccounts extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -81,9 +80,10 @@ class MergeAccounts extends Command
|
|||
if (null !== $sourceAccount->getAccessToken()) {
|
||||
$this->warn("WARNING: The source account (ID {$sourceAccountId}) is linked to a Poniverse account! Normally, the destination account should be the one that's linked to a Poniverse account as that's the one that the artist will be logging into.");
|
||||
$this->line('');
|
||||
$this->warn("If you continue with this merge, the Poniverse account linked to the source Pony.fm account will no longer be able to log into Pony.fm.");
|
||||
if (!$this->confirm('Continue merging this set of source and destination accounts?')){
|
||||
$this->warn('If you continue with this merge, the Poniverse account linked to the source Pony.fm account will no longer be able to log into Pony.fm.');
|
||||
if (! $this->confirm('Continue merging this set of source and destination accounts?')) {
|
||||
$this->error('Merge aborted.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -91,8 +91,9 @@ class MergeAccounts extends Command
|
|||
if (null === $destinationAccount->getAccessToken()) {
|
||||
$this->warn("WARNING: The destination account (ID {$destinationAccountId}) is not linked to a Poniverse account!");
|
||||
$this->warn("This is normal if you're merging two archived profiles but not if you're helping an artist claim their profile.");
|
||||
if (!$this->confirm('Continue merging this set of source and destination accounts?')){
|
||||
if (! $this->confirm('Continue merging this set of source and destination accounts?')) {
|
||||
$this->error('Merge aborted.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +102,7 @@ class MergeAccounts extends Command
|
|||
|
||||
$command = new MergeAccountsCommand($sourceAccount, $destinationAccount);
|
||||
$command->execute();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,9 +22,9 @@ namespace App\Console\Commands;
|
|||
|
||||
use App\Models\Image;
|
||||
use App\Models\ResourceLogItem;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class MigrateOldData extends Command
|
||||
|
@ -45,7 +45,6 @@ class MigrateOldData extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -69,15 +68,15 @@ class MigrateOldData extends Command
|
|||
$this->info('Syncing Users');
|
||||
foreach ($oldUsers as $user) {
|
||||
$displayName = $user->display_name;
|
||||
if (!$displayName) {
|
||||
if (! $displayName) {
|
||||
$displayName = $user->username;
|
||||
}
|
||||
|
||||
if (!$displayName) {
|
||||
if (! $displayName) {
|
||||
$displayName = $user->username;
|
||||
}
|
||||
|
||||
if (!$displayName) {
|
||||
if (! $displayName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -94,11 +93,11 @@ class MigrateOldData extends Command
|
|||
'username' => $user->username,
|
||||
'uses_gravatar' => $user->uses_gravatar,
|
||||
'gravatar' => $user->gravatar,
|
||||
'avatar_id' => null
|
||||
'avatar_id' => null,
|
||||
]);
|
||||
|
||||
$coverId = null;
|
||||
if (!$user->uses_gravatar) {
|
||||
if (! $user->uses_gravatar) {
|
||||
try {
|
||||
$coverFile = $this->getIdDirectory('users', $user->id).'/'.$user->id.'_.png';
|
||||
$coverId = Image::upload(new UploadedFile(
|
||||
|
@ -119,7 +118,7 @@ class MigrateOldData extends Command
|
|||
DB::table('genres')->insert([
|
||||
'id' => $genre->id,
|
||||
'name' => $genre->title,
|
||||
'slug' => $genre->slug
|
||||
'slug' => $genre->slug,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -139,7 +138,7 @@ class MigrateOldData extends Command
|
|||
'id' => $playlist->id,
|
||||
'user_id' => $playlist->user_id,
|
||||
'view_count' => 0,
|
||||
'download_count' => 0
|
||||
'download_count' => 0,
|
||||
]);
|
||||
|
||||
foreach ($logViews as $logItem) {
|
||||
|
@ -164,7 +163,7 @@ class MigrateOldData extends Command
|
|||
'album_id' => $logItem->album_id,
|
||||
'created_at' => $logItem->created_at,
|
||||
'ip_address' => $logItem->ip_address,
|
||||
'track_format_id' => $logItem->track_file_format_id - 1
|
||||
'track_format_id' => $logItem->track_file_format_id - 1,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Could insert log item for album '.$playlist->id.' because '.$e->getMessage());
|
||||
|
@ -219,7 +218,7 @@ class MigrateOldData extends Command
|
|||
'duration' => $track->duration,
|
||||
'view_count' => 0,
|
||||
'play_count' => 0,
|
||||
'download_count' => 0
|
||||
'download_count' => 0,
|
||||
]);
|
||||
|
||||
foreach ($trackLogViews as $logItem) {
|
||||
|
@ -229,7 +228,7 @@ class MigrateOldData extends Command
|
|||
'log_type' => ResourceLogItem::VIEW,
|
||||
'track_id' => $logItem->track_id,
|
||||
'created_at' => $logItem->created_at,
|
||||
'ip_address' => $logItem->ip_address
|
||||
'ip_address' => $logItem->ip_address,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage());
|
||||
|
@ -243,7 +242,7 @@ class MigrateOldData extends Command
|
|||
'log_type' => ResourceLogItem::PLAY,
|
||||
'track_id' => $logItem->track_id,
|
||||
'created_at' => $logItem->created_at,
|
||||
'ip_address' => $logItem->ip_address
|
||||
'ip_address' => $logItem->ip_address,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage());
|
||||
|
@ -258,7 +257,7 @@ class MigrateOldData extends Command
|
|||
'track_id' => $logItem->track_id,
|
||||
'created_at' => $logItem->created_at,
|
||||
'ip_address' => $logItem->ip_address,
|
||||
'track_format_id' => $logItem->track_file_format_id - 1
|
||||
'track_format_id' => $logItem->track_file_format_id - 1,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage());
|
||||
|
@ -272,7 +271,7 @@ class MigrateOldData extends Command
|
|||
DB::table('show_song_track')->insert([
|
||||
'id' => $song->id,
|
||||
'show_song_id' => $song->song_id,
|
||||
'track_id' => $song->track_id
|
||||
'track_id' => $song->track_id,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Could insert show track item for '.$song->track_id.' because '.$e->getMessage());
|
||||
|
@ -321,7 +320,7 @@ class MigrateOldData extends Command
|
|||
'playlist_id' => $logItem->playlist_id,
|
||||
'created_at' => $logItem->created_at,
|
||||
'ip_address' => $logItem->ip_address,
|
||||
'track_format_id' => $logItem->track_file_format_id - 1
|
||||
'track_format_id' => $logItem->track_file_format_id - 1,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Could insert log item for playlist '.$playlist->id.' because '.$e->getMessage());
|
||||
|
@ -338,7 +337,7 @@ class MigrateOldData extends Command
|
|||
'updated_at' => $playlistTrack->updated_at,
|
||||
'position' => $playlistTrack->position,
|
||||
'playlist_id' => $playlistTrack->playlist_id,
|
||||
'track_id' => $playlistTrack->track_id
|
||||
'track_id' => $playlistTrack->track_id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -356,7 +355,7 @@ class MigrateOldData extends Command
|
|||
'track_id' => $comment->track_id,
|
||||
'album_id' => $comment->album_id,
|
||||
'playlist_id' => $comment->playlist_id,
|
||||
'profile_id' => $comment->profile_id
|
||||
'profile_id' => $comment->profile_id,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
$this->error('Could not sync comment '.$comment->id.' because '.$e->getMessage());
|
||||
|
@ -400,6 +399,6 @@ class MigrateOldData extends Command
|
|||
{
|
||||
$dir = (string) (floor($id / 100) * 100);
|
||||
|
||||
return \Config::get('ponyfm.files_directory').'/'.$type.'/'.$dir;
|
||||
return config('ponyfm.files_directory').'/'.$type.'/'.$dir;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,9 +20,9 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Console\Command;
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class PoniverseApiSetup extends Command
|
||||
|
@ -43,7 +43,6 @@ class PoniverseApiSetup extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -74,7 +73,7 @@ class PoniverseApiSetup extends Command
|
|||
$response = $client->post('api-credentials', [
|
||||
'headers' => ['accept' => 'application/json'],
|
||||
'auth' => [$username, $password],
|
||||
'query' => ['app' => 'Pony.fm']
|
||||
'query' => ['app' => 'Pony.fm'],
|
||||
]);
|
||||
} catch (ClientException $e) {
|
||||
if ($e->getResponse()->getStatusCode() === 401) {
|
||||
|
@ -97,7 +96,6 @@ class PoniverseApiSetup extends Command
|
|||
$this->info('Client ID and secret set!');
|
||||
}
|
||||
|
||||
|
||||
protected function setEnvironmentVariable($key, $oldValue, $newValue)
|
||||
{
|
||||
$path = base_path('.env');
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,8 +20,8 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class RebuildArtists extends Command
|
||||
{
|
||||
|
@ -41,7 +41,6 @@ class RebuildArtists extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Kelvin Zhang
|
||||
* Copyright (C) 2015 Kelvin Zhang.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,9 +20,9 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\TrackFile;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class RebuildFilesizes extends Command
|
||||
{
|
||||
|
@ -43,7 +43,6 @@ class RebuildFilesizes extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -65,12 +64,10 @@ class RebuildFilesizes extends Command
|
|||
)
|
||||
) {
|
||||
TrackFile::chunk(200, function ($trackFiles) {
|
||||
|
||||
$this->info('========== Start Chunk ==========');
|
||||
|
||||
foreach ($trackFiles as $trackFile) {
|
||||
/** @var TrackFile $trackFile */
|
||||
|
||||
if (File::exists($trackFile->getFile())) {
|
||||
$size = $trackFile->updateFilesize();
|
||||
$this->info('ID '.$trackFile->id.' processed - '.$size.' bytes');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2017 Isaac Avram
|
||||
* Copyright (C) 2017 Isaac Avram.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -19,8 +19,8 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Image;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
|
@ -57,10 +57,10 @@ class RebuildImages extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info("Regenerating Images");
|
||||
$this->info('Regenerating Images');
|
||||
$progressBar = $this->output->createProgressBar(Image::count());
|
||||
|
||||
Image::chunk(1000, function($images) use ($progressBar) {
|
||||
Image::chunk(1000, function ($images) use ($progressBar) {
|
||||
foreach ($images as $image) {
|
||||
try {
|
||||
$image->buildCovers();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Models\Album;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class RebuildSearchIndex extends Command
|
||||
{
|
||||
|
@ -45,7 +45,6 @@ class RebuildSearchIndex extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -65,7 +64,7 @@ class RebuildSearchIndex extends Command
|
|||
$totalUsers = User::count();
|
||||
|
||||
$trackProgress = $this->output->createProgressBar($totalTracks);
|
||||
$this->info("Processing tracks...");
|
||||
$this->info('Processing tracks...');
|
||||
Track::withTrashed()->chunk(200, function (Collection $tracks) use ($trackProgress) {
|
||||
foreach ($tracks as $track) {
|
||||
/** @var Track $track */
|
||||
|
@ -76,9 +75,8 @@ class RebuildSearchIndex extends Command
|
|||
$trackProgress->finish();
|
||||
$this->line('');
|
||||
|
||||
|
||||
$albumProgress = $this->output->createProgressBar($totalAlbums);
|
||||
$this->info("Processing albums...");
|
||||
$this->info('Processing albums...');
|
||||
Album::withTrashed()->chunk(200, function (Collection $albums) use ($albumProgress) {
|
||||
foreach ($albums as $album) {
|
||||
/** @var Album $album */
|
||||
|
@ -89,9 +87,8 @@ class RebuildSearchIndex extends Command
|
|||
$albumProgress->finish();
|
||||
$this->line('');
|
||||
|
||||
|
||||
$playlistProgress = $this->output->createProgressBar($totalPlaylists);
|
||||
$this->info("Processing playlists...");
|
||||
$this->info('Processing playlists...');
|
||||
Playlist::withTrashed()->chunk(200, function (Collection $playlists) use ($playlistProgress) {
|
||||
foreach ($playlists as $playlist) {
|
||||
/** @var Playlist $playlist */
|
||||
|
@ -102,9 +99,8 @@ class RebuildSearchIndex extends Command
|
|||
$playlistProgress->finish();
|
||||
$this->line('');
|
||||
|
||||
|
||||
$userProgress = $this->output->createProgressBar($totalUsers);
|
||||
$this->info("Processing users...");
|
||||
$this->info('Processing users...');
|
||||
User::chunk(200, function (Collection $users) use ($userProgress) {
|
||||
foreach ($users as $user) {
|
||||
/** @var User $user */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -42,7 +42,6 @@ class RebuildTags extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -60,10 +59,10 @@ class RebuildTags extends Command
|
|||
$track = Track::findOrFail($this->argument('trackId'));
|
||||
$tracks = [$track];
|
||||
} else {
|
||||
$tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id', 'asc')->get();
|
||||
$tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id')->get();
|
||||
}
|
||||
|
||||
$numberOfTracks = sizeof($tracks);
|
||||
$numberOfTracks = count($tracks);
|
||||
|
||||
$this->info("Updating tags for ${numberOfTracks} tracks...");
|
||||
$bar = $this->output->createProgressBar($numberOfTracks);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,11 +20,11 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Commands\GenerateTrackFilesCommand;
|
||||
use App\Jobs\EncodeTrackFile;
|
||||
use App\Models\Track;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
|
||||
class RebuildTrack extends Command
|
||||
{
|
||||
|
@ -48,7 +48,6 @@ class RebuildTrack extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -78,14 +77,14 @@ class RebuildTrack extends Command
|
|||
// The GenerateTrackFiles command will re-encode all TrackFiles.
|
||||
|
||||
if ($result->didFail()) {
|
||||
$this->error("Something went wrong!");
|
||||
$this->error('Something went wrong!');
|
||||
print_r($result->getMessages());
|
||||
}
|
||||
} else {
|
||||
$this->info("Re-encoding this track's files - there should be a line of output for each format!");
|
||||
|
||||
foreach ($track->trackFiles as $trackFile) {
|
||||
if (!$trackFile->is_master) {
|
||||
if (! $trackFile->is_master) {
|
||||
$this->info("Re-encoding this track's {$trackFile->format} file...");
|
||||
$this->dispatch(new EncodeTrackFile($trackFile, true));
|
||||
}
|
||||
|
@ -95,7 +94,7 @@ class RebuildTrack extends Command
|
|||
|
||||
private function printTrackInfo(Track $track)
|
||||
{
|
||||
$this->comment("Track info:");
|
||||
$this->comment('Track info:');
|
||||
$this->comment(" Title: {$track->title}");
|
||||
$this->comment(" Uploaded at: {$track->created_at}");
|
||||
$this->comment(" Artist: {$track->user->display_name} [User ID: {$track->user_id}]");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Kelvin Zhang
|
||||
* Copyright (C) 2015 Kelvin Zhang.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,16 +20,15 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Jobs\EncodeTrackFile;
|
||||
use App\Models\Track;
|
||||
use App\Models\TrackFile;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class RebuildTrackCache extends Command
|
||||
{
|
||||
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
|
@ -49,7 +48,6 @@ class RebuildTrackCache extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -172,7 +170,6 @@ class RebuildTrackCache extends Command
|
|||
$this->output->newLine(1);
|
||||
});
|
||||
|
||||
|
||||
$this->info('Format(s) set from cacheable to non-cacheable: '.implode(' ', array_unique($formats)));
|
||||
$this->info($trackFileCount.' cacheable track files set to non-cacheable.');
|
||||
|
||||
|
@ -209,7 +206,6 @@ class RebuildTrackCache extends Command
|
|||
$this->output->newLine(1);
|
||||
});
|
||||
|
||||
|
||||
$this->info(sprintf('%d track files deleted out of %d track files. Continuing.', $count, $trackFileCount));
|
||||
|
||||
//==========================================================================================================
|
||||
|
@ -228,17 +224,17 @@ class RebuildTrackCache extends Command
|
|||
$this->output->newLine(1);
|
||||
$this->info('---------- Start Chunk ----------');
|
||||
|
||||
// Record the track files which do not exist (i.e., have not been encoded yet)
|
||||
// Record the track files which do not exist (i.e., have not been encoded yet)
|
||||
$emptyTrackFiles = [];
|
||||
|
||||
foreach ($trackFiles as $trackFile) {
|
||||
if (!File::exists($trackFile->getFile())) {
|
||||
if (! File::exists($trackFile->getFile())) {
|
||||
$count++;
|
||||
$emptyTrackFiles[] = $trackFile;
|
||||
}
|
||||
}
|
||||
|
||||
// Encode recorded track files
|
||||
// Encode recorded track files
|
||||
foreach ($emptyTrackFiles as $emptyTrackFile) {
|
||||
$this->info("Started encoding track file ID {$emptyTrackFile->id}");
|
||||
$this->dispatch(new EncodeTrackFile($emptyTrackFile, false));
|
||||
|
@ -248,7 +244,6 @@ class RebuildTrackCache extends Command
|
|||
$this->output->newLine(1);
|
||||
});
|
||||
|
||||
|
||||
$this->info($count.' track files encoded.');
|
||||
$this->output->newLine(1);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,8 +21,8 @@
|
|||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\ResourceLogItem;
|
||||
use DB;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RefreshCache extends Command
|
||||
{
|
||||
|
@ -42,7 +42,6 @@ class RefreshCache extends Command
|
|||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -62,17 +61,17 @@ class RefreshCache extends Command
|
|||
|
||||
DB::table('albums')->update([
|
||||
'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.album_id = albums.id AND deleted_at IS NULL)'),
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)'),
|
||||
]);
|
||||
|
||||
DB::table('playlists')->update([
|
||||
'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.playlist_id = playlists.id AND deleted_at IS NULL)'),
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)'),
|
||||
]);
|
||||
|
||||
DB::table('users')->update([
|
||||
'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.profile_id = users.id AND deleted_at IS NULL)'),
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)')
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)'),
|
||||
]);
|
||||
|
||||
$users = DB::table('users')->get();
|
||||
|
@ -80,7 +79,7 @@ class RefreshCache extends Command
|
|||
$resources = [
|
||||
'album' => [],
|
||||
'playlist' => [],
|
||||
'track' => []
|
||||
'track' => [],
|
||||
];
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
@ -206,7 +205,7 @@ class RefreshCache extends Command
|
|||
|
||||
private function getCacheItem(&$resources, $type, $id)
|
||||
{
|
||||
if (!isset($resources[$type][$id])) {
|
||||
if (! isset($resources[$type][$id])) {
|
||||
$item = [
|
||||
'view_count' => 0,
|
||||
'download_count' => 0,
|
||||
|
@ -227,7 +226,7 @@ class RefreshCache extends Command
|
|||
|
||||
private function getUserCacheItem(&$items, $userId, $type, $id)
|
||||
{
|
||||
if (!isset($items[$userId][$type][$id])) {
|
||||
if (! isset($items[$userId][$type][$id])) {
|
||||
$item = [
|
||||
'is_followed' => false,
|
||||
'is_favourited' => false,
|
||||
|
@ -235,7 +234,7 @@ class RefreshCache extends Command
|
|||
'view_count' => 0,
|
||||
'play_count' => 0,
|
||||
'download_count' => 0,
|
||||
'user_id' => $userId
|
||||
'user_id' => $userId,
|
||||
];
|
||||
|
||||
$item[$type.'_id'] = $id;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use Poniverse\Lib\Client;
|
||||
use App\Models\User;
|
||||
|
||||
class SyncPoniverseAccounts extends Command
|
||||
{
|
||||
|
@ -71,25 +71,25 @@ class SyncPoniverseAccounts extends Command
|
|||
%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%');
|
||||
|
||||
$usersToUpdate
|
||||
->orderBy('id', 'ASC')
|
||||
->chunk(100, function($users) use ($progress) {
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$progress->setMessage("Updating user ID {$user->id}...");
|
||||
$progress->advance();
|
||||
->orderBy('id')
|
||||
->chunk(100, function ($users) use ($progress) {
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$progress->setMessage("Updating user ID {$user->id}...");
|
||||
$progress->advance();
|
||||
|
||||
$this->poniverse->poniverse()->meta()
|
||||
$this->poniverse->poniverse()->meta()
|
||||
->syncAccount(
|
||||
$user->getAccessToken()->getResourceOwnerId(),
|
||||
function(AccessToken $accessTokenInfo) use ($user) {
|
||||
function (AccessToken $accessTokenInfo) use ($user) {
|
||||
$user->setAccessToken($accessTokenInfo);
|
||||
},
|
||||
function(string $newEmailAddress) use ($user) {
|
||||
function (string $newEmailAddress) use ($user) {
|
||||
$user->email = $newEmailAddress;
|
||||
$user->save();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$progress->finish();
|
||||
$this->line('');
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Kelvin Zhang
|
||||
* Copyright (C) 2016 Kelvin Zhang.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,9 +20,9 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\TrackFile;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class VersionFiles extends Command
|
||||
{
|
||||
|
@ -62,23 +62,22 @@ class VersionFiles extends Command
|
|||
|
||||
if ($this->option('force') || $this->confirm('Are you sure you want to rename all unversioned track files? [y|N]', false)) {
|
||||
TrackFile::chunk(200, function ($trackFiles) {
|
||||
|
||||
$this->info('========== Start Chunk ==========');
|
||||
|
||||
foreach ($trackFiles as $trackFile) {
|
||||
/** @var TrackFile $trackFile */
|
||||
|
||||
// Check whether the unversioned file exists
|
||||
if (!File::exists($trackFile->getUnversionedFile())) {
|
||||
$this->info('ID ' . $trackFile->id . ' skipped - file not found');
|
||||
if (! File::exists($trackFile->getUnversionedFile())) {
|
||||
$this->info('ID '.$trackFile->id.' skipped - file not found');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Version the file and check the outcome
|
||||
if (File::move($trackFile->getUnversionedFile(), $trackFile->getFile())) {
|
||||
$this->info('ID ' . $trackFile->id . ' processed');
|
||||
$this->info('ID '.$trackFile->id.' processed');
|
||||
} else {
|
||||
$this->error('ID ' . $trackFile->id . ' was unable to be renamed');
|
||||
$this->error('ID '.$trackFile->id.' was unable to be renamed');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -25,8 +25,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||
/**
|
||||
* This interface is used for type safety when referring to entities that
|
||||
* are capable of accepting comments.
|
||||
*
|
||||
* @package App\Contracts
|
||||
*/
|
||||
interface Commentable extends GeneratesNotifications
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -25,8 +25,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||
/**
|
||||
* This interface is used for type safety when referring to entities that
|
||||
* are capable of being favourited.
|
||||
*
|
||||
* @package App\Contracts
|
||||
*/
|
||||
interface Favouritable extends GeneratesNotifications
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,14 +20,12 @@
|
|||
|
||||
namespace App\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
/**
|
||||
* This interface is used for type safety when referring to entities that can be
|
||||
* the "target resource" of a notification (ie. what the notification is about).
|
||||
*
|
||||
* @package App\Contracts
|
||||
*/
|
||||
interface GeneratesNotifications
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -26,12 +26,7 @@ use App\Models\Track;
|
|||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Interface NotificationHandler
|
||||
* @package App\Contracts
|
||||
*
|
||||
* Each method in this interface represents a type of notification. To add a new
|
||||
* type of notification, add a method for it to this interface and every class
|
||||
* that implements it. Your IDE should be able to help with this.
|
||||
* Interface NotificationHandler.
|
||||
*/
|
||||
interface NotificationHandler
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -28,13 +28,12 @@ interface Searchable
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toElasticsearch():array;
|
||||
public function toElasticsearch(): array;
|
||||
|
||||
/**
|
||||
* @return bool whether this particular object should be indexed or not
|
||||
*/
|
||||
public function shouldBeIndexed():bool;
|
||||
public function shouldBeIndexed(): bool;
|
||||
|
||||
public function updateElasticsearchEntry();
|
||||
public function updateElasticsearchEntrySynchronously();
|
||||
public function updateElasticsearchEntry(bool $removeFromIndex = false);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,13 +21,14 @@
|
|||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use GrahamCampbell\Exceptions\ExceptionHandler;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -41,33 +42,20 @@ class Handler extends ExceptionHandler
|
|||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $e)
|
||||
public function register()
|
||||
{
|
||||
parent::report($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $e
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
return parent::render($request, $e);
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -23,7 +23,7 @@ namespace App\Exceptions;
|
|||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
/**
|
||||
* Class TrackFileNotFoundException
|
||||
* Class TrackFileNotFoundException.
|
||||
*
|
||||
* This exception is used to indicate that the requested `TrackFile` object
|
||||
* does not exist. This is useful when dealing with albums or playlists that
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,24 +20,24 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Config;
|
||||
use Redirect;
|
||||
use View;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getRegister()
|
||||
{
|
||||
return Redirect::to(Config::get('poniverse.urls')['register']);
|
||||
return redirect()->to(config('poniverse.urls')['register']);
|
||||
}
|
||||
|
||||
public function getNotifications()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,42 +20,42 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use View;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getGenres()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getTracks()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getShowSongs()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getUsers()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getClassifierQueue()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getAnnouncements()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,49 +21,49 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\AlbumDownloader;
|
||||
use App;
|
||||
use App\Models\Album;
|
||||
use App\Models\ResourceLogItem;
|
||||
use App\Models\Track;
|
||||
use Redirect;
|
||||
use View;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class AlbumsController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('albums.index');
|
||||
return view('albums.index');
|
||||
}
|
||||
|
||||
public function getShow($id, $slug)
|
||||
{
|
||||
$album = Album::find($id);
|
||||
if (!$album) {
|
||||
App::abort(404);
|
||||
if (! $album) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($album->slug != $slug) {
|
||||
return Redirect::action('AlbumsController@getAlbum', [$id, $album->slug]);
|
||||
return Redirect::action([AlbumsController::class, 'getAlbum'], [$id, $album->slug]);
|
||||
}
|
||||
|
||||
return View::make('albums.show');
|
||||
return view('albums.show');
|
||||
}
|
||||
|
||||
public function getShortlink($id)
|
||||
{
|
||||
$album = Album::find($id);
|
||||
if (!$album) {
|
||||
App::abort(404);
|
||||
if (! $album) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return Redirect::action('AlbumsController@getShow', [$id, $album->slug]);
|
||||
return Redirect::action([AlbumsController::class, 'getShow'], [$id, $album->slug]);
|
||||
}
|
||||
|
||||
public function getDownload($id, $extension)
|
||||
{
|
||||
$album = Album::with('tracks', 'tracks.trackFiles', 'user')->find($id);
|
||||
if (!$album) {
|
||||
App::abort(404);
|
||||
if (! $album) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$format = null;
|
||||
|
@ -78,11 +78,11 @@ class AlbumsController extends Controller
|
|||
}
|
||||
|
||||
if ($format == null) {
|
||||
App::abort(404);
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (!$album->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
|
||||
App::abort(404);
|
||||
if (! $album->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
ResourceLogItem::logItem('album', $id, ResourceLogItem::DOWNLOAD, $format['index']);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,7 +22,7 @@ namespace App\Http\Controllers\Api\Mobile;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Track;
|
||||
use Response;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class TracksController extends Controller
|
||||
{
|
||||
|
@ -41,10 +41,10 @@ class TracksController extends Controller
|
|||
|
||||
$json = [
|
||||
'total_tracks' => $tracks->count(),
|
||||
'tracks' => $tracks->toArray()
|
||||
'tracks' => $tracks->toArray(),
|
||||
];
|
||||
|
||||
return Response::json($json, 200);
|
||||
return response()->json($json, 200);
|
||||
}
|
||||
|
||||
public function popular()
|
||||
|
@ -53,9 +53,9 @@ class TracksController extends Controller
|
|||
|
||||
$json = [
|
||||
'total_tracks' => $tracks->count(),
|
||||
'tracks' => $tracks->toArray()
|
||||
'tracks' => $tracks->toArray(),
|
||||
];
|
||||
|
||||
return Response::json($json, 200);
|
||||
return response()->json($json, 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015-2017 Feld0
|
||||
* Copyright (C) 2015-2017 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,9 +22,10 @@ namespace App\Http\Controllers\Api\V1;
|
|||
|
||||
use App\Commands\UploadTrackCommand;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Http\Controllers\ContentController;
|
||||
use App\Models\Image;
|
||||
use App\Models\Track;
|
||||
use Response;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class TracksController extends ApiControllerBase
|
||||
{
|
||||
|
@ -41,37 +42,37 @@ class TracksController extends ApiControllerBase
|
|||
|
||||
$data = [
|
||||
'id' => (string) $commandData['id'],
|
||||
'status_url' => action('Api\V1\TracksController@getUploadStatus', ['id' => $commandData['id']]),
|
||||
'track_url' => action('TracksController@getTrack', ['id' => $commandData['id'], 'slug' => $commandData['slug']]),
|
||||
'status_url' => action([static::class, 'getUploadStatus'], ['id' => $commandData['id']]),
|
||||
'track_url' => action([\App\Http\Controllers\TracksController::class, 'getTrack'], ['id' => $commandData['id'], 'slug' => $commandData['slug']]),
|
||||
'message' => $commandData['autoPublish']
|
||||
? "This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url."
|
||||
? 'This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url.'
|
||||
: "This track has been accepted for processing! Poll the status_url to know when it's ready to publish. It will be published at the track_url.",
|
||||
];
|
||||
|
||||
$response->setData($data);
|
||||
$response->setStatusCode(202);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function getUploadStatus($trackId)
|
||||
{
|
||||
$track = Track::findOrFail($trackId);
|
||||
$this->authorize('edit', $track);
|
||||
|
||||
if ($track->status === Track::STATUS_PROCESSING) {
|
||||
return Response::json(['message' => 'Processing...'], 202);
|
||||
return response()->json(['message' => 'Processing...'], 202);
|
||||
} elseif ($track->status === Track::STATUS_COMPLETE) {
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'message' => $track->published_at
|
||||
? 'Processing complete! The track is live at the track_url. The artist can edit the track by visiting its edit_url.'
|
||||
: 'Processing complete! The artist must publish the track by visiting its edit_url.',
|
||||
'edit_url' => action('ContentController@getTracks', ['id' => $trackId]),
|
||||
'track_url' => $track->url
|
||||
'edit_url' => action([ContentController::class, 'getTracks'], ['id' => $trackId]),
|
||||
'track_url' => $track->url,
|
||||
], 201);
|
||||
} else {
|
||||
// something went wrong
|
||||
return Response::json(['error' => 'Processing failed! Please contact logic@pony.fm to figure out what went wrong.'], 500);
|
||||
return response()->json(['error' => 'Processing failed! Please contact logic@pony.fm to figure out what went wrong.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,18 +84,19 @@ class TracksController extends ApiControllerBase
|
|||
* @param int $id track ID
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getTrackDetails($id) {
|
||||
public function getTrackDetails($id)
|
||||
{
|
||||
/** @var Track|null $track */
|
||||
$track = Track
|
||||
::with('user', 'album', 'user.avatar', 'cover', 'genre')
|
||||
->published()
|
||||
->where('id', $id)->first();
|
||||
|
||||
if (!$track) {
|
||||
return Response::json(['message' => 'Track not found.'], 404);
|
||||
if (! $track) {
|
||||
return response()->json(['message' => 'Track not found.'], 404);
|
||||
}
|
||||
|
||||
return Response::json(self::trackToJson($track, false, true), 200);
|
||||
return response()->json(self::trackToJson($track, false, true), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,11 +114,11 @@ class TracksController extends ApiControllerBase
|
|||
->published()
|
||||
->where('hash', $hash)->first();
|
||||
|
||||
if (!$track) {
|
||||
return Response::json(['message' => 'Track not found.'], 403);
|
||||
if (! $track) {
|
||||
return response()->json(['message' => 'Track not found.'], 403);
|
||||
}
|
||||
|
||||
return Response::json(self::trackToJson($track, true, false), 200);
|
||||
return response()->json(self::trackToJson($track, true, false), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,7 +128,8 @@ class TracksController extends ApiControllerBase
|
|||
* @param bool $includeComments if true, includes the track's comments in the serialization
|
||||
* @return array serialized track
|
||||
*/
|
||||
private static function trackToJson(Track $track, bool $includeComments, bool $includeStreamUrl) {
|
||||
private static function trackToJson(Track $track, bool $includeComments, bool $includeStreamUrl)
|
||||
{
|
||||
$trackResponse = [
|
||||
'id' => $track->id,
|
||||
'title' => $track->title,
|
||||
|
@ -139,41 +142,41 @@ class TracksController extends ApiControllerBase
|
|||
'avatars' => [
|
||||
'thumbnail' => $track->user->getAvatarUrl(Image::THUMBNAIL),
|
||||
'small' => $track->user->getAvatarUrl(Image::SMALL),
|
||||
'normal' => $track->user->getAvatarUrl(Image::NORMAL)
|
||||
]
|
||||
'normal' => $track->user->getAvatarUrl(Image::NORMAL),
|
||||
],
|
||||
],
|
||||
'stats' => [
|
||||
'views' => $track->view_count,
|
||||
'plays' => $track->play_count,
|
||||
'downloads' => $track->download_count,
|
||||
'comments' => $track->comment_count,
|
||||
'favourites' => $track->favourite_count
|
||||
'favourites' => $track->favourite_count,
|
||||
],
|
||||
'url' => $track->url,
|
||||
'is_vocal' => !!$track->is_vocal,
|
||||
'is_explicit' => !!$track->is_explicit,
|
||||
'is_downloadable' => !!$track->is_downloadable,
|
||||
'is_vocal' => (bool) $track->is_vocal,
|
||||
'is_explicit' => (bool) $track->is_explicit,
|
||||
'is_downloadable' => (bool) $track->is_downloadable,
|
||||
'published_at' => $track->published_at,
|
||||
'duration' => $track->duration,
|
||||
'genre' => $track->genre != null
|
||||
?
|
||||
[
|
||||
'id' => $track->genre->id,
|
||||
'name' => $track->genre->name
|
||||
'name' => $track->genre->name,
|
||||
] : null,
|
||||
'type' => [
|
||||
'id' => $track->trackType->id,
|
||||
'name' => $track->trackType->title
|
||||
'name' => $track->trackType->title,
|
||||
],
|
||||
'covers' => [
|
||||
'thumbnail' => $track->getCoverUrl(Image::THUMBNAIL),
|
||||
'small' => $track->getCoverUrl(Image::SMALL),
|
||||
'normal' => $track->getCoverUrl(Image::NORMAL)
|
||||
'normal' => $track->getCoverUrl(Image::NORMAL),
|
||||
],
|
||||
|
||||
// As of 2017-10-28, this should be expected to produce
|
||||
// "direct_upload", "mlpma", "ponify", or "eqbeats" for all tracks.
|
||||
'source' => $track->source
|
||||
'source' => $track->source,
|
||||
];
|
||||
|
||||
if ($includeComments) {
|
||||
|
@ -191,8 +194,8 @@ class TracksController extends ApiControllerBase
|
|||
'normal' => $comment->user->getAvatarUrl(Image::NORMAL),
|
||||
'thumbnail' => $comment->user->getAvatarUrl(Image::THUMBNAIL),
|
||||
'small' => $comment->user->getAvatarUrl(Image::SMALL),
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -204,7 +207,7 @@ class TracksController extends ApiControllerBase
|
|||
'mp3' => [
|
||||
'url' => $track->getStreamUrl('MP3', session('api_client_id')),
|
||||
'mime_type' => Track::$Formats['MP3']['mime_type'],
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,14 +20,14 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Commands\SaveAccountSettingsCommand;
|
||||
use App\Models\User;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Image;
|
||||
use Gate;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Response;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class AccountController extends ApiControllerBase
|
||||
{
|
||||
|
@ -35,22 +35,23 @@ class AccountController extends ApiControllerBase
|
|||
{
|
||||
$this->authorize('edit', $user);
|
||||
|
||||
return Response::json([
|
||||
'user' => $user->toArray()
|
||||
return response()->json([
|
||||
'user' => $user->toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCurrentUser() {
|
||||
$current_user = Auth::user();
|
||||
public function getCurrentUser(Request $request)
|
||||
{
|
||||
$current_user = $request->user();
|
||||
|
||||
if ($current_user != null) {
|
||||
$user = User::where('id', $current_user->id)->whereNull('disabled_at')->first();
|
||||
|
||||
if ($user == null) {
|
||||
return Response::json(['error' => 'You are not logged in'], 404);
|
||||
return response()->json(['error' => 'You are not logged in'], 404);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'id' => $user->id,
|
||||
'name' => $user->display_name,
|
||||
'slug' => $user->slug,
|
||||
|
@ -58,19 +59,19 @@ class AccountController extends ApiControllerBase
|
|||
'is_archived' => $user->is_archived,
|
||||
'avatars' => [
|
||||
'small' => $user->getAvatarUrl(Image::SMALL),
|
||||
'normal' => $user->getAvatarUrl(Image::NORMAL)
|
||||
'normal' => $user->getAvatarUrl(Image::NORMAL),
|
||||
],
|
||||
'created_at' => $user->created_at
|
||||
'created_at' => $user->created_at,
|
||||
], 200);
|
||||
} else {
|
||||
return Response::json(['error' => 'You are not logged in'], 404);
|
||||
return response()->json(['error' => 'You are not logged in'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSettings($slug)
|
||||
public function getSettings(Request $request, $slug)
|
||||
{
|
||||
$user = null;
|
||||
$current_user = Auth::user();
|
||||
$current_user = $request->user();
|
||||
|
||||
if ($current_user != null) {
|
||||
if ($slug == $current_user->slug) {
|
||||
|
@ -80,16 +81,15 @@ class AccountController extends ApiControllerBase
|
|||
}
|
||||
|
||||
if ($user == null) {
|
||||
return Response::json(['error' => 'User does not exist'], 404);
|
||||
return response()->json(['error' => 'User does not exist'], 404);
|
||||
}
|
||||
|
||||
if (Gate::denies('edit', $user)) {
|
||||
return Response::json(['error' => 'You cannot do that. So stop trying!'], 403);
|
||||
return response()->json(['error' => 'You cannot do that. So stop trying!'], 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'id' => $user->id,
|
||||
'bio' => $user->bio,
|
||||
'can_see_explicit_content' => $user->can_see_explicit_content == 1,
|
||||
|
@ -97,15 +97,15 @@ class AccountController extends ApiControllerBase
|
|||
'slug' => $user->slug,
|
||||
'username' => $user->username,
|
||||
'gravatar' => $user->gravatar ? $user->gravatar : $user->email,
|
||||
'avatar_url' => !$user->uses_gravatar ? $user->getAvatarUrl() : null,
|
||||
'avatar_url' => ! $user->uses_gravatar ? $user->getAvatarUrl() : null,
|
||||
'uses_gravatar' => $user->uses_gravatar == 1,
|
||||
'notification_email' => $user->email,
|
||||
'notifications' => $user->getNotificationSettings()
|
||||
'notifications' => $user->getNotificationSettings(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function postSave(User $user)
|
||||
public function postSave(Request $request, User $user)
|
||||
{
|
||||
return $this->execute(new SaveAccountSettingsCommand(Request::all(), $user));
|
||||
return $this->execute(new SaveAccountSettingsCommand($request->all(), $user));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,31 +20,31 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Models\Album;
|
||||
use App\Commands\CreateAlbumCommand;
|
||||
use App\Commands\DeleteAlbumCommand;
|
||||
use App\Commands\EditAlbumCommand;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Album;
|
||||
use App\Models\Image;
|
||||
use App\Models\ResourceLogItem;
|
||||
use Auth;
|
||||
use Gate;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Models\User;
|
||||
use Response;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class AlbumsController extends ApiControllerBase
|
||||
{
|
||||
public function postCreate()
|
||||
public function postCreate(Request $request)
|
||||
{
|
||||
return $this->execute(new CreateAlbumCommand(Request::all()));
|
||||
return $this->execute(new CreateAlbumCommand($request->all()));
|
||||
}
|
||||
|
||||
public function postEdit($id)
|
||||
public function postEdit(Request $request, $id)
|
||||
{
|
||||
return $this->execute(new EditAlbumCommand($id, Request::all()));
|
||||
return $this->execute(new EditAlbumCommand($id, $request->all()));
|
||||
}
|
||||
|
||||
public function postDelete($id)
|
||||
|
@ -52,7 +52,7 @@ class AlbumsController extends ApiControllerBase
|
|||
return $this->execute(new DeleteAlbumCommand($id));
|
||||
}
|
||||
|
||||
public function getShow($id)
|
||||
public function getShow(Request $request, $id)
|
||||
{
|
||||
$album = Album::with([
|
||||
'tracks' => function ($query) {
|
||||
|
@ -66,16 +66,16 @@ class AlbumsController extends ApiControllerBase
|
|||
'user',
|
||||
'user.avatar',
|
||||
'comments',
|
||||
'comments.user'
|
||||
'comments.user',
|
||||
])
|
||||
->userDetails()
|
||||
->find($id);
|
||||
|
||||
if (!$album) {
|
||||
App::abort(404);
|
||||
if (! $album) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (Request::get('log')) {
|
||||
if ($request->get('log')) {
|
||||
ResourceLogItem::logItem('album', $id, ResourceLogItem::VIEW);
|
||||
$album->view_count++;
|
||||
}
|
||||
|
@ -85,8 +85,8 @@ class AlbumsController extends ApiControllerBase
|
|||
unset($returned_album['formats']);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'album' => $returned_album
|
||||
return response()->json([
|
||||
'album' => $returned_album,
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ class AlbumsController extends ApiControllerBase
|
|||
return $this->notFound('Album not found!');
|
||||
}
|
||||
|
||||
if (!in_array($format, Track::$CacheableFormats)) {
|
||||
if (! in_array($format, Track::$CacheableFormats)) {
|
||||
return $this->notFound('Format not found!');
|
||||
}
|
||||
|
||||
|
@ -114,14 +114,14 @@ class AlbumsController extends ApiControllerBase
|
|||
$url = null;
|
||||
}
|
||||
|
||||
return Response::json(['url' => $url], 200);
|
||||
return response()->json(['url' => $url], 200);
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
public function getIndex(Request $request)
|
||||
{
|
||||
$page = 1;
|
||||
if (Request::has('page')) {
|
||||
$page = Request::get('page');
|
||||
if ($request->has('page')) {
|
||||
$page = $request->get('page');
|
||||
}
|
||||
|
||||
$query = Album::summary()
|
||||
|
@ -134,7 +134,7 @@ class AlbumsController extends ApiControllerBase
|
|||
$perPage = 40;
|
||||
|
||||
$query
|
||||
->orderBy('title', 'asc')
|
||||
->orderBy('title')
|
||||
->skip(($page - 1) * $perPage)
|
||||
->take($perPage);
|
||||
$albums = [];
|
||||
|
@ -143,8 +143,8 @@ class AlbumsController extends ApiControllerBase
|
|||
$albums[] = Album::mapPublicAlbumSummary($album);
|
||||
}
|
||||
|
||||
return Response::json(
|
||||
["albums" => $albums, "current_page" => $page, "total_pages" => ceil($count / $perPage)],
|
||||
return response()->json(
|
||||
['albums' => $albums, 'current_page' => $page, 'total_pages' => ceil($count / $perPage)],
|
||||
200
|
||||
);
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ class AlbumsController extends ApiControllerBase
|
|||
$query = Album::summary()
|
||||
->with('cover', 'user.avatar')
|
||||
->where('user_id', $user->id)
|
||||
->orderBy('created_at', 'desc')->get();
|
||||
->orderByDesc('created_at')->get();
|
||||
$albums = [];
|
||||
|
||||
foreach ($query as $album) {
|
||||
|
@ -167,22 +167,22 @@ class AlbumsController extends ApiControllerBase
|
|||
'created_at' => $album->created_at->format('c'),
|
||||
'covers' => [
|
||||
'small' => $album->getCoverUrl(Image::SMALL),
|
||||
'normal' => $album->getCoverUrl(Image::NORMAL)
|
||||
]
|
||||
'normal' => $album->getCoverUrl(Image::NORMAL),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return Response::json($albums, 200);
|
||||
return response()->json($albums, 200);
|
||||
}
|
||||
|
||||
public function getEdit($id)
|
||||
public function getEdit(Request $request, $id)
|
||||
{
|
||||
$album = Album::with('tracks')->find($id);
|
||||
if (!$album) {
|
||||
if (! $album) {
|
||||
return $this->notFound('Album '.$id.' not found!');
|
||||
}
|
||||
|
||||
if (Gate::denies('edit', Auth::user())) {
|
||||
if (Gate::denies('edit', $request->user())) {
|
||||
return $this->notAuthorized();
|
||||
}
|
||||
|
||||
|
@ -190,11 +190,11 @@ class AlbumsController extends ApiControllerBase
|
|||
foreach ($album->tracks as $track) {
|
||||
$tracks[] = [
|
||||
'id' => $track->id,
|
||||
'title' => $track->title
|
||||
'title' => $track->title,
|
||||
];
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'id' => $album->id,
|
||||
'title' => $album->title,
|
||||
'user_id' => $album->user_id,
|
||||
|
@ -205,7 +205,7 @@ class AlbumsController extends ApiControllerBase
|
|||
'description' => $album->description,
|
||||
'cover_url' => $album->hasCover() ? $album->getCoverUrl(Image::NORMAL) : null,
|
||||
'real_cover_url' => $album->getCoverUrl(Image::NORMAL),
|
||||
'tracks' => $tracks
|
||||
'tracks' => $tracks,
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Session\Store;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AlexaSession;
|
||||
use App\Models\Track;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Session\Store;
|
||||
use Illuminate\Support\Arr;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AlexaController extends Controller
|
||||
|
@ -27,7 +28,7 @@ class AlexaController extends Controller
|
|||
if ($sessId) {
|
||||
$this->session = AlexaSession::find($sessId);
|
||||
|
||||
if (!$this->session) {
|
||||
if (! $this->session) {
|
||||
$this->session = new AlexaSession();
|
||||
$this->session->id = $sessId;
|
||||
}
|
||||
|
@ -35,11 +36,11 @@ class AlexaController extends Controller
|
|||
|
||||
$logger->debug('Incoming Alexa Request', [
|
||||
'type' => $type,
|
||||
'intent' => $intent
|
||||
'intent' => $intent,
|
||||
]);
|
||||
|
||||
$logger->debug('Incoming Alexa Full Request', [
|
||||
'json' => json_encode($request->json()->all(), JSON_PRETTY_PRINT)
|
||||
'json' => json_encode($request->json()->all(), JSON_PRETTY_PRINT),
|
||||
]);
|
||||
|
||||
/** @var JsonResponse $response */
|
||||
|
@ -63,7 +64,7 @@ class AlexaController extends Controller
|
|||
switch ($type) {
|
||||
case 'LaunchRequest':
|
||||
return $this->launch();
|
||||
case 'PlayAudio';
|
||||
case 'PlayAudio':
|
||||
return $this->play();
|
||||
case 'AudioPlayer.PlaybackNearlyFinished':
|
||||
return $this->queueNextTrack();
|
||||
|
@ -99,11 +100,11 @@ class AlexaController extends Controller
|
|||
{
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
"outputSpeech" => [
|
||||
"type" => "SSML",
|
||||
"ssml" => "<speak>If you want to play music, say 'Alexa, ask pony fm to play'</speak>"
|
||||
'outputSpeech' => [
|
||||
'type' => 'SSML',
|
||||
'ssml' => "<speak>If you want to play music, say 'Alexa, ask pony fm to play'</speak>",
|
||||
],
|
||||
'shouldEndSession' => true,
|
||||
],
|
||||
|
@ -114,11 +115,11 @@ class AlexaController extends Controller
|
|||
{
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
"outputSpeech" => [
|
||||
"type" => "SSML",
|
||||
"ssml" => "<speak>Sorry, I don't recognise that command.</speak>"
|
||||
'outputSpeech' => [
|
||||
'type' => 'SSML',
|
||||
'ssml' => "<speak>Sorry, I don't recognise that command.</speak>",
|
||||
],
|
||||
'shouldEndSession' => true,
|
||||
],
|
||||
|
@ -129,15 +130,15 @@ class AlexaController extends Controller
|
|||
{
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
"outputSpeech" => [
|
||||
"type" => "SSML",
|
||||
"ssml" => "
|
||||
'outputSpeech' => [
|
||||
'type' => 'SSML',
|
||||
'ssml' => '
|
||||
<speak>
|
||||
Pony.fm was built by Pixel Wavelength for Viola to keep all her music in one place.
|
||||
</speak>
|
||||
"
|
||||
',
|
||||
],
|
||||
'shouldEndSession' => true,
|
||||
],
|
||||
|
@ -146,14 +147,14 @@ class AlexaController extends Controller
|
|||
|
||||
public function play()
|
||||
{
|
||||
$track = array_first(Track::popular(1));
|
||||
$track = Arr::first(Track::popular(1));
|
||||
|
||||
$this->session->put('current_position', 1);
|
||||
$this->session->put('track_id', $track['id']);
|
||||
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
'directives' => [
|
||||
[
|
||||
|
@ -197,18 +198,18 @@ class AlexaController extends Controller
|
|||
if (count($playlist) === 0) {
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
"outputSpeech" => [
|
||||
"type" => "SSML",
|
||||
"ssml" => "
|
||||
'outputSpeech' => [
|
||||
'type' => 'SSML',
|
||||
'ssml' => "
|
||||
<speak>
|
||||
You've reached the end of the popular tracks today. To start from the beginning say 'Alexa, ask pony fm to play'
|
||||
</speak>
|
||||
"],
|
||||
", ],
|
||||
'directives' => [
|
||||
[
|
||||
'type' => 'AudioPlayer.Stop'
|
||||
'type' => 'AudioPlayer.Stop',
|
||||
],
|
||||
],
|
||||
'shouldEndSession' => true,
|
||||
|
@ -216,7 +217,7 @@ class AlexaController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
$track = $playlist[$position-1];
|
||||
$track = $playlist[$position - 1];
|
||||
|
||||
$trackHistory[] = $trackId;
|
||||
|
||||
|
@ -231,13 +232,13 @@ class AlexaController extends Controller
|
|||
'offsetInMilliseconds' => 0,
|
||||
];
|
||||
|
||||
if (!$replace) {
|
||||
if (! $replace) {
|
||||
$stream['expectedPreviousToken'] = $trackId;
|
||||
}
|
||||
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
'directives' => [
|
||||
[
|
||||
|
@ -247,7 +248,7 @@ class AlexaController extends Controller
|
|||
'stream' => $stream,
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -259,7 +260,7 @@ class AlexaController extends Controller
|
|||
$trackHistory = $this->session->get('track_history', []);
|
||||
$playlist = $this->session->get('playlist', []);
|
||||
|
||||
$track = $playlist[$position-2];
|
||||
$track = $playlist[$position - 2];
|
||||
|
||||
$trackHistory[] = $trackId;
|
||||
|
||||
|
@ -275,7 +276,7 @@ class AlexaController extends Controller
|
|||
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
'directives' => [
|
||||
[
|
||||
|
@ -285,7 +286,7 @@ class AlexaController extends Controller
|
|||
'stream' => $stream,
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -294,11 +295,11 @@ class AlexaController extends Controller
|
|||
{
|
||||
return [
|
||||
'version' => '1.0',
|
||||
'sessionAttributes' => (object)[],
|
||||
'sessionAttributes' => (object) [],
|
||||
'response' => [
|
||||
'directives' => [
|
||||
[
|
||||
'type' => 'AudioPlayer.Stop'
|
||||
'type' => 'AudioPlayer.Stop',
|
||||
],
|
||||
],
|
||||
'shouldEndSession' => true,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,58 +20,64 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Commands\CreateAnnouncementCommand;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Announcement;
|
||||
use Request;
|
||||
use Response;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class AnnouncementsController extends Controller {
|
||||
public function getIndex() {
|
||||
class AnnouncementsController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
$currentDate = Carbon::now();
|
||||
|
||||
$query = Announcement::whereNotNull('start_time')
|
||||
->whereNotNull('end_time')
|
||||
->where('start_time', '<', $currentDate)
|
||||
->where('end_time', '>', $currentDate)
|
||||
->orderBy('start_time', 'desc');
|
||||
->orderByDesc('start_time');
|
||||
|
||||
$announcement = $query->first();
|
||||
|
||||
return Response::json(
|
||||
["announcement" => $announcement],
|
||||
return response()->json(
|
||||
['announcement' => $announcement],
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function getAdminIndex() {
|
||||
public function getAdminIndex()
|
||||
{
|
||||
$this->authorize('access-admin-area');
|
||||
|
||||
$announcements = Announcement::orderBy('start_time', 'desc')
|
||||
$announcements = Announcement::orderByDesc('start_time')
|
||||
->get();
|
||||
|
||||
return Response::json([
|
||||
'announcements' => $announcements->toArray()
|
||||
return response()->json([
|
||||
'announcements' => $announcements->toArray(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getItemById($genreId) {
|
||||
public function getItemById($genreId)
|
||||
{
|
||||
$this->authorize('access-admin-area');
|
||||
|
||||
$query = Announcement::where('id', '=', $genreId)
|
||||
->orderBy('start_time', 'desc');
|
||||
->orderByDesc('start_time');
|
||||
|
||||
$announcement = $query->first();
|
||||
|
||||
return Response::json(
|
||||
["announcement" => $announcement],
|
||||
return response()->json(
|
||||
['announcement' => $announcement],
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function postCreate() {
|
||||
$command = new CreateAnnouncementCommand(Request::get('name'));
|
||||
public function postCreate(Request $request)
|
||||
{
|
||||
$command = new CreateAnnouncementCommand($request->get('name'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,29 +20,29 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Gate;
|
||||
use App\Commands\CreateUserCommand;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Album;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Favourite;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Follower;
|
||||
use App\Models\Image;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use App\Models\Follower;
|
||||
use App;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Response;
|
||||
use ColorThief\ColorThief;
|
||||
use Helpers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ArtistsController extends ApiControllerBase
|
||||
{
|
||||
public function getFavourites($slug)
|
||||
{
|
||||
$user = User::where('slug', $slug)->whereNull('disabled_at')->first();
|
||||
if (!$user) {
|
||||
App::abort(404);
|
||||
if (! $user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$favs = Favourite::where('user_id', $user->id)
|
||||
|
@ -62,33 +62,33 @@ class ArtistsController extends ApiControllerBase
|
|||
},
|
||||
'album' => function ($query) {
|
||||
$query->userDetails();
|
||||
}
|
||||
},
|
||||
])->get();
|
||||
|
||||
$tracks = [];
|
||||
$albums = [];
|
||||
|
||||
foreach ($favs as $fav) {
|
||||
if ($fav->type == 'App\Models\Track') {
|
||||
if ($fav->type == \App\Models\Track::class) {
|
||||
$tracks[] = Track::mapPublicTrackSummary($fav->track);
|
||||
} else {
|
||||
if ($fav->type == 'App\Models\Album') {
|
||||
if ($fav->type == \App\Models\Album::class) {
|
||||
$albums[] = Album::mapPublicAlbumSummary($fav->album);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'tracks' => $tracks,
|
||||
'albums' => $albums
|
||||
'albums' => $albums,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getContent($slug)
|
||||
{
|
||||
$user = User::where('slug', $slug)->whereNull('disabled_at')->first();
|
||||
if (!$user) {
|
||||
App::abort(404);
|
||||
if (! $user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$query = Track::summary()
|
||||
|
@ -112,7 +112,7 @@ class ArtistsController extends ApiControllerBase
|
|||
|
||||
$query = Album::summary()
|
||||
->with('user')
|
||||
->orderBy('created_at', 'desc')
|
||||
->orderByDesc('created_at')
|
||||
->where('track_count', '>', 0)
|
||||
->whereUserId($user->id);
|
||||
|
||||
|
@ -122,7 +122,7 @@ class ArtistsController extends ApiControllerBase
|
|||
$albums[] = Album::mapPublicAlbumSummary($album);
|
||||
}
|
||||
|
||||
return Response::json(['singles' => $singles, 'albumTracks' => $tracks, 'albums' => $albums], 200);
|
||||
return response()->json(['singles' => $singles, 'albumTracks' => $tracks, 'albums' => $albums], 200);
|
||||
}
|
||||
|
||||
public function getShow($slug)
|
||||
|
@ -133,11 +133,11 @@ class ArtistsController extends ApiControllerBase
|
|||
->with([
|
||||
'comments' => function ($query) {
|
||||
$query->with(['user', 'user.avatar']);
|
||||
}
|
||||
},
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
App::abort(404);
|
||||
if (! $user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$trackQuery = Track::summary()
|
||||
|
@ -148,7 +148,7 @@ class ArtistsController extends ApiControllerBase
|
|||
->userDetails()
|
||||
->whereUserId($user->id)
|
||||
->whereNotNull('published_at')
|
||||
->orderBy('created_at', 'desc')
|
||||
->orderByDesc('created_at')
|
||||
->take(20);
|
||||
|
||||
$latestTracks = [];
|
||||
|
@ -162,23 +162,23 @@ class ArtistsController extends ApiControllerBase
|
|||
}
|
||||
|
||||
$userData = [
|
||||
'is_following' => false
|
||||
'is_following' => false,
|
||||
];
|
||||
|
||||
if ($user->users->count()) {
|
||||
$userRow = $user->users[0];
|
||||
$userData = [
|
||||
'is_following' => (bool) $userRow->is_followed
|
||||
'is_following' => (bool) $userRow->is_followed,
|
||||
];
|
||||
}
|
||||
|
||||
$palette = ColorThief::getPalette($user->getAvatarUrlLocal(Image::SMALL), 2);
|
||||
$formatted_palette = array_map("Helpers::rgb2hex", $palette);
|
||||
$formatted_palette = array_map('Helpers::rgb2hex', $palette);
|
||||
|
||||
$followers = Follower::where('artist_id', $user->id)
|
||||
->count();
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'artist' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->display_name,
|
||||
|
@ -186,7 +186,7 @@ class ArtistsController extends ApiControllerBase
|
|||
'is_archived' => (bool) $user->is_archived,
|
||||
'avatars' => [
|
||||
'small' => $user->getAvatarUrl(Image::SMALL),
|
||||
'normal' => $user->getAvatarUrl(Image::NORMAL)
|
||||
'normal' => $user->getAvatarUrl(Image::NORMAL),
|
||||
],
|
||||
'avatar_colors' => $formatted_palette,
|
||||
'created_at' => $user->created_at,
|
||||
|
@ -199,18 +199,18 @@ class ArtistsController extends ApiControllerBase
|
|||
'message_url' => $user->message_url,
|
||||
'user_data' => $userData,
|
||||
'permissions' => [
|
||||
'edit' => Gate::allows('edit', $user)
|
||||
'edit' => Gate::allows('edit', $user),
|
||||
],
|
||||
'isAdmin' => $user->hasRole('admin')
|
||||
]
|
||||
'isAdmin' => $user->hasRole('admin'),
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
public function getIndex(Request $request)
|
||||
{
|
||||
$page = 1;
|
||||
if (Request::has('page')) {
|
||||
$page = Request::get('page');
|
||||
if ($request->has('page')) {
|
||||
$page = $request->get('page');
|
||||
}
|
||||
|
||||
$query = User::where('track_count', '>', 0);
|
||||
|
@ -218,7 +218,7 @@ class ArtistsController extends ApiControllerBase
|
|||
|
||||
// The query results are ordered after they're counted
|
||||
// due to Postgres's behaviour when combining those two operations.
|
||||
$query->orderBy('display_name', 'asc');
|
||||
$query->orderBy('display_name');
|
||||
$perPage = 40;
|
||||
$query->skip(($page - 1) * $perPage)->take($perPage);
|
||||
$users = [];
|
||||
|
@ -227,15 +227,16 @@ class ArtistsController extends ApiControllerBase
|
|||
$users[] = User::mapPublicUserSummary($user);
|
||||
}
|
||||
|
||||
return Response::json(
|
||||
["artists" => $users, "current_page" => $page, "total_pages" => ceil($count / $perPage)],
|
||||
return response()->json(
|
||||
['artists' => $users, 'current_page' => $page, 'total_pages' => ceil($count / $perPage)],
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function postIndex()
|
||||
public function postIndex(Request $request)
|
||||
{
|
||||
$name = Request::json('username');
|
||||
$name = $request->json('username');
|
||||
|
||||
return $this->execute(new CreateUserCommand($name, $name, null, true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,18 +20,18 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use App;
|
||||
use App\Commands\CreateCommentCommand;
|
||||
use App\Models\Comment;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Response;
|
||||
use App\Models\Comment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class CommentsController extends ApiControllerBase
|
||||
{
|
||||
public function postCreate($type, $id)
|
||||
public function postCreate(Request $request, $type, $id)
|
||||
{
|
||||
return $this->execute(new CreateCommentCommand($type, $id, Request::all()));
|
||||
return $this->execute(new CreateCommentCommand($type, $id, $request->all()));
|
||||
}
|
||||
|
||||
public function getIndex($type, $id)
|
||||
|
@ -50,19 +50,19 @@ class CommentsController extends ApiControllerBase
|
|||
if ($type == 'playlist') {
|
||||
$column = 'playlist_id';
|
||||
} else {
|
||||
App::abort(500);
|
||||
abort(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query = Comment::where($column, '=', $id)->orderBy('created_at', 'desc')->with('user');
|
||||
$query = Comment::where($column, '=', $id)->orderByDesc('created_at')->with('user');
|
||||
$comments = [];
|
||||
|
||||
foreach ($query->get() as $comment) {
|
||||
$comments[] = Comment::mapPublic($comment);
|
||||
}
|
||||
|
||||
return Response::json(['list' => $comments, 'count' => count($comments)]);
|
||||
return response()->json(['list' => $comments, 'count' => count($comments)]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,12 +22,13 @@ namespace App\Http\Controllers\Api\Web;
|
|||
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Track;
|
||||
use Auth;
|
||||
use Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class DashboardController extends ApiControllerBase
|
||||
{
|
||||
public function getIndex()
|
||||
public function getIndex(Request $request)
|
||||
{
|
||||
$recentQuery = Track::summary()
|
||||
->with(['genre', 'user', 'cover', 'user.avatar'])
|
||||
|
@ -36,7 +37,7 @@ class DashboardController extends ApiControllerBase
|
|||
->userDetails()
|
||||
->explicitFilter()
|
||||
->published()
|
||||
->orderBy('published_at', 'desc')
|
||||
->orderByDesc('published_at')
|
||||
->take(30);
|
||||
|
||||
$recentQuery->whereHas('user', function ($q) {
|
||||
|
@ -49,9 +50,9 @@ class DashboardController extends ApiControllerBase
|
|||
$recentTracks[] = Track::mapPublicTrackSummary($track);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'recent_tracks' => $recentTracks,
|
||||
'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content)
|
||||
'popular_tracks' => Track::popular(30, $request->user() && $request->user()->can_see_explicit_content),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,27 +20,27 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use App\Models\Album;
|
||||
use App\Commands\ToggleFavouriteCommand;
|
||||
use App\Models\Favourite;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Album;
|
||||
use App\Models\Favourite;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Track;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class FavouritesController extends ApiControllerBase
|
||||
{
|
||||
public function postToggle()
|
||||
public function postToggle(Request $request)
|
||||
{
|
||||
return $this->execute(new ToggleFavouriteCommand(Request::get('type'), Request::get('id')));
|
||||
return $this->execute(new ToggleFavouriteCommand($request->get('type'), $request->get('id')));
|
||||
}
|
||||
|
||||
public function getTracks()
|
||||
public function getTracks(Request $request)
|
||||
{
|
||||
$query = Favourite
|
||||
::whereUserId(Auth::user()->id)
|
||||
::whereUserId($request->user()->id)
|
||||
->whereNotNull('track_id')
|
||||
->with([
|
||||
'track' => function ($query) {
|
||||
|
@ -52,7 +52,7 @@ class FavouritesController extends ApiControllerBase
|
|||
'track.genre',
|
||||
'track.cover',
|
||||
'track.album',
|
||||
'track.album.user'
|
||||
'track.album.user',
|
||||
]);
|
||||
|
||||
$tracks = [];
|
||||
|
@ -65,13 +65,13 @@ class FavouritesController extends ApiControllerBase
|
|||
$tracks[] = Track::mapPublicTrackSummary($fav->track);
|
||||
}
|
||||
|
||||
return Response::json(["tracks" => $tracks], 200);
|
||||
return response()->json(['tracks' => $tracks], 200);
|
||||
}
|
||||
|
||||
public function getAlbums()
|
||||
public function getAlbums(Request $request)
|
||||
{
|
||||
$query = Favourite
|
||||
::whereUserId(Auth::user()->id)
|
||||
::whereUserId($request->user()->id)
|
||||
->whereNotNull('album_id')
|
||||
->with([
|
||||
'album' => function ($query) {
|
||||
|
@ -79,7 +79,7 @@ class FavouritesController extends ApiControllerBase
|
|||
},
|
||||
'album.user',
|
||||
'album.user.avatar',
|
||||
'album.cover'
|
||||
'album.cover',
|
||||
]);
|
||||
|
||||
$albums = [];
|
||||
|
@ -92,13 +92,13 @@ class FavouritesController extends ApiControllerBase
|
|||
$albums[] = Album::mapPublicAlbumSummary($fav->album);
|
||||
}
|
||||
|
||||
return Response::json(["albums" => $albums], 200);
|
||||
return response()->json(['albums' => $albums], 200);
|
||||
}
|
||||
|
||||
public function getPlaylist()
|
||||
public function getPlaylist(Request $request)
|
||||
{
|
||||
$query = Favourite
|
||||
::whereUserId(Auth::user()->id)
|
||||
::whereUserId($request->user()->id)
|
||||
->whereNotNull('playlist_id')
|
||||
->with([
|
||||
'playlist' => function ($query) {
|
||||
|
@ -107,7 +107,7 @@ class FavouritesController extends ApiControllerBase
|
|||
'playlist.user',
|
||||
'playlist.user.avatar',
|
||||
'playlist.tracks',
|
||||
'playlist.tracks.cover'
|
||||
'playlist.tracks.cover',
|
||||
]);
|
||||
|
||||
$playlists = [];
|
||||
|
@ -120,6 +120,6 @@ class FavouritesController extends ApiControllerBase
|
|||
$playlists[] = Playlist::mapPublicPlaylistSummary($fav->playlist);
|
||||
}
|
||||
|
||||
return Response::json(["playlists" => $playlists], 200);
|
||||
return response()->json(['playlists' => $playlists], 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,12 +22,12 @@ namespace App\Http\Controllers\Api\Web;
|
|||
|
||||
use App\Commands\ToggleFollowingCommand;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FollowController extends ApiControllerBase
|
||||
{
|
||||
public function postToggle()
|
||||
public function postToggle(Request $request)
|
||||
{
|
||||
return $this->execute(new ToggleFollowingCommand(Request::get('type'), Request::get('id')));
|
||||
return $this->execute(new ToggleFollowingCommand($request->get('type'), $request->get('id')));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,13 +20,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Commands\CreateGenreCommand;
|
||||
use App\Commands\DeleteGenreCommand;
|
||||
use App\Commands\RenameGenreCommand;
|
||||
use App\Models\Genre;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use Response;
|
||||
use App\Models\Genre;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class GenresController extends ApiControllerBase
|
||||
{
|
||||
|
@ -37,30 +37,32 @@ class GenresController extends ApiControllerBase
|
|||
$genres = Genre::with(['trackCountRelation' => function ($query) {
|
||||
$query->withTrashed();
|
||||
}])
|
||||
->orderBy('name', 'asc')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return Response::json([
|
||||
'genres' => $genres->toArray()
|
||||
return response()->json([
|
||||
'genres' => $genres->toArray(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function postCreate()
|
||||
public function postCreate(Request $request)
|
||||
{
|
||||
$command = new CreateGenreCommand(Request::get('name'));
|
||||
$command = new CreateGenreCommand($request->get('name'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
|
||||
public function putRename($genreId)
|
||||
public function putRename(Request $request, $genreId)
|
||||
{
|
||||
$command = new RenameGenreCommand($genreId, Request::get('name'));
|
||||
$command = new RenameGenreCommand($genreId, $request->get('name'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
|
||||
|
||||
public function deleteGenre($genreId)
|
||||
public function deleteGenre(Request $request, $genreId)
|
||||
{
|
||||
$command = new DeleteGenreCommand($genreId, Request::get('destination_genre_id'));
|
||||
$command = new DeleteGenreCommand($genreId, $request->get('destination_genre_id'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,11 +20,11 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Auth;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Image;
|
||||
use App\Models\User;
|
||||
use Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ImagesController extends ApiControllerBase
|
||||
{
|
||||
|
@ -42,12 +42,12 @@ class ImagesController extends ApiControllerBase
|
|||
'small' => $image->getUrl(Image::SMALL),
|
||||
'normal' => $image->getUrl(Image::NORMAL),
|
||||
'thumbnail' => $image->getUrl(Image::THUMBNAIL),
|
||||
'original' => $image->getUrl(Image::ORIGINAL)
|
||||
'original' => $image->getUrl(Image::ORIGINAL),
|
||||
],
|
||||
'filename' => $image->filename
|
||||
'filename' => $image->filename,
|
||||
];
|
||||
}
|
||||
|
||||
return Response::json($images, 200);
|
||||
return response()->json($images, 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,13 +20,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Minishlink\WebPush\WebPush;
|
||||
|
||||
class NotificationsController extends ApiControllerBase
|
||||
|
@ -36,9 +36,9 @@ class NotificationsController extends ApiControllerBase
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNotifications()
|
||||
public function getNotifications(Request $request)
|
||||
{
|
||||
$notifications = Notification::forUser(Auth::user())
|
||||
$notifications = Notification::forUser($request->user())
|
||||
->take(20)
|
||||
->get();
|
||||
|
||||
|
@ -54,10 +54,10 @@ class NotificationsController extends ApiControllerBase
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function putMarkAsRead()
|
||||
public function putMarkAsRead(Request $request)
|
||||
{
|
||||
$notificationIds = Request::json('notification_ids');
|
||||
$numberOfUpdatedRows = Auth::user()
|
||||
$notificationIds = $request->json('notification_ids');
|
||||
$numberOfUpdatedRows = $request->user()
|
||||
->notifications()
|
||||
->whereIn('id', $notificationIds)
|
||||
->update(['is_read' => true]);
|
||||
|
@ -72,20 +72,20 @@ class NotificationsController extends ApiControllerBase
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function postSubscribe()
|
||||
public function postSubscribe(Request $request)
|
||||
{
|
||||
$input = json_decode(Request::json('subscription'));
|
||||
$input = json_decode($request->json('subscription'));
|
||||
if ($input != 'null') {
|
||||
$existing = Subscription::where('endpoint', '=', $input->endpoint)
|
||||
->where('user_id', '=', Auth::user()->id)
|
||||
->where('user_id', '=', $request->user()->id)
|
||||
->first();
|
||||
|
||||
if ($existing === null) {
|
||||
$subscription = Subscription::create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'user_id' => $request->user()->id,
|
||||
'endpoint' => $input->endpoint,
|
||||
'p256dh' => $input->keys->p256dh,
|
||||
'auth' => $input->keys->auth
|
||||
'auth' => $input->keys->auth,
|
||||
]);
|
||||
|
||||
return ['id' => $subscription->id];
|
||||
|
@ -98,16 +98,16 @@ class NotificationsController extends ApiControllerBase
|
|||
}
|
||||
|
||||
/**
|
||||
* Removes a user's notification subscription
|
||||
* Removes a user's notification subscription.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function postUnsubscribe()
|
||||
public function postUnsubscribe(Request $request)
|
||||
{
|
||||
$input = json_decode(Request::json('subscription'));
|
||||
$input = json_decode($request->json('subscription'));
|
||||
|
||||
$existing = Subscription::where('endpoint', '=', $input->endpoint)
|
||||
->where('user_id', '=', Auth::user()->id)
|
||||
->where('user_id', '=', $request->user()->id)
|
||||
->delete();
|
||||
|
||||
return ['result' => 'success'];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,7 +20,6 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Commands\AddTrackToPlaylistCommand;
|
||||
use App\Commands\CreatePlaylistCommand;
|
||||
use App\Commands\DeletePlaylistCommand;
|
||||
|
@ -30,22 +29,22 @@ use App\Http\Controllers\ApiControllerBase;
|
|||
use App\Models\Image;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\ResourceLogItem;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Models\User;
|
||||
use Response;
|
||||
use App\Models\Track;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Request as RequestF;
|
||||
|
||||
class PlaylistsController extends ApiControllerBase
|
||||
{
|
||||
public function postCreate()
|
||||
public function postCreate(Request $request)
|
||||
{
|
||||
return $this->execute(new CreatePlaylistCommand(Request::all()));
|
||||
return $this->execute(new CreatePlaylistCommand($request->all()));
|
||||
}
|
||||
|
||||
public function postEdit($id)
|
||||
public function postEdit(Request $request, $id)
|
||||
{
|
||||
return $this->execute(new EditPlaylistCommand($id, Request::all()));
|
||||
return $this->execute(new EditPlaylistCommand($id, $request->all()));
|
||||
}
|
||||
|
||||
public function postDelete($id)
|
||||
|
@ -53,19 +52,19 @@ class PlaylistsController extends ApiControllerBase
|
|||
return $this->execute(new DeletePlaylistCommand($id));
|
||||
}
|
||||
|
||||
public function postAddTrack($id)
|
||||
public function postAddTrack(Request $request, $id)
|
||||
{
|
||||
return $this->execute(new AddTrackToPlaylistCommand($id, Request::get('track_id')));
|
||||
return $this->execute(new AddTrackToPlaylistCommand($id, $request->get('track_id')));
|
||||
}
|
||||
|
||||
public function postRemoveTrack($id)
|
||||
public function postRemoveTrack(Request $request, $id)
|
||||
{
|
||||
return $this->execute(new RemoveTrackFromPlaylistCommand($id, Request::get('track_id')));
|
||||
return $this->execute(new RemoveTrackFromPlaylistCommand($id, $request->get('track_id')));
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
public function getIndex(Request $request)
|
||||
{
|
||||
$page = Request::has('page') ? Request::get('page') : 1;
|
||||
$page = $request->has('page') ? $request->get('page') : 1;
|
||||
|
||||
$query = Playlist::summary()
|
||||
->with(
|
||||
|
@ -94,14 +93,14 @@ class PlaylistsController extends ApiControllerBase
|
|||
$playlists[] = Playlist::mapPublicPlaylistSummary($playlist);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
"playlists" => $playlists,
|
||||
"current_page" => $page,
|
||||
"total_pages" => ceil($count / $perPage)
|
||||
return response()->json([
|
||||
'playlists' => $playlists,
|
||||
'current_page' => $page,
|
||||
'total_pages' => ceil($count / $perPage),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getShow($id)
|
||||
public function getShow(Request $request, $id)
|
||||
{
|
||||
$playlist = Playlist::with([
|
||||
'tracks.user',
|
||||
|
@ -113,21 +112,21 @@ class PlaylistsController extends ApiControllerBase
|
|||
},
|
||||
'tracks.trackFiles',
|
||||
'comments',
|
||||
'comments.user'
|
||||
'comments.user',
|
||||
])->userDetails()->find($id);
|
||||
if (!$playlist || !$playlist->canView(Auth::user())) {
|
||||
App::abort('404');
|
||||
if (! $playlist || ! $playlist->canView($request->user())) {
|
||||
abort('404');
|
||||
}
|
||||
|
||||
if (Request::get('log')) {
|
||||
if ($request->get('log')) {
|
||||
ResourceLogItem::logItem('playlist', $id, ResourceLogItem::VIEW);
|
||||
$playlist->view_count++;
|
||||
}
|
||||
|
||||
return Response::json(Playlist::mapPublicPlaylistShow($playlist), 200);
|
||||
return response()->json(Playlist::mapPublicPlaylistShow($playlist), 200);
|
||||
}
|
||||
|
||||
public function getCachedPlaylist($id, $format)
|
||||
public function getCachedPlaylist(Request $request, $id, $format)
|
||||
{
|
||||
// Validation
|
||||
try {
|
||||
|
@ -137,11 +136,11 @@ class PlaylistsController extends ApiControllerBase
|
|||
return $this->notFound('Playlist not found!');
|
||||
}
|
||||
|
||||
if ((!$playlist->is_public && !Auth::check()) || (!$playlist->is_public && ($playlist->user_id !== Auth::user()->id))) {
|
||||
if ((! $playlist->is_public && ! $request->user()) || (! $playlist->is_public && ($playlist->user_id !== $request->user()->id))) {
|
||||
return $this->notFound('Playlist not found!');
|
||||
}
|
||||
|
||||
if (!in_array($format, Track::$CacheableFormats)) {
|
||||
if (! in_array($format, Track::$CacheableFormats)) {
|
||||
return $this->notFound('Format not found!');
|
||||
}
|
||||
|
||||
|
@ -155,10 +154,10 @@ class PlaylistsController extends ApiControllerBase
|
|||
$url = null;
|
||||
}
|
||||
|
||||
return Response::json(['url' => $url], 200);
|
||||
return response()->json(['url' => $url], 200);
|
||||
}
|
||||
|
||||
public function getPinned()
|
||||
public function getPinned(Request $request)
|
||||
{
|
||||
$query = Playlist
|
||||
::userDetails()
|
||||
|
@ -166,8 +165,8 @@ class PlaylistsController extends ApiControllerBase
|
|||
->join('pinned_playlists', function ($join) {
|
||||
$join->on('playlist_id', '=', 'playlists.id');
|
||||
})
|
||||
->where('pinned_playlists.user_id', '=', Auth::user()->id)
|
||||
->orderBy('title', 'asc')
|
||||
->where('pinned_playlists.user_id', '=', $request->user()->id)
|
||||
->orderBy('title')
|
||||
->select('playlists.*')
|
||||
->get();
|
||||
|
||||
|
@ -179,15 +178,15 @@ class PlaylistsController extends ApiControllerBase
|
|||
$playlists[] = $mapped;
|
||||
}
|
||||
|
||||
return Response::json($playlists, 200);
|
||||
return response()->json($playlists, 200);
|
||||
}
|
||||
|
||||
public function getOwned(User $user)
|
||||
public function getOwned(Request $request, User $user)
|
||||
{
|
||||
$query = Playlist::summary()
|
||||
->with('pins', 'tracks', 'tracks.cover')
|
||||
->where('user_id', $user->id)
|
||||
->orderBy('title', 'asc')
|
||||
->orderBy('title')
|
||||
->get();
|
||||
|
||||
$playlists = [];
|
||||
|
@ -201,18 +200,17 @@ class PlaylistsController extends ApiControllerBase
|
|||
'url' => $playlist->url,
|
||||
'covers' => [
|
||||
'small' => $playlist->getCoverUrl(Image::SMALL),
|
||||
'normal' => $playlist->getCoverUrl(Image::NORMAL)
|
||||
'normal' => $playlist->getCoverUrl(Image::NORMAL),
|
||||
],
|
||||
'is_pinned' => $playlist->hasPinFor(Auth::user()->id),
|
||||
'is_pinned' => $playlist->hasPinFor($request->user()->id),
|
||||
'is_public' => $playlist->is_public == 1,
|
||||
'track_ids' => $playlist->tracks->pluck('id')
|
||||
'track_ids' => $playlist->tracks->pluck('id'),
|
||||
];
|
||||
}
|
||||
|
||||
return Response::json($playlists, 200);
|
||||
return response()->json($playlists, 200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function should not deal with anything other than applying order,
|
||||
* which is done after the query's total possible results are counted due
|
||||
|
@ -223,8 +221,8 @@ class PlaylistsController extends ApiControllerBase
|
|||
*/
|
||||
private function applyOrdering($query)
|
||||
{
|
||||
if (Request::has('order')) {
|
||||
$order = \Request::get('order');
|
||||
if (RequestF::has('order')) {
|
||||
$order = RequestF::get('order');
|
||||
$parts = explode(',', $order);
|
||||
$query->orderBy($parts[0], $parts[1]);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,19 +20,19 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Elasticsearch;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Library\Search;
|
||||
use Response;
|
||||
use Elasticsearch;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class SearchController extends ApiControllerBase
|
||||
{
|
||||
public function getSearch(Search $search)
|
||||
public function getSearch(Request $request, Search $search)
|
||||
{
|
||||
$results = $search->searchAllContent(Request::query('query'));
|
||||
$results = $search->searchAllContent($request->query('query'));
|
||||
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'results' => $results,
|
||||
], 200);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,13 +20,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Commands\CreateShowSongCommand;
|
||||
use App\Commands\DeleteShowSongCommand;
|
||||
use App\Commands\RenameShowSongCommand;
|
||||
use App\Models\ShowSong;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use Response;
|
||||
use App\Models\ShowSong;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ShowSongsController extends ApiControllerBase
|
||||
{
|
||||
|
@ -37,31 +37,33 @@ class ShowSongsController extends ApiControllerBase
|
|||
$songs = ShowSong::with(['trackCountRelation' => function ($query) {
|
||||
$query->withTrashed();
|
||||
}])
|
||||
->orderBy('title', 'asc')
|
||||
->orderBy('title')
|
||||
->select('id', 'title', 'slug')
|
||||
->get();
|
||||
|
||||
return Response::json([
|
||||
'showsongs' => $songs->toArray()
|
||||
return response()->json([
|
||||
'showsongs' => $songs->toArray(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function postCreate()
|
||||
public function postCreate(Request $request)
|
||||
{
|
||||
$command = new CreateShowSongCommand(Request::get('title'));
|
||||
$command = new CreateShowSongCommand($request->get('title'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
|
||||
public function putRename($songId)
|
||||
public function putRename(Request $request, $songId)
|
||||
{
|
||||
$command = new RenameShowSongCommand($songId, Request::get('title'));
|
||||
$command = new RenameShowSongCommand($songId, $request->get('title'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
|
||||
|
||||
public function deleteSong($songId)
|
||||
public function deleteSong(Request $request, $songId)
|
||||
{
|
||||
$command = new DeleteShowSongCommand($songId, Request::get('destination_song_id'));
|
||||
$command = new DeleteShowSongCommand($songId, $request->get('destination_song_id'));
|
||||
|
||||
return $this->execute($command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,15 +20,17 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\ResourceLogItem;
|
||||
use App\Models\Track;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use DB;
|
||||
use Response;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StatsController extends ApiControllerBase
|
||||
{
|
||||
|
@ -87,28 +89,28 @@ class StatsController extends ApiControllerBase
|
|||
foreach ($playsArray as $timeOffet => $plays) {
|
||||
if ($hourly) {
|
||||
$set = [
|
||||
'hours' => $timeOffet.' '.str_plural('hour', $timeOffet),
|
||||
'plays' => $plays
|
||||
'hours' => $timeOffet.' '.Str::plural('hour', $timeOffet),
|
||||
'plays' => $plays,
|
||||
];
|
||||
} else {
|
||||
$set = [
|
||||
'days' => $timeOffet.' '.str_plural('day', $timeOffet),
|
||||
'plays' => $plays
|
||||
'days' => $timeOffet.' '.Str::plural('day', $timeOffet),
|
||||
'plays' => $plays,
|
||||
];
|
||||
}
|
||||
array_push($output, $set);
|
||||
}
|
||||
|
||||
if ($hourly) {
|
||||
return Response::json(['playStats' => $output, 'type' => 'Hourly'], 200);
|
||||
return response()->json(['playStats' => $output, 'type' => 'Hourly'], 200);
|
||||
} else {
|
||||
return Response::json(['playStats' => $output, 'type' => 'Daily'], 200);
|
||||
return response()->json(['playStats' => $output, 'type' => 'Daily'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTrackStats($id)
|
||||
public function getTrackStats(Request $request, $id)
|
||||
{
|
||||
$cachedOutput = Cache::remember('track_stats'.$id, 5, function () use ($id) {
|
||||
$cachedOutput = Cache::remember('track_stats'.$id, 300, function () use ($id) {
|
||||
try {
|
||||
$track = Track::published()->findOrFail($id);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
|
@ -116,7 +118,7 @@ class StatsController extends ApiControllerBase
|
|||
}
|
||||
|
||||
// Do we have permission to view this track?
|
||||
if (!$track->canView(Auth::user())) {
|
||||
if (! $track->canView($request->user())) {
|
||||
return $this->notFound('Track not found!');
|
||||
}
|
||||
|
||||
|
@ -134,6 +136,7 @@ class StatsController extends ApiControllerBase
|
|||
$statsData = $this->getStatsData($id, $hourly);
|
||||
|
||||
$output = $this->sortTrackStatsArray($statsData, $hourly);
|
||||
|
||||
return $output;
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,18 +20,18 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use App\Models\Genre;
|
||||
use App\Http\Controllers\ApiControllerBase;
|
||||
use App\Models\Genre;
|
||||
use App\Models\License;
|
||||
use App\Models\ShowSong;
|
||||
use App\Models\TrackType;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TaxonomiesController extends ApiControllerBase
|
||||
{
|
||||
public function getAll()
|
||||
{
|
||||
return \Response::json([
|
||||
return response()->json([
|
||||
'licenses' => License::all()->toArray(),
|
||||
'genres' => Genre::with('trackCountRelation')
|
||||
->orderBy('name')
|
||||
|
@ -48,7 +48,7 @@ class TaxonomiesController extends ApiControllerBase
|
|||
'id',
|
||||
'slug',
|
||||
DB::raw('(SELECT COUNT(tracks.id) FROM show_song_track INNER JOIN tracks ON tracks.id = show_song_track.track_id WHERE show_song_track.show_song_id = show_songs.id AND tracks.published_at IS NOT NULL) AS track_count')
|
||||
)->orderBy('title')->get()->toArray()
|
||||
)->orderBy('title')->get()->toArray(),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,10 +20,6 @@
|
|||
|
||||
namespace App\Http\Controllers\Api\Web;
|
||||
|
||||
use Auth;
|
||||
use File;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Commands\DeleteTrackCommand;
|
||||
use App\Commands\EditTrackCommand;
|
||||
use App\Commands\GenerateTrackFilesCommand;
|
||||
|
@ -33,10 +29,15 @@ use App\Jobs\EncodeTrackFile;
|
|||
use App\Models\Genre;
|
||||
use App\Models\ResourceLogItem;
|
||||
use App\Models\Track;
|
||||
use App\Models\TrackType;
|
||||
use App\Models\TrackFile;
|
||||
use App\Models\TrackType;
|
||||
use App\Models\User;
|
||||
use Response;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Request as RequestF;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class TracksController extends ApiControllerBase
|
||||
|
@ -54,12 +55,12 @@ class TracksController extends ApiControllerBase
|
|||
$this->authorize('edit', $track);
|
||||
|
||||
if ($track->status === Track::STATUS_PROCESSING) {
|
||||
return Response::json(['message' => 'Processing...'], 202);
|
||||
return response()->json(['message' => 'Processing...'], 202);
|
||||
} elseif ($track->status === Track::STATUS_COMPLETE) {
|
||||
return Response::json(['message' => 'Processing complete!'], 201);
|
||||
return response()->json(['message' => 'Processing complete!'], 201);
|
||||
} else {
|
||||
// something went wrong
|
||||
return Response::json(['error' => 'Processing failed!'], 500);
|
||||
return response()->json(['error' => 'Processing failed!'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,9 +69,9 @@ class TracksController extends ApiControllerBase
|
|||
return $this->execute(new DeleteTrackCommand($id));
|
||||
}
|
||||
|
||||
public function postEdit($id)
|
||||
public function postEdit(Request $request, $id)
|
||||
{
|
||||
return $this->execute(new EditTrackCommand($id, Request::all()));
|
||||
return $this->execute(new EditTrackCommand($id, $request->all()));
|
||||
}
|
||||
|
||||
public function postUploadNewVersion($trackId)
|
||||
|
@ -78,13 +79,14 @@ class TracksController extends ApiControllerBase
|
|||
session_write_close();
|
||||
|
||||
$track = Track::find($trackId);
|
||||
if (!$track) {
|
||||
if (! $track) {
|
||||
return $this->notFound('Track not found!');
|
||||
}
|
||||
$this->authorize('edit', $track);
|
||||
|
||||
$track->version_upload_status = Track::STATUS_PROCESSING;
|
||||
$track->update();
|
||||
|
||||
return $this->execute(new UploadTrackCommand(true, false, null, false, $track->getNextVersion(), $track));
|
||||
}
|
||||
|
||||
|
@ -94,12 +96,12 @@ class TracksController extends ApiControllerBase
|
|||
$this->authorize('edit', $track);
|
||||
|
||||
if ($track->version_upload_status === Track::STATUS_PROCESSING) {
|
||||
return Response::json(['message' => 'Processing...'], 202);
|
||||
return response()->json(['message' => 'Processing...'], 202);
|
||||
} elseif ($track->version_upload_status === Track::STATUS_COMPLETE) {
|
||||
return Response::json(['message' => 'Processing complete!'], 201);
|
||||
return response()->json(['message' => 'Processing complete!'], 201);
|
||||
} else {
|
||||
// something went wrong
|
||||
return Response::json(['error' => 'Processing failed!'], 500);
|
||||
return response()->json(['error' => 'Processing failed!'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,41 +115,42 @@ class TracksController extends ApiControllerBase
|
|||
foreach ($trackFiles as $trackFile) {
|
||||
$versions[] = [
|
||||
'version' => $trackFile->version,
|
||||
'url' => '/tracks/' . $track->id . '/version-change/' . $trackFile->version,
|
||||
'created_at' => $trackFile->created_at->timestamp
|
||||
'url' => '/tracks/'.$track->id.'/version-change/'.$trackFile->version,
|
||||
'created_at' => $trackFile->created_at->timestamp,
|
||||
];
|
||||
}
|
||||
|
||||
return Response::json(['current_version' => $track->current_version, 'versions' => $versions], 200);
|
||||
return response()->json(['current_version' => $track->current_version, 'versions' => $versions], 200);
|
||||
}
|
||||
|
||||
public function getChangeVersion($trackId, $newVersion)
|
||||
{
|
||||
$track = Track::find($trackId);
|
||||
if (!$track) {
|
||||
if (! $track) {
|
||||
return $this->notFound('Track not found!');
|
||||
}
|
||||
$this->authorize('edit', $track);
|
||||
|
||||
$masterTrackFile = $track->trackFilesForVersion($newVersion)->where('is_master', true)->first();
|
||||
if (!$masterTrackFile) {
|
||||
if (! $masterTrackFile) {
|
||||
return $this->notFound('Version not found!');
|
||||
}
|
||||
|
||||
$track->version_upload_status = Track::STATUS_PROCESSING;
|
||||
$track->update();
|
||||
$sourceFile = new UploadedFile($masterTrackFile->getFile(), $masterTrackFile->getFilename());
|
||||
|
||||
return $this->execute(new GenerateTrackFilesCommand($track, $sourceFile, false, false, true, $newVersion));
|
||||
}
|
||||
|
||||
public function getShow($id)
|
||||
public function getShow(Request $request, $id)
|
||||
{
|
||||
$track = Track::userDetails()->withComments()->find($id);
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
return $this->notFound('Track not found!');
|
||||
}
|
||||
|
||||
if (Request::get('log')) {
|
||||
if ($request->get('log')) {
|
||||
ResourceLogItem::logItem('track', $id, ResourceLogItem::VIEW);
|
||||
$track->view_count++;
|
||||
}
|
||||
|
@ -157,10 +160,10 @@ class TracksController extends ApiControllerBase
|
|||
unset($returned_track['formats']);
|
||||
}
|
||||
|
||||
return Response::json(['track' => $returned_track], 200);
|
||||
return response()->json(['track' => $returned_track], 200);
|
||||
}
|
||||
|
||||
public function getCachedTrack($id, $format)
|
||||
public function getCachedTrack(Request $request, $id, $format)
|
||||
{
|
||||
// Validation
|
||||
try {
|
||||
|
@ -169,15 +172,15 @@ class TracksController extends ApiControllerBase
|
|||
return $this->notFound('Track not found!');
|
||||
}
|
||||
|
||||
if (!$track->canView(Auth::user())) {
|
||||
return $this->notFound('Track not found!');
|
||||
if (! $track->canView($request->user())) {
|
||||
return $this->notFound('Track not found!');
|
||||
}
|
||||
|
||||
if ($track->is_downloadable == false) {
|
||||
return $this->notFound('Track not found!');
|
||||
return $this->notFound('Track not found!');
|
||||
}
|
||||
|
||||
if (!in_array($format, Track::$CacheableFormats)) {
|
||||
if (! in_array($format, Track::$CacheableFormats)) {
|
||||
return $this->notFound('Format not found!');
|
||||
}
|
||||
|
||||
|
@ -197,16 +200,16 @@ class TracksController extends ApiControllerBase
|
|||
$url = null;
|
||||
}
|
||||
|
||||
return Response::json(['url' => $url], 200);
|
||||
return response()->json(['url' => $url], 200);
|
||||
}
|
||||
|
||||
public function getIndex($all = false, $unknown = false)
|
||||
public function getIndex(Request $request, $all = false, $unknown = false)
|
||||
{
|
||||
$page = 1;
|
||||
$perPage = 45;
|
||||
|
||||
if (Request::has('page')) {
|
||||
$page = Request::get('page');
|
||||
if ($request->has('page')) {
|
||||
$page = $request->get('page');
|
||||
}
|
||||
|
||||
if ($all) {
|
||||
|
@ -238,47 +241,49 @@ class TracksController extends ApiControllerBase
|
|||
$ids[] = $track->id;
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
"tracks" => $tracks,
|
||||
"current_page" => $page,
|
||||
"total_pages" => ceil($totalCount / $perPage)
|
||||
return response()->json([
|
||||
'tracks' => $tracks,
|
||||
'current_page' => $page,
|
||||
'total_pages' => ceil($totalCount / $perPage),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getAllTracks()
|
||||
{
|
||||
$this->authorize('access-admin-area');
|
||||
|
||||
return $this->getIndex(true);
|
||||
}
|
||||
|
||||
public function getClassifierQueue()
|
||||
{
|
||||
$this->authorize('access-admin-area');
|
||||
|
||||
return $this->getIndex(true, true);
|
||||
}
|
||||
|
||||
public function getOwned(User $user)
|
||||
{
|
||||
$query = Track::summary()->where('user_id', $user->id)->orderBy('created_at', 'desc');
|
||||
$query = Track::summary()->where('user_id', $user->id)->orderByDesc('created_at');
|
||||
|
||||
$tracks = [];
|
||||
foreach ($query->get() as $track) {
|
||||
$tracks[] = Track::mapPrivateTrackSummary($track);
|
||||
}
|
||||
|
||||
return Response::json($tracks, 200);
|
||||
return response()->json($tracks, 200);
|
||||
}
|
||||
|
||||
public function getEdit($id)
|
||||
{
|
||||
$track = Track::with('showSongs')->find($id);
|
||||
if (!$track) {
|
||||
if (! $track) {
|
||||
return $this->notFound('Track '.$id.' not found!');
|
||||
}
|
||||
|
||||
$this->authorize('edit', $track);
|
||||
|
||||
return Response::json(Track::mapPrivateTrackShow($track), 200);
|
||||
return response()->json(Track::mapPrivateTrackShow($track), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,8 +296,8 @@ class TracksController extends ApiControllerBase
|
|||
*/
|
||||
private function applyOrdering($query)
|
||||
{
|
||||
if (Request::has('order')) {
|
||||
$order = \Request::get('order');
|
||||
if (RequestF::has('order')) {
|
||||
$order = RequestF::get('order');
|
||||
$parts = explode(',', $order);
|
||||
$query->orderBy($parts[0], $parts[1]);
|
||||
}
|
||||
|
@ -308,8 +313,8 @@ class TracksController extends ApiControllerBase
|
|||
*/
|
||||
private function applyFilters($query, $unknown = false)
|
||||
{
|
||||
if (Request::has('is_vocal')) {
|
||||
$isVocal = \Request::get('is_vocal');
|
||||
if (RequestF::has('is_vocal')) {
|
||||
$isVocal = RequestF::get('is_vocal');
|
||||
if ($isVocal == 'true') {
|
||||
$query->whereIsVocal(true);
|
||||
} else {
|
||||
|
@ -317,27 +322,27 @@ class TracksController extends ApiControllerBase
|
|||
}
|
||||
}
|
||||
|
||||
if (Request::has('in_album')) {
|
||||
if (Request::get('in_album') == 'true') {
|
||||
if (RequestF::has('in_album')) {
|
||||
if (RequestF::get('in_album') == 'true') {
|
||||
$query->whereNotNull('album_id');
|
||||
} else {
|
||||
$query->whereNull('album_id');
|
||||
}
|
||||
}
|
||||
|
||||
if (Request::has('genres')) {
|
||||
$query->whereIn('genre_id', Request::get('genres'));
|
||||
if (RequestF::has('genres')) {
|
||||
$query->whereIn('genre_id', RequestF::get('genres'));
|
||||
}
|
||||
|
||||
if (Request::has('types') && !$unknown) {
|
||||
$query->whereIn('track_type_id', Request::get('types'));
|
||||
if (RequestF::has('types') && ! $unknown) {
|
||||
$query->whereIn('track_type_id', RequestF::get('types'));
|
||||
}
|
||||
|
||||
$archive = null;
|
||||
|
||||
if (Request::has('archive')) {
|
||||
if (RequestF::has('archive')) {
|
||||
// Select which archive to view
|
||||
$archive = Request::get('archive');
|
||||
$archive = RequestF::get('archive');
|
||||
$query->where('source', $archive);
|
||||
}
|
||||
|
||||
|
@ -355,18 +360,19 @@ class TracksController extends ApiControllerBase
|
|||
$archives = ['mlpma', 'ponify', 'eqbeats'];
|
||||
$akey = array_search($archive, $archives);
|
||||
|
||||
if (!$akey)
|
||||
$query->join($archive . '_tracks', 'tracks.id', '=', $archive . 'tracks.track_id');
|
||||
if (! $akey) {
|
||||
$query->join($archive.'_tracks', 'tracks.id', '=', $archive.'tracks.track_id');
|
||||
}
|
||||
}
|
||||
|
||||
if (Request::has('songs')) {
|
||||
if (RequestF::has('songs')) {
|
||||
// DISTINCT is needed here to avoid duplicate results
|
||||
// when a track is associated with multiple show songs.
|
||||
$query->distinct();
|
||||
$query->join('show_song_track', function ($join) {
|
||||
$join->on('tracks.id', '=', 'show_song_track.track_id');
|
||||
});
|
||||
$query->whereIn('show_song_track.show_song_id', Request::get('songs'));
|
||||
$query->whereIn('show_song_track.show_song_id', RequestF::get('songs'));
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,7 +21,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Commands\CommandBase;
|
||||
use Response;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
abstract class ApiControllerBase extends Controller
|
||||
{
|
||||
|
@ -34,28 +34,28 @@ abstract class ApiControllerBase extends Controller
|
|||
*/
|
||||
protected function execute(CommandBase $command)
|
||||
{
|
||||
if (!$command->authorize()) {
|
||||
if (! $command->authorize()) {
|
||||
return $this->notAuthorized();
|
||||
}
|
||||
|
||||
$result = $command->execute();
|
||||
if ($result->didFail()) {
|
||||
return Response::json([
|
||||
return response()->json([
|
||||
'message' => 'Validation failed',
|
||||
'errors' => $result->getMessages()
|
||||
'errors' => $result->getMessages(),
|
||||
], $result->getStatusCode());
|
||||
}
|
||||
|
||||
return Response::json($result->getResponse(), $result->getStatusCode());
|
||||
return response()->json($result->getResponse(), $result->getStatusCode());
|
||||
}
|
||||
|
||||
public function notAuthorized()
|
||||
{
|
||||
return Response::json(['message' => 'You may not do this!'], 403);
|
||||
return response()->json(['message' => 'You may not do this!'], 403);
|
||||
}
|
||||
|
||||
public function notFound($message)
|
||||
{
|
||||
return Response::json(['message' => $message], 403);
|
||||
return response()->json(['message' => $message], 403);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,16 +20,16 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use App\Models\User;
|
||||
use View;
|
||||
use Redirect;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class ArtistsController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('artists.index');
|
||||
return view('artists.index');
|
||||
}
|
||||
|
||||
public function getFavourites($slug)
|
||||
|
@ -51,27 +51,27 @@ class ArtistsController extends Controller
|
|||
$newUser = User::find($user->redirect_to);
|
||||
|
||||
if ($newUser) {
|
||||
return Redirect::action('ArtistsController@getProfile', [$newUser->slug]);
|
||||
return Redirect::action([static::class, 'getProfile'], [$newUser->slug]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->disabled_at) {
|
||||
App::abort('404');
|
||||
abort('404');
|
||||
}
|
||||
|
||||
return View::make('artists.profile');
|
||||
return view('artists.profile');
|
||||
} else {
|
||||
App::abort('404');
|
||||
abort('404');
|
||||
}
|
||||
}
|
||||
|
||||
public function getShortlink($id)
|
||||
{
|
||||
$user = User::find($id);
|
||||
if (!$user || $user->disabled_at !== null) {
|
||||
App::abort('404');
|
||||
if (! $user || $user->disabled_at !== null) {
|
||||
abort('404');
|
||||
}
|
||||
|
||||
return Redirect::action('ArtistsController@getProfile', [$user->slug]);
|
||||
return Redirect::action([static::class, 'getProfile'], [$user->slug]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,18 +20,17 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use Log;
|
||||
use Poniverse\Lib\Client;
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Request;
|
||||
use Redirect;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use Poniverse\Lib\Client;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
@ -45,36 +44,37 @@ class AuthController extends Controller
|
|||
public function getLogin()
|
||||
{
|
||||
if (Auth::guest()) {
|
||||
return Redirect::to(
|
||||
return redirect(
|
||||
$this->poniverse
|
||||
->getOAuthProvider(['redirectUri' => action('AuthController@getOAuth')])
|
||||
->getOAuthProvider(['redirectUri' => action([static::class, 'getOAuth'])])
|
||||
->getAuthorizationUrl());
|
||||
}
|
||||
|
||||
return Redirect::to('/');
|
||||
return redirect()->to('/');
|
||||
}
|
||||
|
||||
public function postLogout()
|
||||
{
|
||||
Auth::logout();
|
||||
return Redirect::to('/');
|
||||
|
||||
return redirect()->to('/');
|
||||
}
|
||||
|
||||
public function getOAuth()
|
||||
public function getOAuth(Request $request)
|
||||
{
|
||||
$oauthProvider = $this->poniverse->getOAuthProvider();
|
||||
|
||||
try {
|
||||
$accessToken = $oauthProvider->getAccessToken('authorization_code', [
|
||||
'code' => Request::query('code'),
|
||||
'redirect_uri' => action('AuthController@getOAuth')
|
||||
'code' => $request->query('code'),
|
||||
'redirect_uri' => action([static::class, 'getOAuth']),
|
||||
]);
|
||||
$this->poniverse->setAccessToken($accessToken);
|
||||
$resourceOwner = $oauthProvider->getResourceOwner($accessToken);
|
||||
} catch (IdentityProviderException $e) {
|
||||
Log::error($e);
|
||||
|
||||
return Redirect::to('/')->with(
|
||||
return redirect()->to('/')->with(
|
||||
'message',
|
||||
'Unfortunately we are having problems attempting to log you in at the moment. Please try again at a later time.'
|
||||
);
|
||||
|
@ -94,13 +94,14 @@ class AuthController extends Controller
|
|||
'type' => 'Bearer',
|
||||
];
|
||||
|
||||
if (!empty($accessToken->getRefreshToken())) {
|
||||
if (! empty($accessToken->getRefreshToken())) {
|
||||
$setData['refresh_token'] = $accessToken->getRefreshToken();
|
||||
}
|
||||
|
||||
if ($token) {
|
||||
//User already exists, update access token and refresh token if provided.
|
||||
DB::table('oauth2_tokens')->where('id', '=', $token->id)->update($setData);
|
||||
|
||||
return $this->loginRedirect(User::find($token->user_id));
|
||||
}
|
||||
|
||||
|
@ -120,7 +121,6 @@ class AuthController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->loginRedirect($user);
|
||||
}
|
||||
|
||||
|
@ -129,14 +129,14 @@ class AuthController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postPoniverseAccountSync()
|
||||
public function postPoniverseAccountSync(Request $request)
|
||||
{
|
||||
$poniverseId = Input::get('id');
|
||||
$updatedAttribute = Input::get('attribute');
|
||||
$poniverseId = $request->get('id');
|
||||
$updatedAttribute = $request->get('attribute');
|
||||
|
||||
// Only email address updates are supported at this time.
|
||||
if ('email' !== $updatedAttribute) {
|
||||
return \Response::json(['message' => 'Unsupported Poniverse account attribute.'], 400);
|
||||
return response()->json(['message' => 'Unsupported Poniverse account attribute.'], 400);
|
||||
}
|
||||
|
||||
$user = User::wherePoniverseId($poniverseId)->first();
|
||||
|
@ -154,13 +154,13 @@ class AuthController extends Controller
|
|||
$user->{$updatedAttribute} = $newUserData->{$updatedAttribute};
|
||||
$user->save();
|
||||
|
||||
return \Response::json(['message' => 'Successfully updated this user!'], 200);
|
||||
return response()->json(['message' => 'Successfully updated this user!'], 200);
|
||||
}
|
||||
|
||||
protected function loginRedirect($user, $rememberMe = true)
|
||||
{
|
||||
Auth::login($user, $rememberMe);
|
||||
|
||||
return Redirect::to('/');
|
||||
return redirect()->to('/');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,22 +20,22 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use View;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class ContentController extends Controller
|
||||
{
|
||||
public function getTracks()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getAlbums()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
|
||||
public function getPlaylist()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -22,8 +22,8 @@ namespace App\Http\Controllers;
|
|||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use View;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('home.index');
|
||||
return view('home.index');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,10 +21,10 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Image;
|
||||
use Config;
|
||||
use App;
|
||||
use Redirect;
|
||||
use Response;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ImagesController extends Controller
|
||||
{
|
||||
|
@ -33,24 +33,24 @@ class ImagesController extends Controller
|
|||
$coverType = Image::getImageTypeFromName($type);
|
||||
|
||||
if ($coverType == null) {
|
||||
App::abort(404);
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$image = Image::find($id);
|
||||
if (!$image) {
|
||||
App::abort(404);
|
||||
if (! $image) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$response = Response::make('', 200);
|
||||
$response = response()->noContent(200);
|
||||
$filename = $image->getFile($coverType['id']);
|
||||
|
||||
if (!is_file($filename)) {
|
||||
if (! is_file($filename)) {
|
||||
$redirect = url('/images/icons/profile_'.Image::$ImageTypes[$coverType['id']]['name'].'.png');
|
||||
|
||||
return Redirect::to($redirect);
|
||||
return redirect()->to($redirect);
|
||||
}
|
||||
|
||||
if (Config::get('app.sendfile')) {
|
||||
if (config('app.sendfile')) {
|
||||
$response->header('X-Sendfile', $filename);
|
||||
} else {
|
||||
$response->header('X-Accel-Redirect', $filename);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Feld0
|
||||
* Copyright (C) 2016 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,51 +20,55 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use Auth;
|
||||
use DB;
|
||||
use App\Models\Email;
|
||||
use App\Models\EmailSubscription;
|
||||
use View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
|
||||
class NotificationsController extends Controller {
|
||||
class NotificationsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @param $emailKey
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function getEmailClick($emailKey) {
|
||||
public function getEmailClick(Request $request, $emailKey)
|
||||
{
|
||||
/** @var Email $email */
|
||||
$email = Email::findOrFail($emailKey);
|
||||
|
||||
DB::transaction(function() use ($email) {
|
||||
$email->emailClicks()->create(['ip_address' => \Request::ip()]);
|
||||
DB::transaction(function () use ($email) {
|
||||
$email->emailClicks()->create(['ip_address' => $request->ip()]);
|
||||
$email->notification->is_read = true;
|
||||
$email->notification->save();
|
||||
});
|
||||
|
||||
return redirect($email->getActivity()->url);
|
||||
return redirect()->to($email->getActivity()->url);
|
||||
}
|
||||
|
||||
public function getEmailUnsubscribe($subscriptionKey) {
|
||||
public function getEmailUnsubscribe(Request $request, $subscriptionKey)
|
||||
{
|
||||
/** @var EmailSubscription $subscription */
|
||||
$subscription = EmailSubscription::findOrFail($subscriptionKey);
|
||||
$subscription->delete();
|
||||
|
||||
if (Auth::check() && $subscription->user->id === Auth::user()->id) {
|
||||
if ($request->user() && $subscription->user->id === $request->user()->id) {
|
||||
return redirect(route('account:settings', [
|
||||
'slug' => $subscription->user->slug,
|
||||
'unsubscribedMessageKey' => $subscription->activity_type
|
||||
]), 303);
|
||||
'unsubscribedMessageKey' => $subscription->activity_type,
|
||||
]), );
|
||||
} else {
|
||||
return redirect(route('email:confirm-unsubscribed', [
|
||||
'unsubscribedUser' => $subscription->user->display_name,
|
||||
'unsubscribedMessageKey' => $subscription->activity_type
|
||||
]), 303);
|
||||
'unsubscribedMessageKey' => $subscription->activity_type,
|
||||
]), );
|
||||
}
|
||||
}
|
||||
|
||||
public function getEmailUnsubscribePage() {
|
||||
return View::make('shared.null');
|
||||
public function getEmailUnsubscribePage()
|
||||
{
|
||||
return view('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,51 +20,52 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\ResourceLogItem;
|
||||
use App\Models\Track;
|
||||
use App\PlaylistDownloader;
|
||||
use Auth;
|
||||
use Redirect;
|
||||
use View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class PlaylistsController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('playlists.index');
|
||||
return view('playlists.index');
|
||||
}
|
||||
|
||||
public function getPlaylist($id, $slug)
|
||||
public function getPlaylist(Request $request, $id, $slug)
|
||||
{
|
||||
$playlist = Playlist::find($id);
|
||||
if (!$playlist || !$playlist->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $playlist || ! $playlist->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($playlist->slug != $slug) {
|
||||
return Redirect::action('PlaylistsController@getPlaylist', [$id, $playlist->slug]);
|
||||
return Redirect::action([static::class, 'getPlaylist'], [$id, $playlist->slug]);
|
||||
}
|
||||
|
||||
return View::make('playlists.show');
|
||||
return view('playlists.show');
|
||||
}
|
||||
|
||||
public function getShortlink($id)
|
||||
public function getShortlink(Request $request, $id)
|
||||
{
|
||||
$playlist = Playlist::find($id);
|
||||
if (!$playlist || !$playlist->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $playlist || ! $playlist->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return Redirect::action('PlaylistsController@getPlaylist', [$id, $playlist->slug]);
|
||||
return Redirect::action([static::class, 'getPlaylist'], [$id, $playlist->slug]);
|
||||
}
|
||||
|
||||
public function getDownload($id, $extension)
|
||||
public function getDownload(Request $request, $id, $extension)
|
||||
{
|
||||
$playlist = Playlist::with('tracks', 'tracks.trackFiles', 'user', 'tracks.album')->find($id);
|
||||
if (!$playlist || !$playlist->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $playlist || ! $playlist->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$format = null;
|
||||
|
@ -79,15 +80,15 @@ class PlaylistsController extends Controller
|
|||
}
|
||||
|
||||
if ($format == null) {
|
||||
App::abort(404);
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (!$playlist->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
|
||||
App::abort(404);
|
||||
if (! $playlist->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
ResourceLogItem::logItem('playlist', $id, ResourceLogItem::DOWNLOAD, $format['index']);
|
||||
$downloader = new PlaylistDownloader($playlist, $formatName);
|
||||
$downloader->download(Auth::user());
|
||||
$downloader->download($request->user());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Logic
|
||||
* Copyright (C) 2016 Logic.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use View;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class StatsController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('tracks.stats');
|
||||
return view('tracks.stats');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,25 +20,25 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ResourceLogItem;
|
||||
use App\Models\Track;
|
||||
use App\Models\TrackFile;
|
||||
use Auth;
|
||||
use Config;
|
||||
use App;
|
||||
use Redirect;
|
||||
use Response;
|
||||
use View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class TracksController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('tracks.index');
|
||||
return view('tracks.index');
|
||||
}
|
||||
|
||||
public function getEmbed($id)
|
||||
public function getEmbed(Request $request, $id)
|
||||
{
|
||||
$track = Track
|
||||
::whereId($id)
|
||||
|
@ -50,17 +50,17 @@ class TracksController extends Controller
|
|||
'genre'
|
||||
)->first();
|
||||
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$userData = [
|
||||
'stats' => [
|
||||
'views' => 0,
|
||||
'plays' => 0,
|
||||
'downloads' => 0
|
||||
'downloads' => 0,
|
||||
],
|
||||
'is_favourited' => false
|
||||
'is_favourited' => false,
|
||||
];
|
||||
|
||||
if ($track->users->count()) {
|
||||
|
@ -71,17 +71,17 @@ class TracksController extends Controller
|
|||
'plays' => $userRow->play_count,
|
||||
'downloads' => $userRow->download_count,
|
||||
],
|
||||
'is_favourited' => $userRow->is_favourited
|
||||
'is_favourited' => $userRow->is_favourited,
|
||||
];
|
||||
}
|
||||
|
||||
return View::make('tracks.embed', ['track' => $track, 'user' => $userData]);
|
||||
return view('tracks.embed', ['track' => $track, 'user' => $userData]);
|
||||
}
|
||||
|
||||
public function getOembed(Request $request)
|
||||
{
|
||||
if (!$request->filled('url')) {
|
||||
App::abort(404);
|
||||
if (! $request->filled('url')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$parsedUrl = parse_url($request->input('url'));
|
||||
|
@ -93,8 +93,8 @@ class TracksController extends Controller
|
|||
->userDetails()
|
||||
->first();
|
||||
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$output = [
|
||||
|
@ -107,24 +107,24 @@ class TracksController extends Controller
|
|||
'title' => $track->title,
|
||||
'author_name' => $track->user->display_name,
|
||||
'author_url' => $track->user->url,
|
||||
'html' => '<iframe src="'.action('TracksController@getEmbed', ['id' => $track->id]).'" width="100%" height="150" allowTransparency="true" frameborder="0" seamless allowfullscreen></iframe>'
|
||||
'html' => '<iframe src="'.action([static::class, 'getEmbed'], ['id' => $track->id]).'" width="100%" height="150" allowTransparency="true" frameborder="0" seamless allowfullscreen></iframe>',
|
||||
];
|
||||
|
||||
return Response::json($output);
|
||||
return response()->json($output);
|
||||
}
|
||||
|
||||
public function getTrack($id, $slug)
|
||||
public function getTrack(Request $request, $id, $slug)
|
||||
{
|
||||
$track = Track::find($id);
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($track->slug != $slug) {
|
||||
return Redirect::action('TracksController@getTrack', [$id, $track->slug]);
|
||||
return Redirect::action([static::class, 'getTrack'], [$id, $track->slug]);
|
||||
}
|
||||
|
||||
return View::make('tracks.show', ['track' => $track]);
|
||||
return view('tracks.show', ['track' => $track]);
|
||||
}
|
||||
|
||||
public function getEdit($id, $slug)
|
||||
|
@ -132,35 +132,35 @@ class TracksController extends Controller
|
|||
return $this->getTrack($id, $slug);
|
||||
}
|
||||
|
||||
public function getShortlink($id)
|
||||
public function getShortlink(Request $request, $id)
|
||||
{
|
||||
$track = Track::find($id);
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return Redirect::action('TracksController@getTrack', [$id, $track->slug]);
|
||||
return Redirect::action([static::class, 'getTrack'], [$id, $track->slug]);
|
||||
}
|
||||
|
||||
public function getStream($id, $extension)
|
||||
public function getStream(Request $request, $id, $extension)
|
||||
{
|
||||
$track = Track::find($id);
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$trackFile = TrackFile::findOrFailByExtension($track->id, $extension);
|
||||
|
||||
$response = Response::make('', 200);
|
||||
$response = response()->noContent(200);
|
||||
$filename = $trackFile->getFile();
|
||||
|
||||
if (!file_exists($filename)) {
|
||||
App::abort(418);
|
||||
if (! file_exists($filename)) {
|
||||
abort(418);
|
||||
}
|
||||
|
||||
ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $trackFile->getFormat()['index']);
|
||||
|
||||
if (Config::get('app.sendfile')) {
|
||||
if (config('app.sendfile')) {
|
||||
$response->header('X-Sendfile', $filename);
|
||||
} else {
|
||||
$response->header('X-Accel-Redirect', $filename);
|
||||
|
@ -179,20 +179,20 @@ class TracksController extends Controller
|
|||
return $response;
|
||||
}
|
||||
|
||||
public function getDownload($id, $extension)
|
||||
public function getDownload(Request $request, $id, $extension)
|
||||
{
|
||||
$track = Track::find($id);
|
||||
if (!$track || !$track->canView(Auth::user())) {
|
||||
App::abort(404);
|
||||
if (! $track || ! $track->canView($request->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$trackFile = TrackFile::findOrFailByExtension($track->id, $extension);
|
||||
ResourceLogItem::logItem('track', $id, ResourceLogItem::DOWNLOAD, $trackFile->getFormat()['index']);
|
||||
|
||||
$response = Response::make('', 200);
|
||||
$response = response()->noContent(200);
|
||||
$filename = $trackFile->getFile();
|
||||
|
||||
if (Config::get('app.sendfile')) {
|
||||
if (config('app.sendfile')) {
|
||||
$response->header('X-Sendfile', $filename);
|
||||
$response->header(
|
||||
'Content-Disposition',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Feld0
|
||||
* Copyright (C) 2015 Feld0.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use View;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class UploaderController extends Controller
|
||||
{
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
return view('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue