rabin 1 سال پیش
والد
کامیت
dc14461e72
3فایلهای تغییر یافته به همراه57 افزوده شده و 14 حذف شده
  1. 6 0
      lib/View/Qiniu.php
  2. 47 0
      lib/Yun.php
  3. 4 14
      src/Yun.php

+ 6 - 0
lib/View/Qiniu.php

@@ -38,6 +38,12 @@ class Qiniu
         return array('qiniu', $token, $domain, $upload['bucket']);
     }
 
+    public function view($config, $file)
+    {
+        $this->auth = new \Qiniu\Auth($config['appkey'], $config['appsecret']);
+        return $this->auth->privateDownloadUrl($file);
+    }
+
     public function callback()
 	{
 		$body = file_get_contents('php://input');

+ 47 - 0
lib/Yun.php

@@ -0,0 +1,47 @@
+<?php
+namespace Upload\Lib;
+
+use Dever;
+
+class Yun
+{
+    public function get($id)
+    {
+        $upload = Dever::db('upload/upload')->one($id);
+        if (!$upload) {
+            return false;
+        }
+        if ($upload['save_type'] == 1) {
+            return false;
+        }
+        if (!$upload['yun']) {
+            return false;
+        }
+        $config = Dever::db('upload/yun')->one($upload['yun']);
+        if (!$config) {
+            return false;
+        }
+    }
+
+    public function view($file)
+    {
+    	$data = parse_url($file);
+    	$path = ltrim($data['path'], '/');
+    	$temp = explode('/', $path);
+    	$config = $this->get($temp[0]);
+    	if (!$config) {
+    		return $file;
+    	}
+    	return Dever::load('upload/lib/yun')->getMethod($config['type'])->view($config, $file);
+    }
+
+    public function getMethod($type)
+	{
+		if ($type == 1) {
+        	$method = 'oss';
+        } else {
+        	$method = 'qiniu';
+        }
+		return Dever::load('upload/lib/view/' . $method);
+	}
+}

+ 4 - 14
src/Yun.php

@@ -10,16 +10,6 @@ use Dever;
 
 class Yun
 {
-	private function getMethod($type)
-	{
-		if ($type == 1) {
-        	$method = 'oss';
-        } else {
-        	$method = 'qiniu';
-        }
-		return Dever::load('upload/lib/view/' . $method);
-	}
-
     # 查看视频截图
     public function cover($key, $video, $num = 1, $local = 2)
     {
@@ -29,7 +19,7 @@ class Yun
         $config = Dever::db('upload/yun')->one(array('host' => $host));
 
         if ($config) {
-            return $this->getMethod($config['type'])->cover($key, $video, $num, $local);
+            return Dever::load('upload/lib/yun')->getMethod($config['type'])->cover($key, $video, $num, $local);
         }
 
         return false;
@@ -61,7 +51,7 @@ class Yun
             $cover = 2;
         }
         
-        list($type, $token, $domain, $bucket) = $this->getMethod($config['type'])->token($config, $upload);
+        list($type, $token, $domain, $bucket) = Dever::load('upload/lib/yun')->getMethod($config['type'])->token($config, $upload);
         $result = array('type' => $type, 'uptoken' => $token, 'domain' => $domain, 'host' => $config['host'], 'bucket' => $bucket, 'cover' => $cover);
         if ($return == 1) {
             return $result;
@@ -80,7 +70,7 @@ class Yun
 		if (!$config) {
 			return 'error';
 		}
-		$body = $this->getMethod($config['type'])->callback();
+		$body = Dever::load('upload/lib/yun')->getMethod($config['type'])->callback();
 		$file = $body['filename'];
 		$key = $body['key'];
 		$size = $body['filesize'];
@@ -150,7 +140,7 @@ class Yun
             if ($upload['yun'] > 0 && $upload['vod_convert'] == 2) {
                 $config = Dever::db('upload/yun')->one($upload['yun']);
                 if ($config) {
-                    $this->getMethod($config['type'])->convert($key, $file, $config, $upload);
+                    Dever::load('upload/lib/yun')->getMethod($config['type'])->convert($key, $file, $config, $upload);
                 }
             }
             $this->initFile($key, $file, $source, false, false, false, $search);