1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-20 19:07:03 +08:00
2021-10-27 18:16:40 +08:00

114 lines
2.4 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Http\Home\Controllers;
use App\Services\MyStorage as StorageService;
use App\Validators\Validator as AppValidator;
/**
* @RoutePrefix("/upload")
*/
class UploadController extends Controller
{
public function initialize()
{
$authUser = $this->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]);
}
/**
* @Post("/im/img", name="home.upload.im_img")
*/
public function uploadImImageAction()
{
}
/**
* @Post("/im/file", name="home.upload.im_file")
*/
public function uploadImFileAction()
{
}
}