dever 3 years ago
parent
commit
a009050a60
8 changed files with 35 additions and 20 deletions
  1. 5 0
      database/upload.php
  2. 5 0
      database/yun.php
  3. 6 2
      lib/Store/Core.php
  4. 12 9
      lib/Store/Handle.php
  5. 1 1
      lib/Store/Oss.php
  6. 1 1
      lib/Store/Qiniu.php
  7. BIN
      sdk/Qiniu/.DS_Store
  8. 5 7
      src/View.php

+ 5 - 0
database/upload.php

@@ -42,6 +42,11 @@ return array
 	# 显示给用户看的名称
 	'lang' => '资源配置',
 	'order'	=> 100,
+	'end' => array
+	(
+		'insert' => 'upload/lib/config.create',
+		'update' => 'upload/lib/config.create',
+	),
 	# 数据结构
 	'struct' => array
 	(

+ 5 - 0
database/yun.php

@@ -15,6 +15,11 @@ return array
     # 显示给用户看的名称
     'lang' => '云端配置',
     'order' => 1,
+    'end' => array
+    (
+        'insert' => 'upload/lib/config.create',
+        'update' => 'upload/lib/config.create',
+    ),
     # 数据结构
     'struct' => array
     (

+ 6 - 2
lib/Store/Core.php

@@ -43,9 +43,10 @@ class Core
 	 * 
 	 * @return mixed
 	 */
-	public function __construct($data = array())
+	public function __construct($config, $data = array())
 	{
 		$this->data = $data;
+		$this->config = $config;
 	}
 
 	public function getData()
@@ -125,7 +126,9 @@ class Core
 		if (trim($this->data['key']) == '') {
 			$this->output['status'] = -1;
 			$this->output['message'] = '请添加配置key';
-		} else {
+		}
+		/*
+		else {
 			$this->config = Dever::load('upload/upload-one', $this->data['key']);
 			
 			if (!$this->config) {
@@ -133,6 +136,7 @@ class Core
 				$this->output['message'] = '此配置不存在';
 			}
 		}
+		*/
 	}
 	
 	/**

+ 12 - 9
lib/Store/Handle.php

@@ -13,25 +13,28 @@ class Handle
     public function __construct($data = array())
     {
         $this->yun = $this->local = false;
-        $config = Dever::db('upload/upload')->one($data['key']);
+        $config = Dever::load('upload/lib/config')->get($data['key']);
+        //$config = Dever::db('upload/upload')->one($data['key']);
+        if (!$config) {
+            Dever::alert('错误的上传配置');
+            return;
+        }
 
         $this->save_type = $config['save_type'];
 
-        $yun = $config['yun'];
-        if ($this->save_type >= 2) {
-            $yun = Dever::db('upload/yun')->one($yun);
-            if ($yun['type'] == 2) {
+        if ($this->save_type >= 2 && $config['yun']) {
+            if ($config['yun']['type'] == 2) {
                 $class = 'Upload\Lib\Store\Qiniu';
-            } elseif ($yun['type'] == 1) {
+            } elseif ($config['yun']['type'] == 1) {
                 $class = 'Upload\Lib\Store\Oss';
             }
-            $data['host'] = $yun['host'];
+            $data['host'] = $config['yun']['host'];
             
-            $this->yun = new $class($data);
+            $this->yun = new $class($config, $data);
         }
 
         if ($this->save_type <= 3) {
-            $this->local = new Local($data);
+            $this->local = new Local($config, $data);
         }
     }
 

+ 1 - 1
lib/Store/Oss.php

@@ -15,7 +15,7 @@ class Oss extends Core implements Config
      */
     public function save()
     {
-        $config = Dever::db('upload/yun')->one($this->config['yun']);
+        $config = $this->config['yun'];
         $accessKey = $config['appkey'];
         $secretKey = $config['appsecret'];
         $endpoint = "http://oss-cn-".$config['region_id'].".aliyuncs.com";

+ 1 - 1
lib/Store/Qiniu.php

@@ -14,7 +14,7 @@ class Qiniu extends Core implements Config
      */
     public function save()
     {
-        $config = Dever::db('upload/yun')->one($this->config['yun']);
+        $config = $this->config['yun'];
         $accessKey = $config['appkey'];
         $secretKey = $config['appsecret'];
         $this->host = $config['host'];

BIN
sdk/Qiniu/.DS_Store


+ 5 - 7
src/View.php

@@ -302,10 +302,9 @@ class View
     public function getYun($key)
     {
         $key = Dever::input('key', $key);
-        $config = Dever::db('upload/upload')->one($key);
-        if ($config && $key && $config['save_type'] >= 2 && $config['yun'] > 0) {
-            $yun = Dever::db('upload/yun')->one($config['yun']);
-            return $yun['host'];
+        $config = Dever::load('upload/lib/config')->get($key);
+        if ($config && $config['yun']) {
+            return $config['yun']['host'];
         }
         return false;
     }
@@ -320,8 +319,7 @@ class View
         $id = $array[2];
 
         $host = Dever::config('host')->uploadRes;
-        $dest = $file;
-        $path = '';
+        $path = $dest = $file;
         $handle = true;
         $local = false;
         if (strstr($file, '{uploadRes}') || strstr($file, $host)) {
@@ -356,7 +354,7 @@ class View
             $temp = explode('/', $path);
             $key = $temp[0];
             $image['file']  = false;
-            $image['key']   = $key;
+            $image['key']   = intval($key);
             $handle = new Handle($image);
             if ($type) {
                 $method = 'handle_' . $type;