Showing
8 changed files
with
143 additions
and
16 deletions
| ... | @@ -3,6 +3,7 @@ | ... | @@ -3,6 +3,7 @@ |
| 3 | namespace App\Http\Controllers\V1; | 3 | namespace App\Http\Controllers\V1; |
| 4 | 4 | ||
| 5 | use App\Http\Controllers\Controller; | 5 | use App\Http\Controllers\Controller; |
| 6 | +use App\Models\Immerse; | ||
| 6 | use App\Models\PackPoem; | 7 | use App\Models\PackPoem; |
| 7 | use Illuminate\Http\Request; | 8 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Support\Facades\Validator; | 9 | use Illuminate\Support\Facades\Validator; |
| ... | @@ -17,8 +18,11 @@ class HomeController extends Controller | ... | @@ -17,8 +18,11 @@ class HomeController extends Controller |
| 17 | */ | 18 | */ |
| 18 | public function index() | 19 | public function index() |
| 19 | { | 20 | { |
| 20 | - // | 21 | + // admin video |
| 21 | - return Response::success(); | 22 | + |
| 23 | + | ||
| 24 | + // user video | ||
| 25 | + return Response::success(Immerse::query()->get()); | ||
| 22 | } | 26 | } |
| 23 | 27 | ||
| 24 | 28 | ... | ... |
| ... | @@ -3,7 +3,12 @@ | ... | @@ -3,7 +3,12 @@ |
| 3 | namespace App\Http\Controllers\V1; | 3 | namespace App\Http\Controllers\V1; |
| 4 | 4 | ||
| 5 | use App\Http\Controllers\Controller; | 5 | use App\Http\Controllers\Controller; |
| 6 | +use App\Models\Immerse; | ||
| 7 | +use App\Models\UserMakeVideo; | ||
| 8 | +use App\Jobs\UserMakeVideo as MakeVideo; | ||
| 6 | use Illuminate\Http\Request; | 9 | use Illuminate\Http\Request; |
| 10 | +use Illuminate\Support\Facades\Validator; | ||
| 11 | +use Jiannei\Response\Laravel\Support\Facades\Response; | ||
| 7 | 12 | ||
| 8 | class ImmerseController extends Controller | 13 | class ImmerseController extends Controller |
| 9 | { | 14 | { |
| ... | @@ -21,16 +26,46 @@ class ImmerseController extends Controller | ... | @@ -21,16 +26,46 @@ class ImmerseController extends Controller |
| 21 | * Store a newly created resource in storage. | 26 | * Store a newly created resource in storage. |
| 22 | * | 27 | * |
| 23 | * @param \Illuminate\Http\Request $request | 28 | * @param \Illuminate\Http\Request $request |
| 24 | - * @return \Illuminate\Http\Response | 29 | + * @throws \Illuminate\Validation\ValidationException |
| 30 | + * @return \Illuminate\Http\JsonResponse | ||
| 25 | */ | 31 | */ |
| 26 | public function store(Request $request) | 32 | public function store(Request $request) |
| 27 | { | 33 | { |
| 28 | - //todo 发布流程 | 34 | + $validator = Validator::make($request->all(),[ |
| 29 | - // if type == 1 | 35 | + 'video_url' => 'required|string', |
| 30 | - // 写入audio-show表,写入immerse表,发送异步转码任务, | 36 | + 'video_id' => 'required', |
| 31 | - // if type == 2 | 37 | + 'content' => 'sometimes', |
| 32 | - // 写入video-show表,写入immerse表,发送异步转码合成视频水印任务 | 38 | + 'weather' => 'sometimes', |
| 39 | + 'thumbnail_url' => 'sometimes', | ||
| 40 | + ]); | ||
| 41 | + | ||
| 42 | + if ($validator->fails()){ | ||
| 43 | + return Response::fail('',500,$validator->errors()); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + $validated = $validator->validated(); | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + $immerse = Immerse::query()->find($request->video_id); | ||
| 50 | + | ||
| 51 | + $video = UserMakeVideo::query()->create([ | ||
| 52 | + 'poem_id' => $immerse->poem_id, | ||
| 53 | + 'type' => $immerse->type, | ||
| 54 | + 'video_url' => $validated['video_url'], | ||
| 55 | + 'image_url' => $immerse->image_url, | ||
| 56 | + 'bg_music' => $immerse->bg_music, | ||
| 57 | + 'bgm_url' => $immerse->bgm_url, | ||
| 58 | + 'feel' => $validated['content'], | ||
| 59 | + 'weather' => $validated['weather'], | ||
| 60 | + 'temp_id' => $immerse->temp_id, | ||
| 61 | + 'thumbnail' => $validated['thumbnail_url'] ? 1 : 0, | ||
| 62 | + 'thumbnail_url' => $validated['thumbnail_url'], | ||
| 63 | + ]); | ||
| 64 | + | ||
| 65 | + // 添加至队列 | ||
| 66 | + MakeVideo::dispatch($video); | ||
| 33 | 67 | ||
| 68 | + return Response::created(); | ||
| 34 | } | 69 | } |
| 35 | 70 | ||
| 36 | /** | 71 | /** | ... | ... |
| ... | @@ -37,7 +37,7 @@ class SettingController extends Controller | ... | @@ -37,7 +37,7 @@ class SettingController extends Controller |
| 37 | return Response::success($array); | 37 | return Response::success($array); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | - public function upload(Request $request) | 40 | + public function uploadImage(Request $request) |
| 41 | { | 41 | { |
| 42 | $validator = Validator::make($request->all(),[ | 42 | $validator = Validator::make($request->all(),[ |
| 43 | 'image' => 'required|mimes:jpeg,png,bmp,gif' | 43 | 'image' => 'required|mimes:jpeg,png,bmp,gif' |
| ... | @@ -59,12 +59,41 @@ class SettingController extends Controller | ... | @@ -59,12 +59,41 @@ class SettingController extends Controller |
| 59 | $dir_l2 = hexdec($hash_hex_l2) % 512; | 59 | $dir_l2 = hexdec($hash_hex_l2) % 512; |
| 60 | $dir = 'uploads/'. $dir_l1. '/' . $dir_l2; | 60 | $dir = 'uploads/'. $dir_l1. '/' . $dir_l2; |
| 61 | 61 | ||
| 62 | - if( !Storage::disk('public')->exists($dir)) { | 62 | + if( !Storage::disk('public')->exists($dir)) Storage::disk('public')->makeDirectory($dir); |
| 63 | 63 | ||
| 64 | - Storage::disk('public')->makeDirectory($dir); | 64 | + $file = $request->file('image')->store($dir,'public'); |
| 65 | + | ||
| 66 | + return Response::success([ | ||
| 67 | + 'relative_path' => $file, | ||
| 68 | + 'absolute_path' => Storage::disk('public')->url($file), | ||
| 69 | + ]); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public function uploadVideo(Request $request) | ||
| 73 | + { | ||
| 74 | + $validator = Validator::make($request->all(),[ | ||
| 75 | + 'video' => 'required|mimes:mp4,flv,mov,avi' | ||
| 76 | + ]); | ||
| 77 | + | ||
| 78 | + if ($validator->fails()){ | ||
| 79 | + return Response::fail('',500,$validator->errors()); | ||
| 65 | } | 80 | } |
| 66 | 81 | ||
| 67 | - $file = $request->file('image')->store($dir,'public'); | 82 | + $hashName = $request->file('video')->hashName(); |
| 83 | + | ||
| 84 | + $hash_hex = md5($hashName); | ||
| 85 | + | ||
| 86 | + // 16进制表示的字符串一共32字节,表示16个二进制字节。 | ||
| 87 | + // 前16个字符用来第一级求摸,后16个用做第二级 | ||
| 88 | + $hash_hex_l1 = substr($hash_hex, 0, 8); | ||
| 89 | + $hash_hex_l2 = substr($hash_hex, 8, 8); | ||
| 90 | + $dir_l1 = hexdec($hash_hex_l1) % 256; | ||
| 91 | + $dir_l2 = hexdec($hash_hex_l2) % 512; | ||
| 92 | + $dir = 'uploads/'. $dir_l1. '/' . $dir_l2; | ||
| 93 | + | ||
| 94 | + if( !Storage::disk('public')->exists($dir)) Storage::disk('public')->makeDirectory($dir); | ||
| 95 | + | ||
| 96 | + $file = $request->file('video')->store($dir,'public'); | ||
| 68 | 97 | ||
| 69 | return Response::success([ | 98 | return Response::success([ |
| 70 | 'relative_path' => $file, | 99 | 'relative_path' => $file, | ... | ... |
| ... | @@ -604,7 +604,7 @@ class MakeVideo implements ShouldQueue | ... | @@ -604,7 +604,7 @@ class MakeVideo implements ShouldQueue |
| 604 | foreach ($components as $component) { | 604 | foreach ($components as $component) { |
| 605 | switch ($component->name){ | 605 | switch ($component->name){ |
| 606 | case 'one_poem': | 606 | case 'one_poem': |
| 607 | - $content = $this->adminMakeVideo->poem->content . PHP_EOL; | 607 | + $content = $this->adminMakeVideo->poem->content; |
| 608 | $text_file = $this->getTempPath('txt'); | 608 | $text_file = $this->getTempPath('txt'); |
| 609 | file_put_contents($text_file, $content); | 609 | file_put_contents($text_file, $content); |
| 610 | 610 | ||
| ... | @@ -619,7 +619,7 @@ class MakeVideo implements ShouldQueue | ... | @@ -619,7 +619,7 @@ class MakeVideo implements ShouldQueue |
| 619 | 'fontcolor=' . $text_color . '@1.0:' . | 619 | 'fontcolor=' . $text_color . '@1.0:' . |
| 620 | 'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' . | 620 | 'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' . |
| 621 | 'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' . | 621 | 'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' . |
| 622 | - 'box=1:boxcolor=' . $text_bg_color . '@' . $opacity . '", '; | 622 | + 'box=1:boxborderw=1:boxcolor=' . $text_bg_color . '@' . $opacity . '", '; |
| 623 | 623 | ||
| 624 | break; | 624 | break; |
| 625 | case 'every_poem': | 625 | case 'every_poem': | ... | ... |
app/Jobs/UserMakeVideo.php
0 → 100644
This diff is collapsed. Click to expand it.
app/Models/UserMakeVideo.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use Illuminate\Database\Migrations\Migration; | ||
| 4 | +use Illuminate\Database\Schema\Blueprint; | ||
| 5 | +use Illuminate\Support\Facades\Schema; | ||
| 6 | + | ||
| 7 | +class CreateUserMakeVideosTable extends Migration | ||
| 8 | +{ | ||
| 9 | + /** | ||
| 10 | + * Run the migrations. | ||
| 11 | + * | ||
| 12 | + * @return void | ||
| 13 | + */ | ||
| 14 | + public function up() | ||
| 15 | + { | ||
| 16 | + Schema::create('user_make_videos', function (Blueprint $table) { | ||
| 17 | + $table->id(); | ||
| 18 | + $table->unsignedInteger('user_id')->comment('用户id'); | ||
| 19 | + $table->string('poem_id')->default('')->comment('一言id'); | ||
| 20 | + $table->unsignedTinyInteger('type')->comment('类型'); | ||
| 21 | + $table->string('video_url')->nullable()->comment('视频地址'); | ||
| 22 | + $table->string('images_url')->nullable()->comment('图片地址'); | ||
| 23 | + $table->unsignedTinyInteger('bg_music')->comment('是否背景音'); | ||
| 24 | + $table->string('bgm_url')->nullable()->comment('背景音地址'); | ||
| 25 | + $table->text('feel')->nullable()->comment('有感'); | ||
| 26 | + $table->text('weather')->nullable()->comment('天气'); | ||
| 27 | + $table->string('temp_id')->default('')->comment('模板id'); | ||
| 28 | + $table->unsignedTinyInteger('thumbnail')->comment('封面图'); | ||
| 29 | + $table->string('thumbnail_url')->nullable()->comment('封面图地址'); | ||
| 30 | + $table->timestamps(); | ||
| 31 | + }); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Reverse the migrations. | ||
| 36 | + * | ||
| 37 | + * @return void | ||
| 38 | + */ | ||
| 39 | + public function down() | ||
| 40 | + { | ||
| 41 | + Schema::dropIfExists('user_make_videos'); | ||
| 42 | + } | ||
| 43 | +} |
| ... | @@ -59,6 +59,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route | ... | @@ -59,6 +59,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route |
| 59 | /** 会员页 */ | 59 | /** 会员页 */ |
| 60 | $api->apiResource('/membership', 'MembershipController'); | 60 | $api->apiResource('/membership', 'MembershipController'); |
| 61 | 61 | ||
| 62 | - /** 文件上传 */ | 62 | + /** 图片上传 */ |
| 63 | - $api->post('/upload/image', 'SettingController@upload'); | 63 | + $api->post('/upload/image', 'SettingController@uploadImage'); |
| 64 | + | ||
| 65 | + /** 视频上传 */ | ||
| 66 | + $api->post('/upload/video', 'SettingController@uploadVideo'); | ||
| 64 | }); | 67 | }); |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment