From ccdf7d9b29e2a9988dc36869cbcf55940374eb0d Mon Sep 17 00:00:00 2001 From: Ghostie Date: Mon, 6 Jan 2025 19:59:20 -0500 Subject: [PATCH] some more fixes --- README.md | 2 +- TODO.md | 6 ++-- app/Http/Controllers/AP/APActorController.php | 15 +++++++--- .../Controllers/AP/APGeneralController.php | 23 +++++++++++++++ .../Controllers/AP/APOutboxController.php | 4 --- app/Models/Note.php | 1 + app/Types/TypeNote.php | 5 +++- ...01_07_000558_add_fields_to_notes_table.php | 28 +++++++++++++++++++ resources/views/browse.blade.php | 4 ++- routes/api.php | 5 ++++ 10 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 app/Http/Controllers/AP/APGeneralController.php create mode 100644 database/migrations/2025_01_07_000558_add_fields_to_notes_table.php diff --git a/README.md b/README.md index 1bfbf3b..e87dbf2 100644 --- a/README.md +++ b/README.md @@ -192,4 +192,4 @@ WantedBy=multi-user.target ## TODO: -For a list of planned features and improvements, please refer to the [TODO](TODO) file. +For a list of planned features and improvements, please refer to the [TODO](TODO.md) file. diff --git a/TODO.md b/TODO.md index 36b1cb1..abf71e0 100644 --- a/TODO.md +++ b/TODO.md @@ -17,6 +17,7 @@ - [ ] Local Boost - [x] Tags - [ ] Pinned Posts + - [ ] Nodeinfo - [-] Social features - [x] Profile @@ -52,8 +53,9 @@ - [ ] Fixes - [x] Fix that weird json encoding in the object field of an activity - - [ ] The profile attachments are not working, they are not being federalised somehow (the interests thingy) - - [ ] Endpoints for getting notes (/ap/v1/note/{note}) + - [x] The profile attachments are not working, they are not being federalised somehow (the interests thingy) + - [x] Endpoints for getting notes (/ap/v1/note/{note}) - [ ] Fix hashtags on post update - [x] Use jobs when posting activities - [ ] Sign the get activities for mastodon when secure mode is enable + - [x] Set a minimum font size for the tags cloud diff --git a/app/Http/Controllers/AP/APActorController.php b/app/Http/Controllers/AP/APActorController.php index 01092b7..39771ac 100644 --- a/app/Http/Controllers/AP/APActorController.php +++ b/app/Http/Controllers/AP/APActorController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\AP; use App\Models\User; use App\Models\Actor; use App\Models\Activity; +use App\Models\Follow; use Illuminate\Http\Request; use App\Http\Controllers\Controller; @@ -15,6 +16,10 @@ class APActorController extends Controller { public function user (User $user) { + if (str_contains (request ()->header ("Accept"), "text/html")) { + return redirect (route ("users.show", ["user_name" => $user->name])); + } + $actor = $user->actor ()->get (); $response = Actor::build_response ($actor->first ()); return response ()->json ($response)->header ("Content-Type", "application/activity+json"); @@ -22,8 +27,9 @@ class APActorController extends Controller public function followers (User $user) { - // TODO: Rewrite this using the follow model - $followers = Activity::where ("type", "Follow")->where ("object", $user->actor->actor_id); + $follower_ids = Follow::where ("object", $user->actor->id)->get (); + $followers = Actor::whereIn ("id", $follower_ids->pluck ("actor")->toArray ()); + $ordered_collection = new TypeOrderedCollection (); $ordered_collection->collection = $followers->get ()->pluck ("actor")->toArray (); $ordered_collection->url = route ("ap.followers", $user->name); @@ -39,8 +45,9 @@ class APActorController extends Controller public function following (User $user) { - // TODO: Rewrite this using the follow model - $following = Activity::where ("type", "Follow")->where ("actor", $user->actor->actor_id); + $following_ids = Follow::where ("actor", $user->actor->id)->get (); + $following = Actor::whereIn ("id", $following_ids->pluck ("object")->toArray ()); + $ordered_collection = new TypeOrderedCollection (); $ordered_collection->collection = $following->get ()->pluck ("object")->toArray (); $ordered_collection->url = route ("ap.following", $user->name); diff --git a/app/Http/Controllers/AP/APGeneralController.php b/app/Http/Controllers/AP/APGeneralController.php new file mode 100644 index 0000000..e7e9860 --- /dev/null +++ b/app/Http/Controllers/AP/APGeneralController.php @@ -0,0 +1,23 @@ +header ("Accept"), "text/html")) { + return redirect (route ("posts.show", ["note" => $note])); + } + + $response = TypeNote::build_response ($note); + return response ()->json ($response)->header ("Content-Type", "application/activity+json"); + } +} diff --git a/app/Http/Controllers/AP/APOutboxController.php b/app/Http/Controllers/AP/APOutboxController.php index 86a8199..1028a1d 100644 --- a/app/Http/Controllers/AP/APOutboxController.php +++ b/app/Http/Controllers/AP/APOutboxController.php @@ -95,10 +95,6 @@ class APOutboxController extends Controller { Storage::disk ("public")->delete ($processed_path); } - else - { - Log::error ("Attachment not found: " . $attachment->url . " " . $processed_path); - } $attachment->delete (); } diff --git a/app/Models/Note.php b/app/Models/Note.php index d27ad9c..f09ea67 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -11,6 +11,7 @@ class Note extends Model "actor_id", "note_id", + "private_id", "in_reply_to", "type", "summary", diff --git a/app/Types/TypeNote.php b/app/Types/TypeNote.php index 0772599..d960984 100644 --- a/app/Types/TypeNote.php +++ b/app/Types/TypeNote.php @@ -62,10 +62,13 @@ class TypeNote public static function craft_from_outbox (Actor $actor, $request) { // TODO: url should be route ('posts.show', $note->id) + $private_id = uniqid (); + $note = Note::create ([ "actor_id" => $actor->id, "summary" => $request ["summary"], - "note_id" => env ("APP_URL") . "/ap/v1/note/" . uniqid (), + "note_id" => env ("APP_URL") . "/ap/v1/note/" . $private_id, + "private_id" => $private_id, "in_reply_to" => $request ["inReplyTo"] ?? null, "type" => "Note", "summary" => $request ["summary"] ?? null, diff --git a/database/migrations/2025_01_07_000558_add_fields_to_notes_table.php b/database/migrations/2025_01_07_000558_add_fields_to_notes_table.php new file mode 100644 index 0000000..0bfa30f --- /dev/null +++ b/database/migrations/2025_01_07_000558_add_fields_to_notes_table.php @@ -0,0 +1,28 @@ +string ("private_id")->nullable (); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('notes', function (Blueprint $table) { + $table->dropColumn ("private_id"); + }); + } +}; diff --git a/resources/views/browse.blade.php b/resources/views/browse.blade.php index bc54212..e49c311 100644 --- a/resources/views/browse.blade.php +++ b/resources/views/browse.blade.php @@ -67,7 +67,9 @@ links.forEach ((link) => { const weight = parseInt (link.getAttribute ("data-weight")); - const size = Math.round ((weight / max_weight) * 210); + // set a minimum size + const min_size = 100; + const size = min_size + (weight / max_weight) * 100; link.style.fontSize = `${size}%`; }); diff --git a/routes/api.php b/routes/api.php index ba32acc..ee78b93 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\AP\APActorController; +use App\Http\Controllers\AP\APGeneralController; use App\Http\Controllers\AP\APInboxController; use App\Http\Controllers\AP\APInstanceInboxController; @@ -13,11 +14,15 @@ use App\Http\Controllers\AP\APWebfingerController; Route::get ("/.well-known/webfinger", [ APWebfingerController::class, "webfinger" ])->name ("ap.webfinger"); Route::prefix ("/ap/v1")->group (function () { + // users Route::post ("/user/{user:name}/inbox", [ APInboxController::class, "inbox" ])->name ("ap.inbox"); Route::post ("/user/{user:name}/outbox", [ APOutboxController::class, "outbox" ])->name ("ap.outbox"); Route::get ("/user/{user:name}/followers", [ APActorController::class, "followers" ])->name ("ap.followers"); Route::get ("/user/{user:name}/following", [ APActorController::class, "following" ])->name ("ap.following"); Route::get ("/user/{user:name}", [ APActorController::class, "user" ])->name ("ap.user"); + // notes + Route::get ("/note/{note:private_id}", [ APGeneralController::class, "note" ])->name ("ap.note"); + Route::post ("/inbox", [ APInstanceInboxController::class, "inbox" ])->name ("ap.inbox"); });