Просмотр исходного кода

Merge pull request #2179 from visuddhinanda/laravel

wbw句子支持删除
visuddhinanda 1 год назад
Родитель
Сommit
a41eee3902

+ 7 - 3
app/Console/Commands/UpgradeWeekly.php

@@ -40,21 +40,25 @@ class UpgradeWeekly extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
+        $currTime = time();
         #译文进度
         $this->call('upgrade:progress');
         $time = time()-$currTime;
-        $message .= "progress:{$time}; ";
+        $message = "progress time:{$time}; ";
+        $this->info($message);
         $currTime = time();
 
         $this->call('upgrade:progress.chapter');
         $time = time()-$currTime;
-        $message .= "progress.chapter:{$time}; ";
+        $message = "progress.chapter time:{$time}; ";
+        $this->info($message);
         $currTime = time();
 
         # 逐词译数据库分析
         $this->call('upgrade:wbw.analyses');
         $time = time()-$currTime;
-        $message .= "wbw.analyses:{$time}; ";
+        $message = "wbw.analyses:{$time}; ";
+        $this->info($message);
 
         # 段落更新图
         $this->call('upgrade:chapter.dynamic');

+ 5 - 1
app/Http/Api/ChannelApi.php

@@ -83,7 +83,11 @@ class ChannelApi{
         }
         return $output;
     }
-
+    public static function canManageByUser($channelId,$userUuid){
+        $isOwner = Channel::where('owner_uid', $userUuid)
+                    ->where('uid', $channelId)->exists();
+        return $isOwner;
+    }
     public static function getSysChannel($channel_name,$fallback=""){
         $channel = Channel::where('name',$channel_name)
                     ->where('owner_uid',config("mint.admin.root_uuid"))

+ 21 - 1
app/Http/Controllers/WbwSentenceController.php

@@ -13,6 +13,7 @@ use App\Http\Api\AuthApi;
 use App\Http\Api\ShareApi;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\CourseApi;
+use App\Models\Sentence;
 
 class WbwSentenceController extends Controller
 {
@@ -168,8 +169,27 @@ class WbwSentenceController extends Controller
      * @param  \App\Models\Wbw  $wbw
      * @return \Illuminate\Http\Response
      */
-    public function destroy(Wbw $wbw)
+    public function destroy(Request $request,string $sentId)
     {
         //
+        //鉴权
+        $user = AuthApi::current($request);
+        if(!$user ){
+            //未登录用户
+            return $this->error(__('auth.failed'),401,401);
+        }
+        $channelId = $request->get('channel');
+        if(!ChannelApi::canManageByUser($channelId,$user['user_uid'])){
+            return $this->error(__('auth.failed'),403,403);
+        }
+        $sent = explode('-',$sentId);
+        $wbwBlockId = WbwBlock::where('book_id',$sent[0])
+                        ->where('paragraph',$sent[1])
+                        ->where('channel_uid',$channelId)
+                        ->value('uid');
+        $delete = Wbw::where('block_uid',$wbwBlockId)
+                    ->whereBetween('wid',[$sent[2],$sent[3]])
+                    ->delete();
+        return $this->ok($delete);
     }
 }