1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 04:21:27 +08:00
xiaochong0302 befaccd085 Merge branch 'develop' of https://gitee.com/koogua/course-tencent-cloud
# Conflicts:
#	CHANGELOG.md
#	LICENSE
#	app/Http/Home/Controllers/ChapterController.php
#	app/Http/Home/Controllers/PublicController.php
#	app/Library/AppInfo.php
#	app/Models/Client.php
#	app/Services/Logic/Chapter/BasicInfo.php
2020-11-27 09:47:09 +08:00

113 lines
2.5 KiB
PHP

<?php
namespace App\Http\Admin\Controllers;
use App\Services\MyStorage as StorageService;
/**
* @RoutePrefix("/admin/upload")
*/
class UploadController extends Controller
{
/**
* @Post("/cover/img", name="admin.upload.cover_img")
*/
public function uploadCoverImageAction()
{
$service = new StorageService();
$file = $service->uploadCoverImage();
if (!$file) {
return $this->jsonError(['msg' => '上传文件失败']);
}
$data = [
'src' => $service->getImageUrl($file->path),
'title' => $file->name,
];
return $this->jsonSuccess(['data' => $data]);
}
/**
* @Post("/avatar/img", name="admin.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="admin.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]);
}
/**
* @Get("/sign", name="admin.upload.sign")
*/
public function signatureAction()
{
$service = new StorageService();
$token = $service->getFederationToken();
$data = [
'credentials' => $token->getCredentials(),
'expiredTime' => $token->getExpiredTime(),
'startTime' => time(),
];
return $this->jsonSuccess($data);
}
/**
* @Get("/sign", name="admin.upload.sign")
*/
public function signatureAction()
{
$service = new StorageService();
$token = $service->getFederationToken();
$data = [
'credentials' => $token->getCredentials(),
'expiredTime' => $token->getExpiredTime(),
'startTime' => time(),
];
return $this->jsonSuccess($data);
}
}