From ab948b2e716348a14c89ce3c0deeb16cb5c9806a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=BE=E5=A4=AA=20=E2=82=8D=E2=82=8D=20=E2=97=9D=28?= =?UTF-8?q?=EF=BD=A5=E2=97=A1=EF=BD=A5=29=E2=97=9F=20=E2=81=BE=E2=81=BE?= Date: Sun, 18 Aug 2024 06:30:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=95=E7=A8=BF=E3=80=81=E5=AF=A9?= =?UTF-8?q?=E6=A0=B8=E6=99=82=EF=BC=8C=E7=B4=80=E9=8C=84=20IP=20=E8=88=87?= =?UTF-8?q?=20UA=EF=BC=8C=E5=85=8D=E5=BE=97=E8=A2=AB=E6=90=9E=E9=82=84?= =?UTF-8?q?=E4=BB=A5=E7=82=BA=E6=98=AF=E6=AD=A3=E5=B8=B8=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Cards/PublishController.php | 6 ++++++ .../Controllers/Api/Cards/ReviewController.php | 18 ++++++++++-------- app/Domains/Social/Models/Cards.php | 2 ++ app/Domains/Social/Models/Reviews.php | 2 ++ app/Domains/Social/Services/CardsService.php | 4 ++++ app/Domains/Social/Services/ReviewService.php | 4 ++++ ..._11_26_000001_create_social_cards_table.php | 4 ++++ .../seeders/Social/SocialCardsTableSeeder.php | 10 ++++++++++ 8 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/Domains/Social/Http/Controllers/Api/Cards/PublishController.php b/app/Domains/Social/Http/Controllers/Api/Cards/PublishController.php index afde4b18..5ac35a06 100644 --- a/app/Domains/Social/Http/Controllers/Api/Cards/PublishController.php +++ b/app/Domains/Social/Http/Controllers/Api/Cards/PublishController.php @@ -80,6 +80,9 @@ public function article(PublishArticleRequest $request) 'ads' => $picture['ads'], ]; + $data['ip_address'] = $request->ip(); + $data['user_agent'] = $request->header('User-Agent'); + /** * 將文字投稿寫入 */ @@ -124,6 +127,9 @@ public function picture(PublishPictureRequest $request) 'type' => 'picture', ]; + $data['ip_address'] = $request->ip(); + $data['user_agent'] = $request->header('User-Agent'); + /** * 將圖片投稿寫入 */ diff --git a/app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php b/app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php index 90b40c11..d7531d46 100644 --- a/app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php +++ b/app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php @@ -111,7 +111,7 @@ public function voting(Request $request, Cards $card, $status) $platforms = Platform::where('action', Platform::ACTION_PUBLISH) ->active() ->get(); - + /** * 根據社群平台逐一發佈 */ @@ -123,49 +123,49 @@ public function voting(Request $request, Cards $card, $status) case Platform::TYPE_FACEBOOK: dispatch(new FacebookPublishJob($model, $platform))->onQueue('highest'); break; - + /** * 丟給負責發表文章到 Twitter 的 Job */ case Platform::TYPE_TWITTER: dispatch(new TwitterPublishJob($model, $platform))->onQueue('highest'); break; - + /** * 丟給負責發表文章到 Plurk 的 Job */ case Platform::TYPE_PLURK: dispatch(new PlurkPublishJob($model, $platform))->onQueue('highest'); break; - + /** * 丟給負責發表文章到 Discord 的 Job */ case Platform::TYPE_DISCORD: dispatch(new DiscordPublishJob($model, $platform))->onQueue('highest'); break; - + /** * 丟給負責發表文章到 Tumblr 的 Job */ case Platform::TYPE_TUMBLR: dispatch(new TumblrPublishJob($model, $platform))->onQueue('highest'); break; - + /** * 丟給負責發表文章到 Telegram 的 Job */ case Platform::TYPE_TELEGRAM: dispatch(new TelegramPublishJob($model, $platform))->onQueue('highest'); break; - + /** * 丟給負責發表文章到 Bsky 的 Job */ case Platform::TYPE_BSKY: dispatch(new BskyPublishJob($card, $platform))->onQueue('highest'); break; - + /** * 其它並不在支援名單當中的社群 */ @@ -186,6 +186,8 @@ public function voting(Request $request, Cards $card, $status) 'model_id' => $request->user()->id, 'card_id' => $card->id, 'point' => ((bool) $status) ? 1 : -1, + 'ip_address' => $request->ip(), + 'user_agent' => $request->header('User-Agent'), ]); return response()->json([ diff --git a/app/Domains/Social/Models/Cards.php b/app/Domains/Social/Models/Cards.php index 7bcae0c5..07a694c5 100644 --- a/app/Domains/Social/Models/Cards.php +++ b/app/Domains/Social/Models/Cards.php @@ -59,6 +59,8 @@ class Cards extends Model 'blockade_by', 'blockade_remarks', 'blockade_at', + 'ip_address', + 'user_agent', ]; /** diff --git a/app/Domains/Social/Models/Reviews.php b/app/Domains/Social/Models/Reviews.php index 90941215..5bebcf63 100644 --- a/app/Domains/Social/Models/Reviews.php +++ b/app/Domains/Social/Models/Reviews.php @@ -45,6 +45,8 @@ class Reviews extends Model 'card_id', 'point', 'config', + 'ip_address', + 'user_agent', ]; /** diff --git a/app/Domains/Social/Services/CardsService.php b/app/Domains/Social/Services/CardsService.php index c67ca439..f1e8b09a 100644 --- a/app/Domains/Social/Services/CardsService.php +++ b/app/Domains/Social/Services/CardsService.php @@ -101,6 +101,8 @@ public function store(array $data = []): Cards 'content' => $data['content'], 'config' => $data['config'], 'picture' => $data['picture'], + 'ip_address' => $data['ip_address'], + 'user_agent' => $data['user_agent'], ]); } catch (Exception $e) { DB::rollBack(); @@ -262,6 +264,8 @@ protected function createCards(array $data = []): Cards 'picture' => $this->createImage($data['picture']), 'active' => $data['active'] ?? false, 'blockade' => $data['blockade'] ?? false, + 'ip_address' => $data['ip_address'] ?? null, + 'user_agent' => $data['user_agent'] ?? null, ]); } diff --git a/app/Domains/Social/Services/ReviewService.php b/app/Domains/Social/Services/ReviewService.php index f259e69f..384815a9 100644 --- a/app/Domains/Social/Services/ReviewService.php +++ b/app/Domains/Social/Services/ReviewService.php @@ -119,6 +119,8 @@ public function store(array $data): Reviews 'model_id' => $data['model_id'], 'card_id' => $data['card_id'], 'point' => $data['point'], + 'ip_address' => $data['ip_address'], + 'user_agent' => $data['user_agent'], ]); } catch (Exception $e) { DB::rollBack(); @@ -197,6 +199,8 @@ protected function createReview(array $data = []): Reviews 'card_id' => $data['card_id'], 'point' => $data['point'], 'config' => isset($data['config']) ? json_encode($data['config']) : '{}', + 'ip_address' => $data['ip_address'] ?? null, + 'user_agent' => $data['user_agent'] ?? null, ]); } } diff --git a/database/migrations/2020_11_26_000001_create_social_cards_table.php b/database/migrations/2020_11_26_000001_create_social_cards_table.php index f62c3c3c..c5e5dc1e 100644 --- a/database/migrations/2020_11_26_000001_create_social_cards_table.php +++ b/database/migrations/2020_11_26_000001_create_social_cards_table.php @@ -88,6 +88,8 @@ public function up(): void $table->unsignedBigInteger('blockade_by')->nullable()->comment('被誰封鎖'); $table->string('blockade_remarks')->nullable()->comment('封鎖原因'); $table->timestamp('blockade_at')->nullable()->comment('在什麼時候被封鎖'); + $table->string('ip_address')->nullable()->comment('IP Address'); + $table->string('user_agent')->nullable()->comment('User Agent'); $table->timestamps(); $table->softDeletes(); @@ -146,6 +148,8 @@ public function up(): void $table->unsignedBigInteger('card_id')->comment('文章 ID'); $table->integer('point')->default(0)->comment('票數權重'); $table->json('config')->comment('設定'); + $table->string('ip_address')->nullable()->comment('IP Address'); + $table->string('user_agent')->nullable()->comment('User Agent'); $table->timestamps(); $table->softDeletes(); diff --git a/database/seeders/Social/SocialCardsTableSeeder.php b/database/seeders/Social/SocialCardsTableSeeder.php index ea06790e..85ad3e9f 100644 --- a/database/seeders/Social/SocialCardsTableSeeder.php +++ b/database/seeders/Social/SocialCardsTableSeeder.php @@ -47,6 +47,8 @@ public function run() 'blockade_by' => null, 'blockade_remarks' => null, 'blockade_at' => null, + 'ip_address' => '127.0.0.1', + 'user_agent' => 'Mozilla/5.0', ]); Cards::create([ @@ -72,6 +74,8 @@ public function run() 'blockade_by' => null, 'blockade_remarks' => null, 'blockade_at' => null, + 'ip_address' => '127.0.0.1', + 'user_agent' => 'Mozilla/5.0', ]); Cards::create([ @@ -106,6 +110,8 @@ public function run() 'blockade_by' => null, 'blockade_remarks' => null, 'blockade_at' => null, + 'ip_address' => '127.0.0.1', + 'user_agent' => 'Mozilla/5.0', ]); Cards::create([ @@ -131,6 +137,8 @@ public function run() 'blockade_by' => null, 'blockade_remarks' => null, 'blockade_at' => null, + 'ip_address' => '127.0.0.1', + 'user_agent' => 'Mozilla/5.0', ]); Cards::create([ @@ -156,6 +164,8 @@ public function run() 'blockade_by' => null, 'blockade_remarks' => null, 'blockade_at' => null, + 'ip_address' => '127.0.0.1', + 'user_agent' => 'Mozilla/5.0', ]); Cards::create([