Commit f91c4d5d by 杨昕

添加定时脚本处理

parent 1c5fd782
Pipeline #10084 passed with stages
in 39 seconds
...@@ -188,5 +188,27 @@ class MediaController extends Controller ...@@ -188,5 +188,27 @@ class MediaController extends Controller
} }
/**
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
*/
public function handleMediaUrl(Request $request){
$res = handler_drive(function () use($request){
SrsHookValidate::srsHookCallback($request,[
'media_name' => '',
'username' => '',
'page' => 'integer',
'media_id' => '',
'description' => '',
'sort' => '',
'page_size' => 'integer',
]);
return MediaModel::handleMediaUrl($request);
});
return success($res);
}
} }
...@@ -21,6 +21,8 @@ class MediaModel extends Eloquent ...@@ -21,6 +21,8 @@ class MediaModel extends Eloquent
protected $fillable = []; protected $fillable = [];
public $timestamps = false;
public function media_category() public function media_category()
...@@ -388,4 +390,76 @@ class MediaModel extends Eloquent ...@@ -388,4 +390,76 @@ class MediaModel extends Eloquent
return $media; return $media;
} }
public static function handleMediaUrl($request){
try{
$medias = MediaModel::query()->raw(function ($collection) use($request){
$limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER) ;
$page = $request->page??1;
/**
* 默认降序
*/
$sort = -1;
if ($request->sort == 'asc'){
$sort = 1;
}
if (isset($request->media_id) && !empty($request->media_id)){
$aggregate[]['$match']['_id'] = $request->media_id;
}
if (isset($request->media_name) && !empty($request->media_name)){
$aggregate[]['$match']['media_url'] = ['$regex' => 'https://qcoenfz67.bkt.clouddn.com' ];
}
if (isset($request->username) && !empty($request->username)){
$aggregate[]['$match']['username'] = $request->username;
}
$aggregate[]['$sort'] = ['start_time' => $sort];
$count = sizeof($collection->aggregate($aggregate)->toArray());
$skip = ((empty($request->page) ? 1 : $request->page)-1) * $limit;
$aggregate[]['$skip'] = $skip;
$aggregate[]['$limit'] = $limit;
return new LengthAwarePaginator($collection->aggregate($aggregate)->toArray(), $count, $limit, $page,[
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page',
]);
});
if (!empty($medias)){
foreach ($medias as $media){
$data = [
'media_url' => "https://vod-mam.eoffcn.com/".$media->_id.'/index.m3u8',
];
$flag = MediaModel::where("_id",$media->_id)->update($data);
if ($flag==0){
throw new \Exception("更新失败");
}
}
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $medias;
}
} }
...@@ -43,5 +43,7 @@ Route::group(['namespace' => 'Api', 'prefix' => 'user'], function () { ...@@ -43,5 +43,7 @@ Route::group(['namespace' => 'Api', 'prefix' => 'user'], function () {
Route::post("media_list","MediaController@media_list"); Route::post("media_list","MediaController@media_list");
Route::get("play_url/{id}","MediaController@play_url"); Route::get("play_url/{id}","MediaController@play_url");
Route::get("media_url_change","Client\MediaController@handleMediaUrl");
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment