Пример #1
0
 public function doPost(JsonResponse $response, LoggedIn $me, HttpFiles $files, $track_id)
 {
     $artwork_file = $files->getOrError("artwork_file");
     $temp_image = TempFileProvider::generate("", $artwork_file["name"]);
     move_uploaded_file($artwork_file["tmp_name"], $temp_image);
     $response->write(Songs::changeCover($track_id, $temp_image));
 }
Пример #2
0
 public function doPost(JsonResponse $response, HttpPost $post)
 {
     $song_id = $post->get("song_id")->reject("")->get();
     $metadata = $post->get("metadata")->filter("is_array")->get();
     $result = count($metadata) == 0 ? array() : Songs::edit($song_id, $metadata);
     $response->write(["tracks" => $result]);
 }
Пример #3
0
 public function doGet(JsonResponse $response, LoggedIn $me)
 {
     ob_start("ob_gzhandler", 8192);
     set_time_limit(0);
     $last_token = (new SelectQuery(TSongsLog::_NAME))->select(TSongsLog::ID)->fetchColumn()->toInt()->getOrElse(0);
     $tracks = (new SelectQuery(TSongs::_NAME))->select(TSongs::$columns)->where(TSongs::FILE_ID . " IS NOT NULL")->where(TSongs::USER_ID, $me->getId())->fetchAll();
     $response->write(array("last_token" => $last_token));
 }
Пример #4
0
 public function doGet(JsonResponse $response, $track_id, $artist, $album)
 {
     $scrobbler = new AudioScrobbler();
     $cover = $scrobbler->getAlbumCover($artist, $album);
     if ($cover->nonEmpty()) {
         $response->write(Songs::changeCover($track_id, $cover->get()));
     } else {
         throw new ControllerException("Artwork not found");
     }
 }
Пример #5
0
 public function doPost(JsonResponse $response, $track_id, HttpFiles $file)
 {
     $track = $file->getOrError("file");
     $decoded_name = urldecode($track["name"]);
     $extension = pathinfo($decoded_name, PATHINFO_EXTENSION);
     $tm = new Song($track_id);
     $temp_file = TempFileProvider::generate("upload", ".{$extension}");
     error_log(print_r($track, true));
     error_log("Old Exists: " . (file_exists($track["tmp_name"]) ? 1 : 0));
     move_uploaded_file($track["tmp_name"], $temp_file);
     error_log("New Exists: " . (file_exists($temp_file) ? 1 : 0));
     $response->write($tm->upload($temp_file, $decoded_name));
 }
Пример #6
0
 public function doGet(JsonResponse $response, LoggedIn $me, $album_artist)
 {
     $artist_stats = (new SelectQuery(TSongs::_NAME))->selectAlias("COUNT(DISTINCT " . TSongs::T_ALBUM . ")", "albums_count")->selectAlias("COUNT(" . TSongs::ID . ")", "tracks_count")->selectAlias("SUM(" . TSongs::LENGTH . ")", "tracks_duration")->selectAlias("MIN(" . TSongs::C_BIG_ID . ")", TSongs::C_BIG_ID)->selectAlias("MIN(" . TSongs::C_MID_ID . ")", TSongs::C_MID_ID)->selectAlias("MIN(" . TSongs::C_SMALL_ID . ")", TSongs::C_SMALL_ID)->where(TSongs::USER_ID, $me->getId())->where(TSongs::A_ARTIST, $album_artist)->fetchOneRow()->get();
     $artist_stats["album_artist"] = $album_artist;
     $response->write($artist_stats);
 }
Пример #7
0
 public function doPost(JsonResponse $response, $track_artist)
 {
     $deleted_songs = Songs::deleteByArtist($track_artist);
     $response->write($deleted_songs);
 }
Пример #8
0
    return true;
}, E_ERROR);
// Set global exception handler
set_exception_handler(function (Exception $exception) {
    if ($exception instanceof ApplicationException) {
        $message = $exception->getMessage();
        $http_code = $exception->getHttpCode();
    } else {
        $message = $exception->getMessage();
        $http_code = HttpStatusCodes::HTTP_INTERNAL_SERVER_ERROR;
    }
    error_log("Exception: " . $exception->getMessage());
    error_log("Stacktrace: " . $exception->getTraceAsString());
    http_response_code($http_code);
    $response_data = array("message" => $message, "code" => $http_code);
    JsonResponse::ifInstance()->call("write", $response_data)->otherwise(Consumer::call([TinyView::class, "show"], "error.tmpl", $response_data));
});
// Scan autorun directory for executable scripts
foreach (scandir(AUTORUN_SCRIPTS_PATH) as $file) {
    if ($file == "." || $file == "..") {
        continue;
    }
    require_once AUTORUN_SCRIPTS_PATH . $file;
}
function static_class_init($class_name)
{
    if (class_exists($class_name) && method_exists($class_name, STATIC_CLASS_INIT_METHOD)) {
        $ref = new ReflectionMethod($class_name, STATIC_CLASS_INIT_METHOD);
        if ($ref->isStatic()) {
            Injector::run($ref);
        }
Пример #9
0
 public function doPost(JsonResponse $response)
 {
     $response->write(Songs::create(), 201);
 }
Пример #10
0
 public function doGet(JsonResponse $response, $playlist_id)
 {
     $playlist = new Playlist($playlist_id);
     $response->write($playlist);
 }
Пример #11
0
 public function doPost(JsonResponse $response, NewPlaylistForm $form)
 {
     $playlist = Playlist::create($form->getName());
     $response->write($playlist);
 }
Пример #12
0
 public function doGet(JsonResponse $response, LoggedIn $me)
 {
     $songs_count = (new SelectQuery(TSongs::_NAME))->select("COUNT(" . TSongs::ID . ")")->where(TSongs::USER_ID, $me->getId())->fetchColumn()->get();
     $response->write(["email" => $me->getEmail(), "name" => $me->getName(), "id" => $me->getId(), "stats" => ["tracks_count" => $songs_count, "artists_count" => 0, "albums_count" => 0, "genres_count" => 0, "compilations_count" => 0]]);
 }
Пример #13
0
 public function doGet(JsonResponse $response, $id, DatabaseConnection $connection)
 {
     /** @var Track $track */
     $track = $connection->getLightORM()->load(Track::class, $id);
     $response->write($track);
 }
Пример #14
0
 public function doGet(JsonResponse $response, LoggedIn $me)
 {
     $playlists = PlaylistDao::getList([TPlaylists::USER_ID => $me->getId()]);
     $playlist_objects = $playlists->map(Mapper::call(Playlist::class, "new"));
     $response->write($playlist_objects);
 }