Merge branch 'main' of https://gitcode.gynhc.com/aAHai/xiaozhongchuf
这个提交包含在:
@@ -49,6 +49,7 @@ class File extends Backend
|
||||
foreach ($result['list'] as &$v) {
|
||||
$v['checked'] = false;
|
||||
$v['showTools'] = false;
|
||||
$v['fullurl'] = cdnurl($v['url'], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@
|
||||
</div>
|
||||
<div @click="handleSelectFile(index)" v-for="(item, index) of fileList" :key="item.id" class="file-list" @mouseenter="enterFileItem($event, index)" @mouseleave="leaveFileItem($event, index)">
|
||||
<div class="file-img-item">
|
||||
<img class="file-image" :src="item.mimetype.indexOf('image') >= 0 ? item.url : `/s.php/ajax/icon?suffix=${item.imagetype}`" alt="">
|
||||
<img class="file-image" :src="item.mimetype.indexOf('image') >= 0 ? (item.fullurl || item.url) : `/s.php/ajax/icon?suffix=${item.imagetype}`" alt="">
|
||||
</div>
|
||||
<div v-if="item.checked || item.showTools" class="tools">
|
||||
<div class="top">
|
||||
@@ -315,7 +315,7 @@
|
||||
<img src="/assets/img/check-check.png" alt="">
|
||||
</div>
|
||||
{/if}
|
||||
<div @click.stop="handleOpenFile(item.url)" style="margin: 0 12px;" class="v-icon">
|
||||
<div @click.stop="handleOpenFile(item.fullurl || item.url)" style="margin: 0 12px;" class="v-icon">
|
||||
<img src="/assets/img/see-see.png?id=1" alt="">
|
||||
</div>
|
||||
<div @click.stop="dell(item.id)" class="v-icon">
|
||||
|
||||
@@ -519,7 +519,16 @@ if (!function_exists('cdnurl')) {
|
||||
{
|
||||
$regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
|
||||
$cdnurl = \think\Config::get('upload.cdnurl');
|
||||
$url = is_array($url) ? $url[0] : $url;
|
||||
if (empty($cdnurl) && function_exists('get_addon_config')) {
|
||||
$cosConfig = get_addon_config('cos');
|
||||
if (!empty($cosConfig['cdnurl'])) {
|
||||
$cdnurl = rtrim($cosConfig['cdnurl'], '/');
|
||||
}
|
||||
}
|
||||
$url = is_array($url) ? $url[0] : $url;
|
||||
if (empty($url)) {
|
||||
return '';
|
||||
}
|
||||
if (is_bool($domain) || stripos($cdnurl, '/') === 0) {
|
||||
$url = preg_match($regex, $url) || ($cdnurl && stripos($url, $cdnurl) === 0) ? $url : $cdnurl . $url;
|
||||
}
|
||||
@@ -527,6 +536,15 @@ if (!function_exists('cdnurl')) {
|
||||
$domain = is_bool($domain) ? request()->domain() : $domain;
|
||||
$url = $domain . $url;
|
||||
}
|
||||
|
||||
// 采用COS图片处理参数将图片最大宽度限制在1000px以内并转为webp格式
|
||||
if (!empty($cdnurl) && stripos($url, $cdnurl) !== false) {
|
||||
if (preg_match('/\.(jpg|jpeg|png|bmp|webp)(\?.*)?$/i', $url) && stripos($url, 'imageMogr2') === false) {
|
||||
$separator = (strpos($url, '?') !== false) ? '&' : '?';
|
||||
$url .= $separator . 'imageMogr2/thumbnail/1000x%3E/format/webp';
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,10 +446,69 @@ class Upload
|
||||
$attachment->data(array_filter($params));
|
||||
$attachment->save();
|
||||
|
||||
$this->syncToCos($attachment);
|
||||
|
||||
\think\Hook::listen("upload_after", $attachment);
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步文件到腾讯云COS
|
||||
* @param Attachment $attachment
|
||||
*/
|
||||
protected function syncToCos($attachment)
|
||||
{
|
||||
try {
|
||||
$addonInfo = get_addon_info('cos');
|
||||
if (!$addonInfo || empty($addonInfo['state'])) {
|
||||
return;
|
||||
}
|
||||
$cosConfig = get_addon_config('cos');
|
||||
if (empty($cosConfig) || empty($cosConfig['secretId']) || empty($cosConfig['secretKey']) || empty($cosConfig['bucket'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!class_exists('\Qcloud\Cos\Client')) {
|
||||
$cosAddonPath = (defined('ADDON_PATH') ? ADDON_PATH : (ROOT_PATH . 'addons' . DS)) . 'cos' . DIRECTORY_SEPARATOR;
|
||||
\think\Loader::addNamespace('Qcloud\Cos', $cosAddonPath . 'library' . DIRECTORY_SEPARATOR . 'Qcloud' . DIRECTORY_SEPARATOR . 'Cos' . DIRECTORY_SEPARATOR);
|
||||
\think\Loader::addNamespace('GuzzleHttp\Command', $cosAddonPath . 'library' . DIRECTORY_SEPARATOR . 'Guzzle' . DIRECTORY_SEPARATOR . 'command' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR);
|
||||
\think\Loader::addNamespace('GuzzleHttp\Command\Guzzle', $cosAddonPath . 'library' . DIRECTORY_SEPARATOR . 'Guzzle' . DIRECTORY_SEPARATOR . 'guzzle-services' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR);
|
||||
\think\Loader::addNamespace('GuzzleHttp\UriTemplate', $cosAddonPath . 'library' . DIRECTORY_SEPARATOR . 'Guzzle' . DIRECTORY_SEPARATOR . 'uri-template' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
$realPath = ROOT_PATH . 'public' . str_replace('/', DS, $attachment->url);
|
||||
if (!file_exists($realPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client = new \Qcloud\Cos\Client([
|
||||
'region' => $cosConfig['region'],
|
||||
'schema' => 'https',
|
||||
'credentials' => [
|
||||
'secretId' => $cosConfig['secretId'],
|
||||
'secretKey' => $cosConfig['secretKey'],
|
||||
]
|
||||
]);
|
||||
|
||||
$key = ltrim($attachment->url, '/');
|
||||
$fileHandle = fopen($realPath, 'rb');
|
||||
$client->upload($cosConfig['bucket'], $key, $fileHandle);
|
||||
if (is_resource($fileHandle)) {
|
||||
fclose($fileHandle);
|
||||
}
|
||||
|
||||
$attachment->storage = 'cos';
|
||||
$attachment->save();
|
||||
|
||||
// 如果设置了不保留本地备份,则删除本地文件
|
||||
if (isset($cosConfig['serverbackup']) && $cosConfig['serverbackup'] == 0) {
|
||||
@unlink($realPath);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\think\Log::write('COS Upload Error: ' . $e->getMessage(), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置错误信息
|
||||
* @param $msg
|
||||
|
||||
@@ -12,6 +12,19 @@ return [
|
||||
'sms_check' => [
|
||||
'alisms',
|
||||
],
|
||||
'app_init' => [
|
||||
'cos',
|
||||
'shopro',
|
||||
],
|
||||
'module_init' => [
|
||||
'cos',
|
||||
],
|
||||
'upload_config_init' => [
|
||||
'cos',
|
||||
],
|
||||
'upload_delete' => [
|
||||
'cos',
|
||||
],
|
||||
'epay_config_init' => [
|
||||
'epay',
|
||||
],
|
||||
@@ -27,9 +40,6 @@ return [
|
||||
'upgrade' => [
|
||||
'shopro',
|
||||
],
|
||||
'app_init' => [
|
||||
'shopro',
|
||||
],
|
||||
'config_init' => [
|
||||
'summernote',
|
||||
],
|
||||
|
||||
在新工单中引用
屏蔽一个用户