public function doGet() { Songs::wipeOldPreviews(); FileServer::removeUnused(); FileServer::removeDead(); $limit = 30; while ($limit-- > 0) { set_time_limit(30); (new SelectQuery(TSongs::_NAME))->select(TSongs::FILE_NAME, TSongs::FILE_ID, TSongs::ID)->where(TSongs::PEAKS_ID . " IS NULL")->where(TSongs::FILE_ID . " IS NOT NULL")->limit(1)->eachRow(function ($row) { Logger::printf("Creating peaks for file: %s", $row[TSongs::FILE_NAME]); $peaks = WaveformGenerator::generate(FileServer::getFileUsingId($row[TSongs::FILE_ID])); $file_id = FileServer::registerByContent(json_encode($peaks), "application/json"); SongDao::updateSongUsingId($row[TSongs::ID], [TSongs::PEAKS_ID => $file_id]); }); sleep(1); } }
/** * @return mixed */ private function getFilePath() { return FileServer::getFileUsingId($this->track_data[TSongs::FILE_ID]); }
public function doGet($id) { FileServer::sendToClient($id); }
public static function changeCover($song_id, $cover_file) { $song_ids = explode(",", $song_id); $song_objects = (new SelectQuery(TSongs::_NAME))->where(TSongs::ID, $song_ids)->where(TSongs::USER_ID, self::$me->getId())->fetchAll(); // Delete exists covers foreach ($song_objects as $song) { if ($song[TSongs::C_SMALL_ID]) { FileServer::unregister($song[TSongs::C_SMALL_ID]); } if ($song[TSongs::C_MID_ID]) { FileServer::unregister($song[TSongs::C_MID_ID]); } if ($song[TSongs::C_BIG_ID]) { FileServer::unregister($song[TSongs::C_BIG_ID]); } } $covers = FFProbe::readTempCovers($cover_file)->getOrThrow(ControllerException::class, "Image file is corrupted"); $query = (new UpdateQuery(TSongs::_NAME))->where(TSongs::ID, $song_ids)->where(TSongs::USER_ID, self::$me->getId()); $full_cover_id = FileServer::register($covers[0]); $middle_cover_id = FileServer::register($covers[1]); $small_cover_id = FileServer::register($covers[2]); $query->set(TSongs::C_SMALL_ID, $small_cover_id)->set(TSongs::C_MID_ID, $middle_cover_id)->set(TSongs::C_BIG_ID, $full_cover_id); $query->returning(implode(",", [TSongs::ID, TSongs::C_SMALL_ID, TSongs::C_MID_ID, TSongs::C_BIG_ID])); return $query->fetchAll(); }
public static function removeUnused() { $unused_files = (new SelectQuery(TFiles::_NAME))->where(TFiles::USED, 0)->fetchAll(); foreach ($unused_files as $file) { Logger::printf("Deleting unused file with id = %s, size = %d", $file[TFiles::ID], $file[TFiles::SIZE]); FileServer::findFileUsingId($file[TFiles::ID])->filter("file_exists")->then("unlink"); (new DeleteQuery(TFiles::_NAME))->where(TFiles::ID, $file[TFiles::ID])->update(); } }