Sfoglia il codice sorgente

Merge pull request #1615 from visuddhinanda/laravel

offline index 放 Cache
visuddhinanda 2 anni fa
parent
commit
2e6340cb47

+ 13 - 10
app/Console/Commands/ExportOffline.php

@@ -45,6 +45,7 @@ class ExportOffline extends Command
         //term
         $this->info('term');
         $this->call('export:term');
+
         //导出channel
         $this->info('channel');
         $this->call('export:channel');
@@ -67,14 +68,17 @@ class ExportOffline extends Command
 
         $this->info('zip');
         $exportPath = 'app/public/export/offline';
-        $exportFile = 'sentence-'.date("Y-m-d").'.db3';
-        $zipFile = "sentence-".date("Y-m-d").".db3.";
-        if($this->argument('format')==='7z'){
-            $zipFile .= "7z";
-        }else if($this->argument('format')==='lzma'){
-            $zipFile .= "lzma";
-        }else{
-            $zipFile .= "gz";
+        $exportFile = 'wikipali-offline-'.date("Y-m-d").'.db3';
+        switch ($this->argument('format')) {
+            case '7z':
+                $zipFile = $exportFile . ".7z";
+                break;
+            case 'lzma':
+                $zipFile = $exportFile . ".lzma";
+                break;
+            default:
+                $zipFile = $exportFile . ".gz";
+                break;
         }
         //
         $exportFullFileName = storage_path($exportPath.'/'.$exportFile);
@@ -94,13 +98,12 @@ class ExportOffline extends Command
 
         $info = array();
         $info[] = ['filename'=>$zipFile,
-                   'url'=>Storage::disk('local')->url($exportPath.'/'.$zipFile),
                    'create_at'=>date("Y-m-d H:i:s"),
                    'chapter'=>Cache::get("/export/chapter/count"),
                    'filesize'=>filesize($zipFullFileName),
                    'min_app_ver'=>'1.3',
                     ];
-        Storage::disk('local')->put("public/export/offline/index.json", json_encode($info));
+        Cache::put('/offline/index',$info);
         return 0;
     }
 }

+ 69 - 0
app/Http/Controllers/OfflineIndexController.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Cache;
+
+class OfflineIndexController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+        if(Cache::has('/offline/index')){
+            return Cache::get('/offline/index');
+        }else{
+            return [];
+        }
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function show($id)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, $id)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy($id)
+    {
+        //
+    }
+}

+ 2 - 4
routes/api.php

@@ -67,6 +67,7 @@ use App\Http\Controllers\DictStatisticController;
 use App\Http\Controllers\SearchTitleController;
 use App\Http\Controllers\TransferController;
 use App\Http\Controllers\HealthCheckController;
+use App\Http\Controllers\OfflineIndexController;
 
 /*
 |--------------------------------------------------------------------------
@@ -186,6 +187,7 @@ Route::group(['prefix' => 'v2'],function(){
     Route::apiResource('search-title-index',SearchTitleController::class);
     Route::apiResource('transfer',TransferController::class);
     Route::apiResource('health-check',HealthCheckController::class);
+    Route::apiResource('offline-index',OfflineIndexController::class);
 
     Route::get('download/{type1}/{type2}/{uuid}/{filename}', function ($type1,$type2,$uuid,$filename) {
         header("Content-Type: {$type1}/{$type1}");
@@ -199,10 +201,6 @@ Route::group(['prefix' => 'v2'],function(){
         return file_get_contents(public_path("app/palicanon/category/{$file}.json"));
     });
 
-    Route::get('offline-index', function () {
-        return file_get_contents(storage_path("app/public/export/offline/index.json"));
-    });
-
     Route::get('guide/{lang}/{file}', function ($lang,$file) {
         $filename = public_path("app/users_guide/{$lang}/{$file}.md");
         if(file_exists($filename)){