Introducing new features.

This commit is contained in:
WispX 2021-12-13 22:46:05 +08:00
parent edc61f42d9
commit e2e0a2ce9a
10 changed files with 86 additions and 21 deletions

View File

@ -2,12 +2,35 @@
namespace App\Http\Controllers;
use App\Service\UploadService;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function upload(Request $request, UploadService $service): array
{
// TODO 如果关闭了游客上传返回404
// TODO 检测IP是否超出上传限制
// TODO 获取用户组
// TODO 判断储存容量
// TODO 获取策略列表,根据用户所选的策略上传
// TODO 检测是否存在该图片,有则直接返回
// TODO 图片保存至默认相册(若有)
$data = [
'url' => 'https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png',
'html' => '<img src="https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png" alt="e212bc43771ad6d391952732a1713e31.png" title="e212bc43771ad6d391952732a1713e31.png" />',
'bbcode' => '[img]https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png[/img]',
'markdown' => '![e212bc43771ad6d391952732a1713e31.png](https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png)',
'markdown_with_link' => '[![e212bc43771ad6d391952732a1713e31.png](https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png)](https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png)',
];
$status = true;
$message = '上传失败,储存空间不足';
return compact('status', 'data', 'message');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
//
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\View\View;
class UserController extends Controller
{
public function dashboard(): View
{
return view('dashboard');
}
}

View File

@ -33,6 +33,22 @@ class Group extends Model
'configs' => 'collection',
];
protected static function booted()
{
static::creating(function (self $group) {
$group->configs = collect([
'upload_max_size' => 5120, // 最大上传大小
'upload_single_num' => 3, // 单次同时上传数量
'is_need_review' => false, // 上传是否需要审查
'limit_per_day' => 0, // 每天可以上传数量0 为不限制
'upload_allowed_types' => ['jpg', 'jpeg', 'gif', 'png', 'ico'], // 允许上传的文件类型
'path_naming_rule' => '{Y}/{m}/{d}', // 路径命名规则
'file_naming_rule' => '{uniqid}', // 文件命名规则
'user_initial_capacity' => 1048576, // 用户初始容量
])->merge($group->configs ?: []);
});
}
public function users(): HasMany
{
return $this->hasMany(User::class, 'user_id', 'id');

View File

@ -80,7 +80,7 @@ class User extends Authenticatable
{
static::creating(function (self $user) {
$user->configs = collect([
'upload_default_album' => 0, // 默认上传文件夹
'upload_default_album' => 0, // 默认上传相册
'upload_default_strategy' => 0, // 默认上传策略
'is_upload_show_preview', // 是否显示上传预览
'is_upload_auto_clear_preview', // 上传成功是否自动删除预览图

View File

@ -0,0 +1,8 @@
<?php
namespace App\Service;
class UploadService
{
}

View File

@ -1,3 +1,3 @@
<x-app-layout>
<x-upload/>
仪表盘
</x-app-layout>

View File

@ -18,7 +18,7 @@
</div>
<div class="flex flex-col space-y-2 mb-5">
<p class="text-gray-400 text-sm mx-4">我的</p>
<x-nav-link :active="request()->routeIs('upload')">
<x-nav-link :href="route('upload')" :active="request()->routeIs('upload')">
<x-slot name="icon"><i class="fas fa-cloud-upload-alt text-blue-500"></i></x-slot>
<x-slot name="name">上传图片</x-slot>
</x-nav-link>

View File

@ -0,0 +1,3 @@
<x-app-layout>
<x-upload/>
</x-app-layout>

View File

@ -13,25 +13,14 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::get('/', function () {
return view('welcome');
})->name('/');
use App\Http\Controllers\Controller;
use App\Http\Controllers\User\UserController;
Route::post('/upload', function () {
$data = [
'url' => 'https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png',
'html' => '&lt;img src="https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png" alt="e212bc43771ad6d391952732a1713e31.png" title="e212bc43771ad6d391952732a1713e31.png" /&gt;',
'bbcode' => '[img]https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png[/img]',
'markdown' => '![e212bc43771ad6d391952732a1713e31.png](https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png)',
'markdown_with_link' => '[![e212bc43771ad6d391952732a1713e31.png](https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png)](https://pic.iqy.ink/2021/12/12/e8cfd03eb787f.png)',
];
$status = true;
$message = '上传失败,储存空间不足';
return compact('status', 'data', 'message');
Route::get('/', fn () => view('welcome'))->name('/');
Route::post('/upload', [Controller::class, 'upload']);
Route::group(['middleware' => ['auth'],], function () {
Route::get('/dashboard', [UserController::class, 'dashboard'])->name('dashboard');
Route::get('/upload', fn () => view('upload'))->name('upload');
});
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth'])->name('dashboard');
require __DIR__.'/auth.php';