request = $request; $this->fileService = $fileService; } /** * 文件列表 * * @return void */ public function index() { $conditions = []; $conditions['limit'] = $this->request->get('limit', 20); $files = $this->fileService->index($conditions); return res($files, '文件列表', 201); } /** * 删除. * * @return \Illuminate\Http\Response */ public function destroy() { $ids = $this->request->ids(); $this->fileService->destroy($ids); return res(true, '删除成功'); } /** * 上传文件. * * @return \Illuminate\Http\Response */ public function upload() { $rule = []; foreach (FileService::$mimeTypes as $type => $mimeType) { $rule[$type] = 'mimetypes:'.implode(',', $mimeType); } Validator::validate($this->request->all(), $rule); foreach (array_keys(FileService::$mimeTypes) as $type) { if ($this->request->has($type)) { $file = $this->request->file($type); break; } } if (!$file) { throw new InvalidArgumentException('请上传正确的文件'); } $input = $this->request->only(['height', 'width', 'duration', 'type', 'typeid', 'cover']); $fileModel = $this->fileService->upload($file, $input); return res($fileModel, '上传成功'); } }