Commit a6b3f90a by 杨昕

Merge branch 'test' into 'master'

Test

See merge request !20
parents 02e2b69c 08015594
Pipeline #10616 passed with stages
in 42 seconds
......@@ -58,7 +58,7 @@ class Handler extends ExceptionHandler
// var_dump($exception->getMessage());
// var_dump($exception->getFile());
// var_dump($exception->getLine());die;
// var_dump($exception->getLine());
#检测当前请求是否是api路由
......@@ -86,6 +86,8 @@ class Handler extends ExceptionHandler
return error('请求接口过于频繁',429);
}
}else if($exception instanceof \RedisException){
return error('redis连接异常');
}
if ($request->is('api/*')) {
......
......@@ -182,27 +182,5 @@ 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);
}
}
......@@ -2,12 +2,16 @@
namespace App\Http\Controllers\Api;
use App\Exceptions\FormException;
use App\Model\MediaModel;
use App\Model\QiniuModel;
use App\Tool\SrsHookValidate;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use MongoBinData;
use MongoDB\BSON\UTCDateTime;
use Qiniu\Auth;
class MediaController extends Controller
......@@ -53,12 +57,139 @@ class MediaController extends Controller
/**
* 获取媒资列表
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
*/
public function mediaListOnce(Request $request){
$res = handler_drive(function () use($request){
SrsHookValidate::srsHookCallback($request,[
'page' => 'integer',
'sort' => '',
'page_size' => 'integer',
'start_time' => 'date',
'end_time' => 'date',
]);
return MediaModel::mediaList($request);
});
return success($res);
}
/**
* @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);
}
/**
* 视频上传成功之后,回调重新上传
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
*/
public function hookRestoreMedia(Request $request){
$id = handler_drive(function () use ($request) {
SrsHookValidate::srsHookCallback($request,array_merge([
'media_name' => 'required',
'secret_key' => '',
'media_url' => 'required',
'description' => '',
]));
$data_time = Carbon::now();
$params = array(
'media_id' => 'mda-'.generateRandomNum(16),
'media_type'=> '5efa9cb5d16f5a214671fd86',
'start_time'=> $data_time,
'end_time' => $data_time,
'access_key'=> '',
'description'=>'网校',
'create_time'=> $data_time,
);
$request->replace(array_merge($request->all(),$params));
$id = MediaModel::hookRestoreMedia($request);
return $id;
});
return success($id);
}
/**
* 更新百度status
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
*/
public function updateMediaStatus(Request $request,$media_id){
$id = handler_drive(function () use ($request,$media_id) {
SrsHookValidate::srsHookCallback($request,[
'status' => ''
]);
$id = MediaModel::updateMediaStatus($request,$media_id);
return $id;
});
return success($id);
}
/**
* 更新数据日期
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
*/
public function updateDatetime(Request $request){
$id = handler_drive(function () use ($request) {
$id = MediaModel::updateDatetime($request);
return $id;
});
return success($id);
}
}
......@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Web;
use App\Model\MediaCategoryModel;
use App\Model\MediaModel;
use App\Tool\SrsHookValidate;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
......@@ -18,6 +19,7 @@ class MediaController extends Controller
* @throws \App\Exceptions\FormException
*/
public function index(Request $request){
// php 特殊字符转义,实现字符串安全存入数据库,
SrsHookValidate::srsHookCallback($request,[
......@@ -117,6 +119,17 @@ class MediaController extends Controller
'media_url' => 'required',
]);
$data_time = Carbon::now();
$params = array(
'start_time'=> $data_time,
'end_time' => $data_time,
'create_time'=> $data_time,
);
$request->replace(array_merge($request->all(),$params));
return MediaModel::hookRestoreMedia($request);
});
......
......@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class ModuleModel extends Model
{
public static function getModuleList(){
$module = file_get_contents('module.json');
$module = file_get_contents(public_path('module.json'));
return json_decode($module,true);
}
}
<?php
namespace App\Model;
use App\Exceptions\DatabaseException;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class RecycleModel extends Eloquent
{
/**
* mongodb collection 名字
*/
protected $collection = 'recycle';
protected $connection = 'mongodb'; //使用mongodb
protected $primaryKey = '_id';
public static function addRecycle($obj_id,$obj_type="media"){
$recycle = RecycleModel::where([
"obj_type" => $obj_type,
"obj_id" => $obj_id,
])->first();
if (!empty($recycle)){
throw new \Exception("回收站已存在");
}
$obj_model = 'App\\Model\\'.ucfirst($obj_type).'Model';
$model = new $obj_model();
$obj = $model->find($obj_id)->toArray();
if (empty($obj)){
throw new \Exception('数据不存在');
}
$data = [
'obj_id' => $obj_id,
'obj_type' => $obj_type,
'content' => json_encode($obj),
'create_time'=> date('Y-m-d H:i:s',time())
];
$id = RecycleModel::insertGetId($data);
if (!$id){
throw new \Exception('添加回收站失败');
}
return $id;
}
}
#!/usr/bin/env bash
WORK_DIR=$1
if [ ! -n "${WORK_DIR}" ] ;then
WORK_DIR="."
fi
echo "Restarting LaravelS..."
./bin/laravels restart -d -i
echo "Starting fswatch..."
LOCKING=0
fswatch -e ".*" -i "\\.php$" -r ${WORK_DIR} | while read file
do
if [[ ! ${file} =~ .php$ ]] ;then
continue
fi
if [ ${LOCKING} -eq 1 ] ;then
echo "Reloading, skipped."
continue
fi
echo "File ${file} has been modified."
LOCKING=1
./bin/laravels reload
LOCKING=0
done
exit 0
\ No newline at end of file
#!/usr/bin/env bash
WORK_DIR=$1
if [ ! -n "${WORK_DIR}" ] ;then
WORK_DIR="."
fi
echo "Restarting LaravelS..."
./bin/laravels restart -d -i
echo "Starting inotifywait..."
LOCKING=0
inotifywait --event modify --event create --event move --event delete -mrq ${WORK_DIR} | while read file
do
if [[ ! ${file} =~ .php$ ]] ;then
continue
fi
if [ ${LOCKING} -eq 1 ] ;then
echo "Reloading, skipped."
continue
fi
echo "File ${file} has been modified."
LOCKING=1
./bin/laravels reload
LOCKING=0
done
exit 0
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
* This autoloader is only used to pull laravel-s.
* Class Psr4Autoloader
*/
class Psr4Autoloader
{
/**
* An associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected $prefixes = array();
/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
}
/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $base_dir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
* @return void
*/
public function addNamespace($prefix, $base_dir, $prepend = false)
{
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/';
// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = array();
}
// retain the base directory for the namespace prefix
if ($prepend) {
array_unshift($this->prefixes[$prefix], $base_dir);
} else {
array_push($this->prefixes[$prefix], $base_dir);
}
}
/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
* @return mixed The mapped file name on success, or boolean false on
* failure.
*/
public function loadClass($class)
{
// the current namespace prefix
$prefix = $class;
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (false !== $pos = strrpos($prefix, '\\')) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
// the rest is the relative class name
$relative_class = substr($class, $pos + 1);
// try to load a mapped file for the prefix and relative class
$mapped_file = $this->loadMappedFile($prefix, $relative_class);
if ($mapped_file) {
return $mapped_file;
}
// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
}
// never found a mapped file
return false;
}
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function loadMappedFile($prefix, $relative_class)
{
// are there any base directories for this namespace prefix?
if (isset($this->prefixes[$prefix]) === false) {
return false;
}
// look through base directories for this namespace prefix
foreach ($this->prefixes[$prefix] as $base_dir) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir
. str_replace('\\', '/', $relative_class)
. '.php';
// if the mapped file exists, require it
if ($this->requireFile($file)) {
// yes, we're done
return $file;
}
}
// never found it
return false;
}
/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
* @return bool True if the file exists, false if not.
*/
protected function requireFile($file)
{
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
}
$basePath = realpath(__DIR__ . '/../');
$loader = new Psr4Autoloader();
$loader->register();
// Register laravel-s
$loader->addNamespace('Hhxsv5\LaravelS', $basePath . '/vendor/hhxsv5/laravel-s/src');
// Register laravel-s dependencies
$loader->addNamespace('Symfony\Component\Console', $basePath . '/vendor/symfony/console');
$loader->addNamespace('Symfony\Contracts\Service', $basePath . '/vendor/symfony/service-contracts');
$loader->addNamespace('Symfony\Contracts', $basePath . '/vendor/symfony/contracts');
$command = new Hhxsv5\LaravelS\Console\Portal($basePath);
$input = new Symfony\Component\Console\Input\ArgvInput();
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$code = $command->run($input, $output);
exit($code);
\ No newline at end of file
......@@ -10,6 +10,7 @@
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"hhxsv5/laravel-s": "~3.7.0",
"jacobcyl/ali-oss-storage": "^2.1",
"jenssegers/mongodb": "^3.4.1",
"laravel/framework": "5.7.*",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "406acf0914b165793ca0d5c7e37f7408",
"content-hash": "7214d6941783eda5b5d4a23e562f5e10",
"packages": [
{
"name": "aliyuncs/oss-sdk-php",
......@@ -622,6 +622,84 @@
"time": "2019-07-01T23:21:34+00:00"
},
{
"name": "hhxsv5/laravel-s",
"version": "v3.7.6",
"source": {
"type": "git",
"url": "https://github.com/hhxsv5/laravel-s.git",
"reference": "f0c0275f875072f0b6ac74e5d5a320c2ab5950f9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hhxsv5/laravel-s/zipball/f0c0275f875072f0b6ac74e5d5a320c2ab5950f9",
"reference": "f0c0275f875072f0b6ac74e5d5a320c2ab5950f9",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-pcntl": "*",
"php": ">=5.5.9",
"swoole/ide-helper": "@dev",
"symfony/console": ">=2.7.0"
},
"require-dev": {
"phpunit/phpunit": ">=4.8.36"
},
"suggest": {
"ext-inotify": "Inotify, used to real-time reload.",
"ext-swoole": "Coroutine based Async PHP programming framework, require >= 1.7.19."
},
"bin": [
"bin/fswatch"
],
"type": "library",
"extra": {
"laravel": {
"providers": [
"Hhxsv5\\LaravelS\\Illuminate\\LaravelSServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Hhxsv5\\LaravelS\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Xie Biao",
"email": "hhxsv5@sina.com"
}
],
"description": "🚀 LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.",
"homepage": "https://github.com/hhxsv5/laravel-s",
"keywords": [
"LaravelS",
"async",
"coroutine",
"http",
"inotify",
"laravel",
"laravel-s",
"lumen",
"performance",
"process",
"server",
"swoole",
"task",
"tcp",
"timer",
"udp",
"websocket"
],
"time": "2020-07-20T16:24:14+00:00"
},
{
"name": "jacobcyl/ali-oss-storage",
"version": "2.1.0",
"source": {
......@@ -2522,6 +2600,40 @@
"time": "2019-11-12T09:31:26+00:00"
},
{
"name": "swoole/ide-helper",
"version": "4.5.2",
"source": {
"type": "git",
"url": "https://github.com/swoole/ide-helper.git",
"reference": "e45892fb913204fc776bdec019ca8b723e7249b1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swoole/ide-helper/zipball/e45892fb913204fc776bdec019ca8b723e7249b1",
"reference": "e45892fb913204fc776bdec019ca8b723e7249b1",
"shasum": ""
},
"require-dev": {
"guzzlehttp/guzzle": "~6.5.0",
"laminas/laminas-code": "~3.4.0",
"squizlabs/php_codesniffer": "~3.5.0",
"symfony/filesystem": "~4.0"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Team Swoole",
"email": "team@swoole.com"
}
],
"description": "IDE help files for Swoole.",
"time": "2020-05-28T19:17:49+00:00"
},
{
"name": "symfony/console",
"version": "v4.4.10",
"source": {
......
......@@ -123,7 +123,7 @@ return [
'redis' => [
'client' => 'predis',
'client' => 'phpredis',
'default' => [
// 'host' => env('rd_host', 'offcn-redis-svc'),
......
<?php
/**
* @see https://github.com/hhxsv5/laravel-s/blob/master/Settings-CN.md Chinese
* @see https://github.com/hhxsv5/laravel-s/blob/master/Settings.md English
*/
return [
'listen_ip' => env('LARAVELS_LISTEN_IP', '127.0.0.1'),
'listen_port' => env('LARAVELS_LISTEN_PORT', 5200),
'socket_type' => defined('SWOOLE_SOCK_TCP') ? SWOOLE_SOCK_TCP : 1,
'enable_coroutine_runtime' => false,
'server' => env('LARAVELS_SERVER', 'LaravelS'),
'handle_static' => env('LARAVELS_HANDLE_STATIC', false),
'laravel_base_path' => env('LARAVEL_BASE_PATH', base_path()),
'inotify_reload' => [
'enable' => env('LARAVELS_INOTIFY_RELOAD', false),
'watch_path' => base_path(),
'file_types' => ['.php'],
'excluded_dirs' => [],
'log' => true,
],
'event_handlers' => [],
'websocket' => [
'enable' => false,
//'handler' => XxxWebSocketHandler::class,
],
'sockets' => [],
'processes' => [
//[
// 'class' => \App\Processes\TestProcess::class,
// 'redirect' => false, // Whether redirect stdin/stdout, true or false
// 'pipe' => 0 // The type of pipeline, 0: no pipeline 1: SOCK_STREAM 2: SOCK_DGRAM
// 'enable' => true // Whether to enable, default true
//],
],
'timer' => [
'enable' => env('LARAVELS_TIMER', false),
'jobs' => [
// Enable LaravelScheduleJob to run `php artisan schedule:run` every 1 minute, replace Linux Crontab
//\Hhxsv5\LaravelS\Illuminate\LaravelScheduleJob::class,
// Two ways to configure parameters:
// [\App\Jobs\XxxCronJob::class, [1000, true]], // Pass in parameters when registering
// \App\Jobs\XxxCronJob::class, // Override the corresponding method to return the configuration
],
'max_wait_time' => 5,
],
'swoole_tables' => [],
'register_providers' => [],
'cleaners' => [
// See LaravelS's built-in cleaners: https://github.com/hhxsv5/laravel-s/blob/master/Settings.md#cleaners
],
'destroy_controllers' => [
'enable' => false,
'excluded_list' => [
//\App\Http\Controllers\TestController::class,
],
],
'swoole' => [
'daemonize' => env('LARAVELS_DAEMONIZE', false),
'dispatch_mode' => 2,
'reactor_num' => env('LARAVELS_REACTOR_NUM', function_exists('swoole_cpu_num') ? swoole_cpu_num() * 2 : 4),
'worker_num' => env('LARAVELS_WORKER_NUM', function_exists('swoole_cpu_num') ? swoole_cpu_num() * 2 : 8),
//'task_worker_num' => env('LARAVELS_TASK_WORKER_NUM', function_exists('swoole_cpu_num') ? swoole_cpu_num() * 2 : 8),
'task_ipc_mode' => 1,
'task_max_request' => env('LARAVELS_TASK_MAX_REQUEST', 8000),
'task_tmpdir' => @is_writable('/dev/shm/') ? '/dev/shm' : '/tmp',
'max_request' => env('LARAVELS_MAX_REQUEST', 8000),
'open_tcp_nodelay' => true,
'pid_file' => storage_path('laravels.pid'),
'log_file' => storage_path(sprintf('logs/swoole-%s.log', date('Y-m'))),
'log_level' => 4,
'document_root' => base_path('public'),
'buffer_output_size' => 2 * 1024 * 1024,
'socket_buffer_size' => 128 * 1024 * 1024,
'package_max_length' => 4 * 1024 * 1024,
'reload_async' => true,
'max_wait_time' => 60,
'enable_reuse_port' => true,
'enable_coroutine' => false,
'http_compression' => false,
// Slow log
// 'request_slowlog_timeout' => 2,
// 'request_slowlog_file' => storage_path(sprintf('logs/slow-%s.log', date('Y-m'))),
// 'trace_event_worker' => true,
/**
* More settings of Swoole
* @see https://wiki.swoole.com/#/server/setting Chinese
* @see https://www.swoole.co.uk/docs/modules/swoole-server/configuration English
*/
],
];
<!DOCTYPE html>
<html>
@include('admin.common.commonMedia')
<body>
<!--====================================================
MAIN NAVBAR
======================================================-->
@include('admin.common.header')
<!--====================================================
PAGE CONTENT
======================================================-->
<div class="page-content d-flex align-items-stretch">
<!--***** SIDE NAVBAR *****-->
@include('admin.common.left')
<div class="content-inner">
<div class="row" id="report4">
<div class="col-md-3" onclick="important_task('/web/pending_news')">
<div class="card text-center social-bottom sb-gp">
<i class="fa fa-google-plus"></i>
<div>0 </div>
<p>我的待办</p>
</div>
</div>
<div class="col-md-3">
<div class="card text-center social-bottom sb-fb">
<i class="fa fa-facebook"></i>
<div>100 +</div>
<p>普通会员</p>
</div>
</div>
<div class="col-md-3">
<div class="card text-center social-bottom sb-tw">
<i class="fa fa-twitter"></i>
<div>100 +</div>
<p>管理员</p>
</div>
</div>
<div class="col-md-3">
<div class="card text-center social-bottom sb-in">
<i class="fa fa-instagram"></i>
<div>500 +</div>
<p>已发布新闻</p>
</div>
</div>
</div>
<!--***** REPORT-2 *****-->
<div class="row" id="report2">
<div class="col-md-6">
<div class="card card-c1">
<div class="card-header card-chart" data-background-color="green">
<canvas class="ct-chart" id="myChart1" height="190"></canvas>
</div>
<div class="card-content">
<h4 class="title">Daily Sales</h4>
<p class="category">
<span class="text-success"><i class="fa fa-long-arrow-up"></i> 55% </span> increase in today sales.</p>
</div>
<div class="card-footer">
<div class="stats">
<i class="fa fa-clock-o"></i> updated 4 minutes ago
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card card-c1">
<div class="card-header card-chart" data-background-color="orange">
<canvas class="ct-chart" id="myChart2" height="190"></canvas>
</div>
<div class="card-content">
<h4 class="title">Email Subscriptions</h4>
<p class="category">Last Campaign Performance</p>
</div>
<div class="card-footer">
<div class="stats">
<i class="fa fa-clock-o"></i> campaign sent 2 days ago
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Global Javascript -->
@include('admin.common.foot')
<!--Core Javascript -->
<script src="{{ asset('xadmin/js/mychart.js')}}"></script>
<script>
function important_task(url){
window.location.href = url;
}
</script>
</body>
</html>
\ No newline at end of file
......@@ -31,8 +31,6 @@ Route::group(['namespace' => 'Api', 'prefix' => 'v1', 'middleware' => ['auth']],
Route::get('media_list', 'Client\MediaController@mediaList');
});
......@@ -43,7 +41,11 @@ Route::group(['namespace' => 'Api', 'prefix' => 'user'], function () {
Route::post("media_list","MediaController@media_list");
Route::get("play_url/{id}","MediaController@play_url");
Route::get("media_url_change","Client\MediaController@handleMediaUrl");
Route::get("media_list_once","MediaController@mediaListOnce");
Route::post('hook_restore', 'MediaController@hookRestoreMedia');
Route::post('update_status/{id}', 'MediaController@updateMediaStatus');
//Route::get("media_url_change","MediaController@handleMediaUrl");
});
\ No newline at end of file
No preview for this file type
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