diff --git a/CloudreveInstaller/Installer.php b/CloudreveInstaller/Installer.php
index 4c65db35..d17573ba 100644
--- a/CloudreveInstaller/Installer.php
+++ b/CloudreveInstaller/Installer.php
@@ -16,7 +16,7 @@ class Installer{
/ /___| | (_) | |_| | (_| | | | __/\ V / __/
\____/|_|\___/ \__,_|\__,_|_| \___| \_/ \___|
- Ver $version
+ Ver $version
================================================
";
$ioContext->write($welcomMsg);
@@ -98,11 +98,11 @@ class Installer{
return self::getSqlInformation($event);
}
return [
- "hostname" => $hostname,
- "database" => $database,
- "username" => $username,
- "password" => $password,
- "hostport" => $hostport,
+ "hostname" => $hostname,
+ "database" => $database,
+ "username" => $username,
+ "password" => $password,
+ "hostport" => $hostport,
];
}
diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php
index f970d323..41639d6e 100644
--- a/application/index/model/FileManage.php
+++ b/application/index/model/FileManage.php
@@ -61,6 +61,9 @@ class FileManage extends Model{
case 'remote':
$this->adapter = new \app\index\model\RemoteAdapter($this->fileData,$this->policyData,$this->userData);
break;
+ case 'onedrive':
+ $this->adapter = new \app\index\model\OnedriveAdapter($this->fileData,$this->policyData,$this->userData);
+ break;
default:
# code...
break;
@@ -90,6 +93,11 @@ class FileManage extends Model{
if($this->fileData["size"]>$sizeLimit){
die('{ "result": { "success": false, "error": "您当前用户组最大可编辑'.$sizeLimit.'字节的文件"} }');
}else{
+ try{
+ $fileContent = $this->adapter->getFileContent();
+ }catch(\Exception $e){
+ die('{ "result": { "success": false, "error": "'.$e->getMessage().'"} }');
+ }
$fileContent = $this->adapter->getFileContent();
$result["result"] = $fileContent;
if(empty(json_encode($result))){
@@ -432,6 +440,9 @@ class FileManage extends Model{
}else if(in_array($key,$uniquePolicy["remoteList"])){
RemoteAdapter::DeleteFile($value,$uniquePolicy["remotePolicyData"][$key][0]);
self::deleteFileRecord(array_column($value, 'id'),array_sum(array_column($value, 'size')),$value[0]["upload_user"]);
+ }else if(in_array($key,$uniquePolicy["onedriveList"])){
+ OnedriveAdapter::DeleteFile($value,$uniquePolicy["onedrivePolicyData"][$key][0]);
+ self::deleteFileRecord(array_column($value, 'id'),array_sum(array_column($value, 'size')),$value[0]["upload_user"]);
}
}
return ["result"=>["success"=>true,"error"=>null]];
@@ -715,6 +726,8 @@ class FileManage extends Model{
$s3PolicyData = [];
$remoteList = [];
$remotePolicyData = [];
+ $onedriveList = [];
+ $onedrivePolicyData = [];
foreach ($data as $key => $value) {
if(!in_array($value['policy_id'],$tempList)){
array_push($tempList,$value['policy_id']);
@@ -762,6 +775,13 @@ class FileManage extends Model{
}
array_push($remotePolicyData[$value['policy_id']],$policyTempData);
break;
+ case 'onedrive':
+ array_push($onedriveList,$value['policy_id']);
+ if(empty($onedrivePolicyData[$value['policy_id']])){
+ $onedrivePolicyData[$value['policy_id']] = [];
+ }
+ array_push($onedrivePolicyData[$value['policy_id']],$policyTempData);
+ break;
default:
# code...
break;
@@ -782,6 +802,8 @@ class FileManage extends Model{
's3PolicyData' => $s3PolicyData,
'remoteList' => $remoteList,
'remotePolicyData' => $remotePolicyData,
+ 'onedriveList' => $onedriveList,
+ 'onedrivePolicyData' => $onedrivePolicyData,
);
return $returenValue;
}
diff --git a/application/index/model/OnedriveAdapter.php b/application/index/model/OnedriveAdapter.php
new file mode 100644
index 00000000..5091485d
--- /dev/null
+++ b/application/index/model/OnedriveAdapter.php
@@ -0,0 +1,140 @@
+fileModel = $file;
+ $this->policyModel = $policy;
+ $this->userModel = $user;
+ $this->clinet = new Client([
+ 'stream_back_end' => \Krizalys\Onedrive\StreamBackEnd::TEMP,
+ 'client_id' => $this->policyModel["bucketname"],
+
+ // Restore the previous state while instantiating this client to proceed in
+ // obtaining an access token.
+ 'state' => json_decode($this->policyModel["sk"]),
+ ]);
+ }
+
+ /**
+ * 获取文本文件内容
+ *
+ * @return string 文件内容
+ */
+ public function getFileContent(){
+ $file = new \Krizalys\Onedrive\File($this->clinet,"/me/drive/root:/".$this->fileModel["pre_name"].":");
+ return $file->fetchContent();
+ }
+
+ /**
+ * 签名预览URL
+ *
+ * @return void
+ */
+ public function Preview($base=null,$name=null){
+ $preview = json_decode(json_encode($this->clinet->apiGet("/me/drive/root:/".rawurlencode($this->fileModel["pre_name"]).":")),true);
+ return [1,$preview["@microsoft.graph.downloadUrl"]];
+ }
+
+ /**
+ * 保存文件内容
+ *
+ * @param string $content 文件内容
+ * @return void
+ */
+ public function saveContent($content){
+ $this->clinet->createFile(rawurldecode($this->fileModel["pre_name"]),"/me/drive/root:/",$content);
+ }
+
+ /**
+ * 计算缩略图大小
+ *
+ * @param int $width 原始宽
+ * @param int $height 原始高
+ * @return array
+ */
+ static function getThumbSize($width,$height){
+ $rate = $width/$height;
+ $maxWidth = 90;
+ $maxHeight = 39;
+ $changeWidth = 39*$rate;
+ $changeHeight = 90/$rate;
+ if($changeWidth>=$maxWidth){
+ return [(int)$changeHeight,90];
+ }
+ return [39,(int)$changeWidth];
+ }
+
+
+ /**
+ * 获取缩略图地址
+ *
+ * @return string 缩略图地址
+ */
+ public function getThumb(){
+ $picInfo = explode(",",$this->fileModel["pic_info"]);
+ $thumbSize = self::getThumbSize($picInfo[0],$picInfo[1]);
+ $thumb = json_decode(json_encode($this->clinet->apiGet("/me/drive/root:/".rawurlencode($this->fileModel["pre_name"]).":/thumbnails")),true);
+ return [1,$thumb["value"][0]["small"]["url"]];
+ }
+
+ /**
+ * 删除某一策略下的指定upyun文件
+ *
+ * @param array $fileList 待删除文件的数据库记录
+ * @param array $policyData 待删除文件的上传策略信息
+ * @return void
+ */
+ static function DeleteFile($fileList,$policyData){
+ $clinet = new Client([
+ 'stream_back_end' => \Krizalys\Onedrive\StreamBackEnd::TEMP,
+ 'client_id' => $policyData["bucketname"],
+
+ // Restore the previous state while instantiating this client to proceed in
+ // obtaining an access token.
+ 'state' => json_decode($policyData["sk"]),
+ ]);
+ foreach (array_column($fileList, 'pre_name') as $key => $value) {
+ $clinet->deleteObject("/me/drive/root:/".rawurlencode($value).":");
+ }
+ }
+
+ /**
+ * 生成文件下载URL
+ *
+ * @return array
+ */
+ public function Download(){
+ $preview = json_decode(json_encode($this->clinet->apiGet("/me/drive/root:/".rawurlencode($this->fileModel["pre_name"]).":")),true);
+ return [1,$preview["@microsoft.graph.downloadUrl"]];
+ }
+
+ /**
+ * 签名临时URL用于Office预览
+ *
+ * @return array
+ */
+ public function signTmpUrl(){
+ return $this->Preview();
+ }
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/application/index/model/UploadHandler.php b/application/index/model/UploadHandler.php
index d2eb5294..c50f8304 100644
--- a/application/index/model/UploadHandler.php
+++ b/application/index/model/UploadHandler.php
@@ -113,7 +113,7 @@ class UploadHandler extends Model{
$path = "";
}
$task = new Task();
- $task->taskName = "Upload Big File " . $fname . "to Onedrive";
+ $task->taskName = "Upload Big File " . $fname . " to Onedrive";
$task->taskType = "uploadChunksToOnedrive";
$task->taskContent = json_encode([
"path" => $path,
@@ -243,7 +243,7 @@ class UploadHandler extends Model{
//处理Onedrive等非直传
if($this->policyContent['policy_type'] == "onedrive"){
$task = new Task();
- $task->taskName = "Upload" . $info["name"] . "to Onedrive";
+ $task->taskName = "Upload" . $info["name"] . " to Onedrive";
$task->taskType = "uploadSingleToOnedrive";
$task->taskContent = json_encode([
"path" => $info["path"],
diff --git a/extend/Krizalys/Onedrive/Client.php b/extend/Krizalys/Onedrive/Client.php
index c9c6cf73..8cb748ad 100644
--- a/extend/Krizalys/Onedrive/Client.php
+++ b/extend/Krizalys/Onedrive/Client.php
@@ -515,12 +515,10 @@ class Client
{
$url =
self::API_URL
- . $path
- . '?access_token=' . urlencode(
- $this->_state->token->data->access_token
- );
-
+ . $path;
$curl = self::_createCurl($path, $options);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer '
+ . $this->_state->token->data->access_token,]);
curl_setopt($curl, CURLOPT_URL, $url);
return $this->_processResult($curl);
}
@@ -538,7 +536,6 @@ class Client
$url = self::API_URL . $path;
$data = (object) $data;
$curl = self::_createCurl($path);
-
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
diff --git a/static/js/angular-filemanager.min.js b/static/js/angular-filemanager.min.js
index a9fbb63d..27950b99 100644
--- a/static/js/angular-filemanager.min.js
+++ b/static/js/angular-filemanager.min.js
@@ -1590,7 +1590,7 @@ angular.module("FileManagerApp").run(["$templateCache",
function(e) {
e.put("src/templates/current-folder-breadcrumb.html", '
\r\n - \r\n \r\n {{"filemanager" | translate}}\r\n \r\n
\r\n - \r\n \r\n {{dir | strLimit : 8}}\r\n \r\n \r\n {{dir | strLimit : 12}}\r\n \r\n
\r\n
'),
e.put("src/templates/item-context-menu.html", ''),
- e.put("src/templates/main-icons.html", '\r\n
\r\n\r\n
\r\n\r\n
\r\n {{"no_files_in_folder" | translate}}...\r\n
\r\n \r\n
\r\n {{ fileNavigator.error }}\r\n
\r\n
'),
+ e.put("src/templates/main-icons.html", '\r\n
\r\n\r\n
\r\n\r\n
\r\n {{"no_files_in_folder" | translate}}...\r\n
\r\n \r\n
\r\n {{ fileNavigator.error }}\r\n
\r\n
'),
e.put("src/templates/main-table-modal.html", ''),
e.put("src/templates/main-table.html", '\r\n'),
e.put("src/templates/main.html", '\r\n
\r\n\r\n
\r\n\r\n
\r\n
\r\n
\r\n'),
diff --git a/static/js/filemanager_share.js b/static/js/filemanager_share.js
index 473bbaee..5b8dea4c 100644
--- a/static/js/filemanager_share.js
+++ b/static/js/filemanager_share.js
@@ -127,10 +127,12 @@ function(e, r) {
},
e.openImagePreview = function() {
var r = e.singleSelection();
+ if(r.model.pic==""){
+ }else{
t =e.apiMiddleware.listPic(r);
loadPreview(t);
-
+ }
@@ -566,6 +568,7 @@ function(e) {
perms: new n(r && r.rights),
content: r && r.content || "",
fileId: r && r.id || '',
+ pic: r && r.pic || '',
recursive: !1,
fullPath: function() {
var e = this.path.filter(Boolean);