提交 18bcd93d 编写于 作者: H HFO4

Feat: Use official s3 SDK / support minio

上级 76ea4989
......@@ -95,7 +95,8 @@ class File extends Controller{
}
public function gerSource(){
$reqPath = $_POST["path"];
$reqData = json_decode(file_get_contents("php://input"),true);
$reqPath = $reqData['path'];
$fileObj = new FileManage($reqPath,$this->userObj->uid);
$FileHandler = $fileObj->Source();
}
......
......@@ -120,6 +120,7 @@ class CallbackHandler extends Model{
if(empty($CallbackSqlData)){
$this->setError("Undelegated Request",false,true);
}
Db::name('callback')->where('callback_key',$key)->delete();
$this->policyData = Db::name('policy')->where('id',$CallbackSqlData['pid'])->find();
$this->userData = Db::name('users')->where('id',$CallbackSqlData['uid'])->find();
$paths = explode("/",$this->CallbackData["key"]);
......@@ -135,7 +136,7 @@ class CallbackHandler extends Model{
if(!$jsonData["fsize"]){
$this->setError("File not exist",false,true);
}
$jsonData["fsize"] = $jsonData["fsize"]["size"];
$jsonData["fsize"] = $jsonData["fsize"];
$picInfo = "";
$addAction = FileManage::addFile($jsonData,$this->policyData,$this->userData["id"],"");
if(!$addAction[0]){
......@@ -147,14 +148,25 @@ class CallbackHandler extends Model{
}
private function getS3FileInfo(){
$s3 = new \S3\S3($this->policyData["ak"], $this->policyData["sk"],false,$this->policyData["op_pwd"]);
$s3->setSignatureVersion('v4');
$s3 = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $this->policyData["op_name"],
'endpoint' => $this->policyData["op_pwd"],
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $this->policyData["ak"],
'secret' => $this->policyData["sk"],
],
]);
try {
$returnVal = $s3->getObjectInfo($this->policyData["bucketname"],$this->CallbackData["key"]);
$returnVal = $s3->headObject([
'Bucket'=>$this->policyData["bucketname"],
'Key'=>$this->CallbackData["key"]
]);
} catch (Exception $e) {
return false;
}
return $returnVal;
return $returnVal["ContentLength"];
}
public function setSuccess($fname){
......
......@@ -4,9 +4,6 @@ namespace app\index\model;
use think\Model;
use think\Db;
use Upyun\Upyun;
use Upyun\Config;
use \app\index\model\Option;
/**
......@@ -42,8 +39,25 @@ class S3Adapter extends Model{
if($base===true || $base ===false){
$base = null;
}
$s3 = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $this->policyModel["op_name"],
'endpoint' => $this->policyModel["op_pwd"],
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $this->policyModel["ak"],
'secret' => $this->policyModel["sk"],
],
]);
$cmd = $s3->getCommand('GetObject', [
'Bucket' => $this->policyModel["bucketname"],
'Key' => $this->fileModel["pre_name"],
]);
$timeOut = Option::getValue("timeout");
return [1,\S3\S3::aws_s3_link($this->policyModel["ak"], $this->policyModel["sk"],$this->policyModel["bucketname"],"/".$this->fileModel["pre_name"],3600,$this->policyModel["op_name"])];
$req = $s3->createPresignedRequest($cmd, '+'.($timeOut/60).' minutes');
$url = (string)$req->getUri();
return [1,$url];
}
/**
......@@ -53,9 +67,21 @@ class S3Adapter extends Model{
* @return void
*/
public function saveContent($content){
$s3 = new \S3\S3($this->policyModel["ak"], $this->policyModel["sk"],false,$this->policyModel["op_pwd"]);
$s3->setSignatureVersion('v4');
$s3->putObjectString($content, $this->policyModel["bucketname"], $this->fileModel["pre_name"]);
$s3 = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $this->policyModel["op_name"],
'endpoint' => $this->policyModel["op_pwd"],
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $this->policyModel["ak"],
'secret' => $this->policyModel["sk"],
],
]);
$s3->putObject([
'Bucket' => $this->policyModel["bucketname"],
'Key' => $this->fileModel["pre_name"],
'Body' => $content,
]);
}
/**
......@@ -78,7 +104,26 @@ class S3Adapter extends Model{
*/
public function Download(){
$timeOut = Option::getValue("timeout");
return [1,\S3\S3::aws_s3_link($this->policyModel["ak"], $this->policyModel["sk"],$this->policyModel["bucketname"],"/".$this->fileModel["pre_name"],3600,$this->policyModel["op_name"],array(),false)];
$s3 = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $this->policyModel["op_name"],
'endpoint' => $this->policyModel["op_pwd"],
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $this->policyModel["ak"],
'secret' => $this->policyModel["sk"],
],
]);
$cmd = $s3->getCommand('GetObject', [
'Bucket' => $this->policyModel["bucketname"],
'Key' => $this->fileModel["pre_name"],
'ResponseContentDisposition' => 'attachment; filename='.$this->fileModel["orign_name"],
]);
$timeOut = Option::getValue("timeout");
$req = $s3->createPresignedRequest($cmd, '+'.($timeOut/60).' minutes');
$url = (string)$req->getUri();
return [1,$url];
}
/**
......@@ -89,9 +134,21 @@ class S3Adapter extends Model{
* @return boolean
*/
static function deleteS3File($fname,$policy){
$s3 = new \S3\S3($policy["ak"], $policy["sk"],false,$policy["op_pwd"]);
$s3->setSignatureVersion('v4');
return $s3->deleteObject($policy["bucketname"],$fname);
$s3 = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $policy["op_name"],
'endpoint' => $policy["op_pwd"],
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $policy["ak"],
'secret' => $policy["sk"],
],
]);
$result = $s3->deleteObject([
'Bucket' => $policy["bucketname"],
'Key' => $fname,
]);
return $result["DeleteMarker"];
}
/**
......
......@@ -90,12 +90,13 @@
<script src="http://127.0.0.1:3000/static/js/2.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/3.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/4.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/6.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/5.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/7.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/9.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/1.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/8.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/12.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/10.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/1.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/9.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/13.chunk.js"></script>
<script src="http://127.0.0.1:3000/static/js/index.chunk.js"></script>
</html>
\ No newline at end of file
......@@ -90,12 +90,16 @@
-->
</body>
<script src="http://192.168.123.19:3000/static/js/runtime~folderShare.bundle.js"></script>
<script src="http://192.168.123.19:3000/static/js/14.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/15.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/16.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/17.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/12.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/18.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/0.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/2.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/3.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/4.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/5.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/7.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/8.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/10.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/1.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/9.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/13.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/folderShare.chunk.js"></script>
......
......@@ -72,9 +72,7 @@
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/mdeditor/editormd.min.js"></script>
<script src="http://192.168.123.19:3000/static/js/runtime~markdown.bundle.js"></script>
<script src="http://192.168.123.19:3000/static/js/7.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/0.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/1.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/9.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/8.chunk.js"></script>
<script src="http://192.168.123.19:3000/static/js/markdown.chunk.js"></script>
</html>
......@@ -32,7 +32,8 @@
"topthink/think-captcha":"1.*",
"aliyuncs/oss-sdk-php": "~2.0",
"sabre/dav":"~3.2.0",
"upyun/sdk": "^3.3"
"upyun/sdk": "^3.3",
"aws/aws-sdk-php": "^3.90"
},
"autoload": {
"psr-0": {
......
此差异已折叠。
此差异已折叠。
......@@ -711,22 +711,21 @@ function QiniuJsSDK() {
} else if (op.uptoken_url) {
logger.debug("get uptoken from: ", that.uptoken_url);
// TODO: use mOxie
// var ajax = that.createAjax();
// ajax.open('GET', that.uptoken_url, false);
// ajax.setRequestHeader("If-Modified-Since", "0");
// ajax.send();
var ajax = new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(xhr);
};
xhr.onerror = reject;
xhr.open('GET', that.uptoken_url+"?path="+encodeURIComponent(window.pathCache[file.id]));
xhr.send();
});
ajax.then(function(result){
var res = that.parseJSON(result.responseText);
var ajax = that.createAjax();
ajax.open('GET', that.uptoken_url+"?path="+encodeURIComponent(window.pathCache[file.id]),false);
ajax.setRequestHeader("If-Modified-Since", "0");
ajax.send();
// var ajax = new Promise(function(resolve, reject) {
// var xhr = new XMLHttpRequest();
// xhr.onload = function() {
// resolve(xhr);
// };
// xhr.onerror = reject;
// xhr.open('GET', that.uptoken_url+"?path="+encodeURIComponent(window.pathCache[file.id]));
// xhr.send();
// });
if (ajax.status === 200) {
var res = that.parseJSON(ajax.responseText);
that.token = res.uptoken;
if (uploadConfig.saveType == "oss"){
var putPolicy = that.token;
......@@ -771,7 +770,7 @@ function QiniuJsSDK() {
};
logger.debug("get token info: ", that.tokenInfo);
}
})
}
// ajax.onload = function (e){
// if (ajax.status === 200) {
......@@ -1313,11 +1312,11 @@ function QiniuJsSDK() {
}
}else if(uploadConfig.saveType == "s3" && err.status!=401){
var str = err.response
var a = $.parseXML(str);
$(a).find('Error').each(function () {
errTip = $(this).children('Message').text();
var errorText = "Error";
});
parser = new DOMParser();
xmlDoc = parser.parseFromString(str, "text/xml");
errTip = xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue;
var errorText = "Error";
}else{
var errorObj = that.parseJSON(err.response);
var errorText = errorObj.error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册