perf:云存储初始化时机优化、上传扩展优化

This commit is contained in:
妙码生花 2023-07-12 20:26:27 +08:00
parent 13ab01422e
commit 36d332baa0
4 changed files with 13 additions and 6 deletions

View File

@ -1,10 +1,12 @@
<?php
// 应用公共文件
use think\App;
use ba\Filesystem;
use think\Response;
use think\facade\Db;
use think\facade\Lang;
use think\facade\Event;
use think\facade\Config;
use app\admin\model\Config as configModel;
use think\exception\HttpResponseException;
@ -94,6 +96,9 @@ if (!function_exists('full_url')) {
*/
function full_url(string $relativeUrl = '', bool $domain = true, string $default = ''): string
{
// 存储/上传资料配置
Event::trigger('uploadConfigInit', App::getInstance());
$cdnUrl = Config::get('buildadmin.cdn_url');
if (!$cdnUrl) $cdnUrl = request()->upload['cdn'] ?? request()->domain();
if ($domain === true) {
@ -332,6 +337,9 @@ if (!function_exists('get_upload_config')) {
*/
function get_upload_config(): array
{
// 存储/上传资料配置
Event::trigger('uploadConfigInit', App::getInstance());
$uploadConfig = Config::get('upload');
$uploadConfig['maxsize'] = Filesystem::fileUnitToByte($uploadConfig['maxsize']);

View File

@ -6,7 +6,6 @@ use Throwable;
use think\App;
use think\Response;
use app\BaseController;
use think\facade\Event;
use think\facade\Config;
use think\exception\HttpResponseException;
@ -44,8 +43,6 @@ class Api extends BaseController
ip_check();
// 时区设定
set_timezone();
// 存储/上传资料配置
Event::trigger('uploadConfigInit', $this->app);
}
parent::initialize();

View File

@ -62,7 +62,7 @@ export function fileUpload(fd: FormData, params: anyObj = {}, forceLocal = false
}
if (!forceLocal && uploadExpandState() == 'enable') {
return uploadExpand(fd, params)
return uploadExpand(fd, params, config)
}
return createAxios({

View File

@ -1,9 +1,11 @@
import { AxiosRequestConfig } from 'axios'
export const state: () => 'disable' | 'enable' = () => 'disable'
export function fileUpload(fd: FormData, params: anyObj = {}): ApiPromise {
export function fileUpload(fd: FormData, params: anyObj = {}, config: AxiosRequestConfig = {}): ApiPromise {
// 上传扩展,定义此函数,并将上方的 state 设定为 enable系统可自动使用此函数进行上传
return new Promise((resolve, reject) => {
console.log(fd, params)
console.log(fd, params, config)
reject('未定义')
})
}