11
11
*/
12
12
namespace Overtrue \LaravelUEditor ;
13
13
14
- use Qiniu \Auth ;
15
- use Qiniu \Processing \Operation ;
16
- use Qiniu \Storage \BucketManager ;
17
- use Qiniu \Storage \UploadManager ;
14
+ use Storage ;
18
15
use Symfony \Component \HttpFoundation \File \UploadedFile ;
19
16
20
17
/**
@@ -32,19 +29,7 @@ class QiNiuStorage implements StorageInterface
32
29
*/
33
30
public function store (UploadedFile $ file , $ filename )
34
31
{
35
- $ uploadManager = new UploadManager ();
36
-
37
- list ($ result , $ error ) = $ uploadManager ->putFile (
38
- $ this ->getQiNiuAuth ()->uploadToken (config ('filesystems.disks.qiniu.bucket ' )),
39
- basename ($ filename ),
40
- $ file ->getRealPath ()
41
- );
42
-
43
- if ($ error !== null ) {
44
- throw new StoreErrorException (trans ('ERROR_UNKNOWN ' ));
45
- } else {
46
- // Anything todo here ?
47
- }
32
+ Storage::disk ('qiniu ' )->writeStream ($ filename , fopen ($ file ->getRealPath (), 'r ' ));
48
33
}
49
34
50
35
/**
@@ -59,67 +44,24 @@ public function store(UploadedFile $file, $filename)
59
44
*/
60
45
public function lists ($ path , $ start , $ size = 20 , array $ allowFiles = [])
61
46
{
62
- $ bucketManager = new BucketManager ($ this ->getQiNiuAuth ());
63
-
64
- list ($ iterms , $ marker , $ error ) = $ bucketManager ->listFiles (config ('filesystems.disks.qiniu.bucket ' ), '' , '' , $ size );
65
-
66
- if ($ error !== null ) {
67
- throw new StoreErrorException (trans ('ERROR_UNKNOWN ' ));
68
- } else {
69
- $ files = [];
70
- foreach (collect ($ iterms )->sortBy ('putTime ' , SORT_REGULAR , true )->toArray () as $ file ) {
71
- $ files [] = [
72
- 'url ' => $ this ->getQiNiuUrl ($ file ['key ' ]),
73
- 'mtime ' => $ file ['putTime ' ],
74
- ];
75
- }
47
+ $ contents = Storage::disk ('qiniu ' )->listContents ($ path ,true );
76
48
49
+ return collect ($ contents )->map (function ($ file ) {
50
+ $ files ['url ' ] = $ this ->getUrl ('/ ' .$ file ['path ' ]);
51
+ $ files ['mtime ' ] = $ file ['timestamp ' ];
77
52
return $ files ;
78
- }
53
+ });
79
54
}
80
55
81
56
/**
82
57
* Make the url of file.
83
58
*
84
59
* @param $filename
85
60
*
86
- * @return mixed
87
- */
88
- public function getUrl ($ filename )
89
- {
90
- return $ this ->getQiNiuUrl (basename ($ filename ));
91
- }
92
-
93
- /**
94
- * Get QiNiu auth object.
95
- *
96
- * @return string
97
- */
98
- protected function getQiNiuAuth ()
99
- {
100
- return new Auth (config ('filesystems.disks.qiniu.key ' ), config ('filesystems.disks.qiniu.secret ' ));
101
- }
102
-
103
-
104
- /**
105
- * Get QiNiu url base on file key.
106
- *
107
- * @param $key
108
61
* @return string
109
62
*/
110
- protected function getQiNiuUrl ($ key )
111
- {
112
- return $ this ->getQiNiuOperation ()->buildUrl ($ key , [], config ('filesystems.disks.qiniu.protocol ' ));
113
- }
114
-
115
- /**
116
- * Get QiNiu operation object.
117
- *
118
- * @return Operation
119
- */
120
- protected function getQiNiuOperation ()
63
+ public function getUrl ($ filename )
121
64
{
122
- return new Operation ( config ('filesystems.disks.qiniu.domain ' )) ;
65
+ return ' http:// ' . config ('filesystems.disks.qiniu.domain ' ) . $ filename ;
123
66
}
124
-
125
67
}
0 commit comments