Kaynağa Gözat

s3 加 bucket

visuddhinanda 2 yıl önce
ebeveyn
işleme
2dbbc4f5f2

+ 19 - 17
app/Console/Commands/ExportOffline.php

@@ -16,7 +16,7 @@ class ExportOffline extends Command
      * php artisan export:offline lzma
      * @var string
      */
-    protected $signature = 'export:offline {format?  : zip file format 7z,lzma,gz }';
+    protected $signature = 'export:offline {format?  : zip file format 7z,lzma,gz } {--shortcut}';
 
     /**
      * The console command description.
@@ -69,22 +69,24 @@ class ExportOffline extends Command
         $this->info('channel');
         $this->call('export:channel');
 
-        //tag
-        $this->info('tag');
-        $this->call('export:tag');
-        $this->call('export:tag.map');
-        //
-        $this->info('pali text');
-        $this->call('export:pali.text');
-        //导出章节索引
-        $this->info('chapter');
-        $this->call('export:chapter.index');
-        //导出译文
-        $this->info('sentence');
-        $this->call('export:sentence',['--type'=>'translation']);
-        $this->call('export:sentence',['--type'=>'nissaya']);
-        //导出原文
-        $this->call('export:sentence',['--type'=>'original']);
+        if(!$this->option('shortcut')){
+            //tag
+            $this->info('tag');
+            $this->call('export:tag');
+            $this->call('export:tag.map');
+            //
+            $this->info('pali text');
+            $this->call('export:pali.text');
+            //导出章节索引
+            $this->info('chapter');
+            $this->call('export:chapter.index');
+            //导出译文
+            $this->info('sentence');
+            $this->call('export:sentence',['--type'=>'translation']);
+            $this->call('export:sentence',['--type'=>'nissaya']);
+            //导出原文
+            $this->call('export:sentence',['--type'=>'original']);
+        }
 
         $this->info('zip');
         Log::debug('export offline: db写入完毕');

+ 20 - 7
app/Console/Commands/ExportZip.php

@@ -96,22 +96,35 @@ class ExportZip extends Command
                 ];
         }
 
-        //s3
-        Storage::put($zipFile, file_get_contents($zipFullFileName));
+        $this->info('upload file='.$zipFile);
+        Log::debug('export offline: upload file {filename}',['filename'=>$zipFile]);
+
+        $bucket = 'attachments-'.config('app.env');
+        $tmpFile =  "{$bucket}\{$zipFile}";
+        Storage::put($tmpFile, file_get_contents($zipFullFileName));
+
+        $this->info('upload done file='.$tmpFile);
+        Log::debug('export offline: upload done {filename}',['filename'=>$tmpFile]);
 
         if (App::environment('local')) {
-            $s3Link = Storage::url($zipFile);
+            $link = Storage::url($tmpFile);
         }else{
             try{
-                $s3Link = Storage::temporaryUrl($zipFile, now()->addDays(1));
+                $link = Storage::temporaryUrl($tmpFile, now()->addDays(2));
             }catch(\Exception $e){
-                Log::error('export offline generate temporaryUrl fail {Exception}',['exception'=>$e]);
+                Log::error('export offline: generate temporaryUrl fail {Exception}',
+                            [
+                                'exception'=>$e,
+                                'file'=>$tmpFile
+                            ]);
                 return 1;
             }
         }
-        Log::info('export offline: link='.$s3Link);
+        $this->info('link = '.$link);
+        Log::info('export offline: link='.$link);
+
         $url[] = [
-            'link'=>$s3Link,
+            'link'=>$link,
             'hostname'=>'Amazon cloud storage(Hongkong)',
         ];
         $info[] = ['filename'=>$zipFile,