Showing
4 changed files
with
55 additions
and
0 deletions
| ... | @@ -4,6 +4,7 @@ namespace App\Http\Controllers\V1; | ... | @@ -4,6 +4,7 @@ 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\Immerse; |
| 7 | +use App\Models\OnePoem; | ||
| 7 | use App\Models\PackPoem; | 8 | use App\Models\PackPoem; |
| 8 | use Illuminate\Http\Request; | 9 | use Illuminate\Http\Request; |
| 9 | use Jiannei\Response\Laravel\Support\Facades\Response; | 10 | use Jiannei\Response\Laravel\Support\Facades\Response; |
| ... | @@ -69,4 +70,13 @@ class HomeController extends Controller | ... | @@ -69,4 +70,13 @@ class HomeController extends Controller |
| 69 | return Response::success($packpoems); | 70 | return Response::success($packpoems); |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 73 | + | ||
| 74 | + public function poem($id) | ||
| 75 | + { | ||
| 76 | + try{ | ||
| 77 | + return Response::success(OnePoem::query()->find($id)); | ||
| 78 | + }catch (\Exception $exception){ | ||
| 79 | + return Response::fail($exception->getMessage()); | ||
| 80 | + } | ||
| 81 | + } | ||
| 72 | } | 82 | } | ... | ... |
| ... | @@ -101,6 +101,38 @@ class SettingController extends Controller | ... | @@ -101,6 +101,38 @@ class SettingController extends Controller |
| 101 | ]); | 101 | ]); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | + public function uploadAudio(Request $request) | ||
| 105 | + { | ||
| 106 | + $validator = Validator::make($request->all(),[ | ||
| 107 | + 'audio' => 'required|mimes:aac,mp3,wav,m4a,amr' | ||
| 108 | + ]); | ||
| 109 | + | ||
| 110 | + if ($validator->fails()){ | ||
| 111 | + return Response::fail('',500,$validator->errors()); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + $hashName = $request->file('audio')->hashName(); | ||
| 115 | + | ||
| 116 | + $hash_hex = md5($hashName); | ||
| 117 | + | ||
| 118 | + // 16进制表示的字符串一共32字节,表示16个二进制字节。 | ||
| 119 | + // 前16个字符用来第一级求摸,后16个用做第二级 | ||
| 120 | + $hash_hex_l1 = substr($hash_hex, 0, 8); | ||
| 121 | + $hash_hex_l2 = substr($hash_hex, 8, 8); | ||
| 122 | + $dir_l1 = hexdec($hash_hex_l1) % 256; | ||
| 123 | + $dir_l2 = hexdec($hash_hex_l2) % 512; | ||
| 124 | + $dir = 'uploads/'. $dir_l1. '/' . $dir_l2; | ||
| 125 | + | ||
| 126 | + if( !Storage::disk('public')->exists($dir)) Storage::disk('public')->makeDirectory($dir); | ||
| 127 | + | ||
| 128 | + $file = $request->file('audio')->store($dir,'public'); | ||
| 129 | + | ||
| 130 | + return Response::success([ | ||
| 131 | + 'relative_path' => $file, | ||
| 132 | + 'absolute_path' => Storage::disk('public')->url($file), | ||
| 133 | + ]); | ||
| 134 | + } | ||
| 135 | + | ||
| 104 | 136 | ||
| 105 | public function protocol() | 137 | public function protocol() |
| 106 | { | 138 | { | ... | ... |
| ... | @@ -46,6 +46,13 @@ class Immerse extends Model | ... | @@ -46,6 +46,13 @@ class Immerse extends Model |
| 46 | return Storage::disk('public')->url($url); | 46 | return Storage::disk('public')->url($url); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | + public function getHuangliAttribute($huangli) | ||
| 50 | + { | ||
| 51 | + if ($huangli == null) return ''; | ||
| 52 | + | ||
| 53 | + return $huangli; | ||
| 54 | + } | ||
| 55 | + | ||
| 49 | public function poem() | 56 | public function poem() |
| 50 | { | 57 | { |
| 51 | return $this->hasOne(OnePoem::class,'id','poem_id'); | 58 | return $this->hasOne(OnePoem::class,'id','poem_id'); | ... | ... |
| ... | @@ -45,6 +45,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route | ... | @@ -45,6 +45,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route |
| 45 | /** 视频上传 */ | 45 | /** 视频上传 */ |
| 46 | $api->post('/upload/video', 'SettingController@uploadVideo'); | 46 | $api->post('/upload/video', 'SettingController@uploadVideo'); |
| 47 | 47 | ||
| 48 | + /** 音频上传 */ | ||
| 49 | + $api->post('/upload/audio', 'SettingController@uploadAudio'); | ||
| 50 | + | ||
| 48 | /** 会员页 */ | 51 | /** 会员页 */ |
| 49 | $api->get('/membership', 'MembershipController@index'); | 52 | $api->get('/membership', 'MembershipController@index'); |
| 50 | }); | 53 | }); |
| ... | @@ -73,6 +76,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc | ... | @@ -73,6 +76,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc |
| 73 | /** 作品详情 */ | 76 | /** 作品详情 */ |
| 74 | $api->delete('/my/videos/{id}', 'UserController@deleteVideo'); | 77 | $api->delete('/my/videos/{id}', 'UserController@deleteVideo'); |
| 75 | 78 | ||
| 79 | + /** 查询一言 */ | ||
| 80 | + $api->get('/poem/{id}', 'HomeController@poem'); | ||
| 81 | + | ||
| 76 | /** 临境 */ | 82 | /** 临境 */ |
| 77 | $api->apiResource('/immersive', 'ImmerseController'); | 83 | $api->apiResource('/immersive', 'ImmerseController'); |
| 78 | 84 | ... | ... |
-
Please register or login to post a comment