Add comment spam classification and captcha checks.
Score artwork comments with local signatures plus Together AI, and optionally require Turnstile before posting.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('artwork_comments', function (Blueprint $table): void {
|
||||
$table->unsignedTinyInteger('spam_score')->nullable()->after('is_approved');
|
||||
$table->unsignedTinyInteger('spam_probability')->nullable()->after('spam_score');
|
||||
$table->string('spam_reason', 500)->nullable()->after('spam_probability');
|
||||
$table->string('moderation_source', 40)->nullable()->after('spam_reason');
|
||||
$table->timestamp('moderated_at')->nullable()->after('moderation_source');
|
||||
$table->index(['spam_score', 'moderated_at'], 'artwork_comments_spam_score_idx');
|
||||
});
|
||||
|
||||
Schema::create('comment_spam_signatures', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('content_hash', 64)->unique();
|
||||
$table->string('pattern_signature', 64)->nullable()->index();
|
||||
$table->string('source', 40);
|
||||
$table->string('reason', 500)->nullable();
|
||||
$table->unsignedTinyInteger('confidence')->default(0);
|
||||
$table->unsignedInteger('hit_count')->default(0);
|
||||
$table->unsignedBigInteger('reviewed_by')->nullable()->index();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('comment_spam_signatures');
|
||||
Schema::table('artwork_comments', function (Blueprint $table): void {
|
||||
$table->dropIndex('artwork_comments_spam_score_idx');
|
||||
$table->dropColumn([
|
||||
'spam_score', 'spam_probability', 'spam_reason',
|
||||
'moderation_source', 'moderated_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('comment_spam_signatures')) {
|
||||
Schema::create('comment_spam_signatures', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('content_hash', 64)->unique();
|
||||
$table->string('pattern_signature', 64)->nullable()->index();
|
||||
$table->string('source', 40);
|
||||
$table->string('reason', 500)->nullable();
|
||||
$table->unsignedTinyInteger('confidence')->default(0);
|
||||
$table->unsignedInteger('hit_count')->default(0);
|
||||
$table->unsignedBigInteger('reviewed_by')->nullable()->index();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('comment_spam_signatures', function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'pattern_signature')) {
|
||||
$table->string('pattern_signature', 64)->nullable()->index();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'source')) {
|
||||
$table->string('source', 40)->nullable();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'reason')) {
|
||||
$table->string('reason', 500)->nullable();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'confidence')) {
|
||||
$table->unsignedTinyInteger('confidence')->default(0);
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'hit_count')) {
|
||||
$table->unsignedInteger('hit_count')->default(0);
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'reviewed_by')) {
|
||||
$table->unsignedBigInteger('reviewed_by')->nullable()->index();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'metadata')) {
|
||||
$table->json('metadata')->nullable();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('comment_spam_signatures', 'created_at')) {
|
||||
$table->timestamp('created_at')->nullable()->useCurrent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('comment_spam_signatures') || ! Schema::hasColumn('comment_spam_signatures', 'hit_count')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('comment_spam_signatures', function (Blueprint $table): void {
|
||||
$table->dropColumn('hit_count');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user