diff --git a/application/index/controller/File.php b/application/index/controller/File.php
index 9b663d99..1c751998 100644
--- a/application/index/controller/File.php
+++ b/application/index/controller/File.php
@@ -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();
}
diff --git a/application/index/model/CallbackHandler.php b/application/index/model/CallbackHandler.php
index ef658ab2..1b982e85 100644
--- a/application/index/model/CallbackHandler.php
+++ b/application/index/model/CallbackHandler.php
@@ -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){
diff --git a/application/index/model/S3Adapter.php b/application/index/model/S3Adapter.php
index b9c7a3c0..184c43da 100644
--- a/application/index/model/S3Adapter.php
+++ b/application/index/model/S3Adapter.php
@@ -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"];
}
/**
diff --git a/application/index/view/home/home.html b/application/index/view/home/home.html
index 3252f3f2..a215065e 100644
--- a/application/index/view/home/home.html
+++ b/application/index/view/home/home.html
@@ -90,12 +90,13 @@
-
+
-
-
-
+
+
+
+