Commit 00042cf1 authored by 刘小敏's avatar 刘小敏

feat(hwobs): 支持 V4 签名算法并添加调试日志

parent a7408baf
......@@ -252,8 +252,8 @@ if (typeof Config.upload.storage !== 'undefined' && Config.upload.storage === 'h
this.on("sending", function (file, xhr, formData) {
var that = this;
var _send = xhr.send;
//仅允许部分字段
var allowFields = ['partNumber', 'uploadId', 'key', 'AccessKeyId', 'policy', 'signature', 'file'];
//仅允许部分字段(V4签名需要额外字段)
var allowFields = ['partNumber', 'uploadId', 'key', 'AccessKeyId', 'policy', 'signature', 'X-Amz-Algorithm', 'X-Amz-Credential', 'X-Amz-Date', 'acl', 'file'];
formData.forEach(function (value, key) {
if (allowFields.indexOf(key) < 0) {
formData.delete(key);
......
......@@ -61,7 +61,10 @@ class Index extends Controller
$obs = new ObsClient([
'key' => $config['accessKey'],
'secret' => $config['secretKey'],
'endpoint' => $config['endpoint']
'endpoint' => $config['endpoint'],
'region' => 'cn-east-3',
'region' => 'cn-east-3', // ← 新增:V4 签名必需
'signature'=> 'v4' // ← 新增:使用 V4 签名算法
]);
if ($chunk) {
$partSize = $this->request->post("chunksize");
......@@ -92,10 +95,33 @@ class Index extends Controller
$params['AccessKeyId'] = $config['accessKey'];
$params['policy'] = $signature['Policy'];
$params['signature'] = $signature['Signature'];
// V4 签名需要额外传递以下字段给前端
if (isset($signature['Algorithm'])) {
$params['X-Amz-Algorithm'] = $signature['Algorithm'];
$params['X-Amz-Credential'] = $signature['Credential'];
$params['X-Amz-Date'] = $signature['Date'];
}
$params['acl'] = 'public-read'; // 传递 ACL 参数给前端
}
// DEBUG: 写日志排查签名内容
file_put_contents(ROOT_PATH . 'addons' . DS . 'hwobs' . DS . 'debug.log',
date('Y-m-d H:i:s') . "\n" .
"Method: " . (isset($signature['Algorithm']) ? 'V4' : 'V2') . "\n" .
"Algorithm: " . (isset($signature['Algorithm']) ? $signature['Algorithm'] : 'N/A') . "\n" .
"Credential: " . (isset($signature['Credential']) ? $signature['Credential'] : 'N/A') . "\n" .
"Date: " . (isset($signature['Date']) ? $signature['Date'] : 'N/A') . "\n" .
"Policy base64: " . substr($signature['Policy'], 0, 50) . "...\n" .
"Signature: " . substr($signature['Signature'], 0, 20) . "...\n" .
"---\n", FILE_APPEND);
$params['headers'] = $headers;
$params['date'] = $date;
// DEBUG: 记录返回给前端的 params 里 V4 字段情况
file_put_contents(ROOT_PATH . 'addons' . DS . 'hwobs' . DS . 'debug.log',
"params keys: " . implode(', ', array_keys($params)) . "\n" .
"has X-Amz-Algorithm: " . (isset($params['X-Amz-Algorithm']) ? 'YES' : 'NO') . "\n" .
"has X-Amz-Credential: " . (isset($params['X-Amz-Credential']) ? 'YES' : 'NO') . "\n" .
"has X-Amz-Date: " . (isset($params['X-Amz-Date']) ? 'YES' : 'NO') . "\n" .
"=== END DEBUG ===\n\n", FILE_APPEND);
$this->success('', null, $params);
}
......@@ -118,7 +144,9 @@ class Index extends Controller
$obs = new ObsClient([
'key' => $config['accessKey'],
'secret' => $config['secretKey'],
'endpoint' => $config['endpoint']
'endpoint' => $config['endpoint'],
'region' => 'cn-east-3',
'signature'=> 'v4'
]);
//检测删除文件或附件
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment