Browse Source

Merge pull request #1944 from visuddhinanda/laravel

studio_id -> owner_uid
visuddhinanda 2 years ago
parent
commit
ee65f5615e

+ 2 - 2
app/Http/Controllers/ArticleController.php

@@ -396,7 +396,7 @@ class ArticleController extends Controller
             }
         });
         if(Str::isUuid($newArticle->uid)){
-            return $this->ok($newArticle);
+            return $this->ok(new ArticleResource($newArticle));
         }else{
             return $this->error('fail');
         }
@@ -520,7 +520,7 @@ class ArticleController extends Controller
         $article->save();
 
         OpsLog::debug($user_uid,$article);
-        return $this->ok($article);
+        return $this->ok(new ArticleResource($article));
     }
 
     /**

+ 22 - 8
app/Http/Controllers/AttachmentController.php

@@ -21,7 +21,7 @@ class AttachmentController extends Controller
      *
      * @return \Illuminate\Http\Response
      */
-    public function index()
+    public function index(Request $request)
     {
         //
 		switch ($request->get('view')) {
@@ -34,7 +34,7 @@ class AttachmentController extends Controller
                 if($user['user_uid'] !== StudioApi::getIdByName($request->get('studio'))){
                     return $this->error(__('auth.failed'));
                 }
-                $table = Attachment::where('studio_id', $user["user_uid"]);
+                $table = Attachment::where('owner_uid', $user["user_uid"]);
                 break;
             default:
                 return $this->error("error view",[],200);
@@ -43,6 +43,9 @@ class AttachmentController extends Controller
         if($request->has('search')){
             $table = $table->where('title', 'like', $request->get('search')."%");
         }
+        if($request->has('content_type')){
+            $table = $table->where('content_type', 'like', $request->get('content_type')."%");
+        }
         $count = $table->count();
         $table = $table->orderBy($request->get('order','updated_at'),
                                  $request->get('dir','desc'));
@@ -170,6 +173,14 @@ class AttachmentController extends Controller
     public function update(Request $request, Attachment $attachment)
     {
         //
+        $user = AuthApi::current($request);
+        if(!$user){
+            return $this->error(__('auth.failed'),401,401);
+        }
+
+        $attachment->title = $request->get('title');
+        $attachment->save();
+        return $this->ok(new AttachmentResource($attachment));
     }
 
     /**
@@ -204,15 +215,18 @@ class AttachmentController extends Controller
         if(!$res){
             return $this->error('no res');
         }
-        if($user['user_uid']!==$res->user_uid){
+        if($user['user_uid'] !== $res->user_uid){
             return $this->error(__('auth.failed'),403,403);
         }
-        $del = $res->delete();
+
         //删除文件
-        $path_parts = pathinfo($request->get('name'));
-        Storage::delete($request->get('name'));
-        Storage::delete($path_parts['dirname'].'/'.$path_parts['filename'].'_m.jpg');
-        Storage::delete($path_parts['dirname'].'/'.$path_parts['filename'].'_s.jpg');
+        $filename = $res->bucket . '/' . $res->name;
+        $path_parts = pathinfo($res->name);
+        Storage::delete($filename);
+        Storage::delete($res->bucket.'/'.$path_parts['filename'].'_m.jpg');
+        Storage::delete($res->bucket.'/'.$path_parts['filename'].'_s.jpg');
+
+        $del = $res->delete();
         return $this->ok($del);
     }
 }

+ 11 - 3
app/Http/Controllers/DictController.php

@@ -31,6 +31,7 @@ class DictController extends Controller
         $wordDataOutput = [];
         $dictListOutput = [];
         $caseListOutput = [];
+        $wordDataPass = [];
 		$indexCol = ['word','note','dict_id'];
         $words = [];
         $word_base = [];
@@ -57,6 +58,7 @@ class DictController extends Controller
         for ($i=0; $i < 2; $i++) {
             # code...
             $word_base = [];
+            $wordDataOutput = [];
             foreach ($words as $word => $case) {
                 # code...
                 $searched[] = $word;
@@ -170,15 +172,20 @@ class DictController extends Controller
                     }
                 }
             }
+
+            $wordDataPass[] = ['pass'=>$i+1,'words'=>$wordDataOutput];
+
             if(count($word_base)===0){
                 break;
             }else{
                 $words = $word_base;
             }
+
         }
 
-        if($resultCount<3){
+        if($resultCount<2){
             //查询内文
+            $wordDataOutput = [];
             $table = UserDict::select($indexCol)
                                 ->where('note','like','%'.$word.'%')
                                 ->where('language','<>','my')
@@ -210,11 +217,12 @@ class DictController extends Controller
                 ];
                 $wordData['dict'][] = $currData;
             }
-            $wordDataOutput[]=$wordData;
+            $wordDataOutput[] = $wordData;
+            $wordDataPass[] = ['pass'=>0,'words'=>$wordDataOutput];
         }
 
 
-        $output['words'] = $wordDataOutput;
+        $output['words'] = $wordDataPass;
         $output['dictlist'] = $dictListOutput;
         $output['caselist'] = $caseListOutput;