getAuthUser(); $validator = new AppValidator(); $validator->checkAuthUser($authUser->id); } /** * @Post("/avatar/img", name="home.upload.avatar_img") */ public function uploadAvatarImageAction() { $service = new StorageService(); $file = $service->uploadAvatarImage(); if (!$file) { return $this->jsonError(['msg' => '上传文件失败']); } $data = [ 'src' => $service->getImageUrl($file->path), 'title' => $file->name, ]; return $this->jsonSuccess(['data' => $data]); } /** * @Post("/content/img", name="home.upload.content_img") */ public function uploadContentImageAction() { $service = new StorageService(); $file = $service->uploadContentImage(); if (!$file) { return $this->jsonError(['msg' => '上传文件失败']); } $data = [ 'src' => $service->getImageUrl($file->path), 'title' => $file->name, ]; return $this->jsonSuccess(['data' => $data]); } /** * @Post("/remote/img", name="home.upload.remote_img") */ public function uploadRemoteImageAction() { $originalUrl = $this->request->getPost('url', ['trim', 'string']); $service = new StorageService(); $file = $service->uploadRemoteImage($originalUrl); $newUrl = $originalUrl; if ($file) { $newUrl = $service->getImageUrl($file->path); } /** * 编辑器要求返回的数据结构 */ $data = [ 'url' => $newUrl, 'originalURL' => $originalUrl, ]; return $this->jsonSuccess(['data' => $data]); } }