refactor: 七牛云上传

This commit is contained in:
2025-07-24 18:03:41 +08:00
parent ea6c9ce9cd
commit 49e5a9b8c7
9 changed files with 519 additions and 174 deletions

View File

@@ -39,6 +39,60 @@ return [
// 可见性
'visibility' => 'public',
],
'public_qiniu' => [
// 磁盘类型
'type' => \filesystem\driver\Qiniu::class,
// bucker 名称
'bucket' => 'orico-official-website',
// 访问密钥
'access_key' => 'dOsTum4a5qvhPTBbZRPX0pIOU7PZWRX7htKjztms',
// 密钥
'secret_key' => 'KFxsGbnErkALFfeGdMa8QWTdodJbamMX0iznLe-q',
// 外部URL
'base_url' => '//szw73dlk3.hn-bkt.clouddn.com',
// 路径
'path_prefix' => '/storage',
// 文件名称回调,可为文件名添加特定标志,以便可以在后续识别
'filename_generator' => function (\think\file\UploadedFile $file, callable $context_generator = null): callable {
return function() use ($file, $context_generator) {
// 为文件名称添加配置名,以为后续可能根据文件名识别文件所属存储配置信息
$marker = '_' . base64_encode('public_qiniu');
$filename = $context_generator ? $context_generator($file) : null;
if ($filename == null) {
return date('Ymd') . '/' . md5(microtime(true) . $file->getPathname()) . $marker;
}
return $filename . $marker;
};
},
],
'video_qiniu' => [
// 磁盘类型
'type' => \filesystem\driver\Qiniu::class,
// bucker 名称
'bucket' => 'orico-official-website',
// 访问密钥
'access_key' => 'dOsTum4a5qvhPTBbZRPX0pIOU7PZWRX7htKjztms',
// 密钥
'secret_key' => 'KFxsGbnErkALFfeGdMa8QWTdodJbamMX0iznLe-q',
// 外部URL
'base_url' => '//szw73dlk3.hn-bkt.clouddn.com',
// 路径
'path_prefix' => '/storage/videos',
// 文件名称回调,可为文件名添加特定标志,以便可以在后续识别
'filename_generator' => function (\think\file\UploadedFile $file, callable $context_generator = null): callable {
return function() use ($file, $context_generator) {
// 为文件名称添加配置名,以为后续可能根据文件名识别文件所属存储配置信息
$marker = '_' . base64_encode('video_qiniu');
$filename = $context_generator ? $context_generator() : null;
if ($filename == null) {
return date('Ymd') . '/' . md5(microtime(true) . $file->getPathname()) . $marker;
}
return $filename . $marker;
};
},
]
// 更多的磁盘配置信息
],
];