Browse Source

use temporaryUrl

visuddhinanda 2 years ago
parent
commit
d203d5dc20
2 changed files with 42 additions and 2 deletions
  1. 12 1
      app/Console/Commands/ExportZip.php
  2. 30 1
      app/Http/Controllers/OfflineIndexController.php

+ 12 - 1
app/Console/Commands/ExportZip.php

@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Facades\Log;
 use App\Tools\RedisClusters;
+use Illuminate\Support\Facades\App;
 
 class ExportZip extends Command
 {
@@ -97,7 +98,17 @@ class ExportZip extends Command
 
         //s3
         Storage::put($zipFile, file_get_contents($zipFullFileName));
-        $s3Link = Storage::url($zipFile);
+
+        if (App::environment('local')) {
+            $s3Link = Storage::url($zipFile);
+        }else{
+            try{
+                $s3Link = Storage::temporaryUrl($zipFile, now()->addDays(1));
+            }catch(\Exception $e){
+                Log::error('export offline generate temporaryUrl fail {Exception}',['exception'=>$e]);
+                return 1;
+            }
+        }
         Log::info('export offline: link='.$s3Link);
         $url[] = [
             'link'=>$s3Link,

+ 30 - 1
app/Http/Controllers/OfflineIndexController.php

@@ -7,6 +7,8 @@ use Illuminate\Support\Facades\Cache;
 use App\Tools\RedisClusters;
 use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Facades\App;
 
 class OfflineIndexController extends Controller
 {
@@ -19,7 +21,34 @@ class OfflineIndexController extends Controller
     {
         //
         if(RedisClusters::has('/offline/index')){
-            return RedisClusters::get('/offline/index');
+            $fileInfo = RedisClusters::get('/offline/index');
+            foreach ($fileInfo as $key => $file) {
+                $zipFile = $file['filename'];
+                $url = array();
+                foreach (config('mint.server.cdn_urls') as $key => $cdn) {
+                    $url[] = [
+                            'link' => $cdn . '/' . $zipFile,
+                            'hostname' =>'cdn-' . $key,
+                        ];
+                }
+                if (App::environment('local')) {
+                    $s3Link = Storage::url($zipFile);
+                }else{
+                    try{
+                        $s3Link = Storage::temporaryUrl($zipFile, now()->addDays(1));
+                    }catch(\Exception $e){
+                        Log::error('offline-index {Exception}',['exception'=>$e]);
+                        return [];
+                    }
+                }
+                Log::info('offline-index: link='.$s3Link);
+                $url[] = [
+                    'link'=>$s3Link,
+                    'hostname'=>'Amazon cloud storage(Hongkong)',
+                ];
+                $fileInfo[$key]['url'] = $url;
+            }
+            return $fileInfo;
         }else{
             return [];
         }