added support for profile song

This commit is contained in:
Ghostie 2025-01-08 19:06:55 -05:00
parent 248fbc14e8
commit a9a22984d2
6 changed files with 71 additions and 9 deletions

View File

@ -373,7 +373,7 @@ class APOutboxController extends Controller
$note->activity_id = $create_activity->id;
$note->save ();
$response = TypeActivity::post_to_instances ($create_activity, $actor);
$response = TypeActivity::post_to_instances ($create_activity, $actor, true);
return response ()->json ("success", 200);
}
}

View File

@ -55,6 +55,7 @@ class ProfileController extends Controller
$incoming_fields = $request->validate ([
"avatar" => "image|max:4096",
"song" => "file|mimes:audio/mpeg,mp3|max:1024",
"bio" => "sometimes|nullable|string",
"about_you" => "sometimes|nullable|string",
"status" => "sometimes|nullable|string",
@ -69,24 +70,38 @@ class ProfileController extends Controller
]);
$user = auth ()->user ();
$fname = $user->id . "-" . uniqid () . ".jpg";
$fname = $user->id . "-" . uniqid ();
$changing_avatar = false;
$changing_song = false;
$old_avatar = null;
$old_song = null;
if (isset ($incoming_fields["avatar"]) && !empty ($incoming_fields["avatar"]))
{
$manager = new ImageManager (new Driver ());
$image = $manager->read ($request->file ("avatar"));
$image_data = $image->cover (256, 256)->toJpeg ();
Storage::disk ("public")->put ("avatars/" . $fname, $image_data);
Storage::disk ("public")->put ("avatars/" . $fname . ".jpg", $image_data);
$old_avatar = $user->avatar;
$user->avatar = $fname;
$user->avatar = $fname . ".jpg";
$user->actor->icon = env ("APP_URL") . $user->avatar;
$changing_avatar = true;
}
if (isset ($incoming_fields["song"]) && !empty ($incoming_fields["song"]))
{
$file = $request->file ("song");
Storage::disk ("public")->put ("songs/" . $fname . ".mp3", file_get_contents ($file));
$old_song = $user->profile_song;
$user->profile_song = $fname . ".mp3";
$changing_song = true;
}
$user->bio = $incoming_fields["bio"];
$user->about_you = $incoming_fields["about_you"];
$user->status = $incoming_fields["status"];
@ -106,9 +121,10 @@ class ProfileController extends Controller
$user->actor->save ();
if ($changing_avatar)
{
Storage::disk ("public")->delete (str_replace ("/storage/", "", $old_avatar));
}
if ($changing_song)
Storage::disk ("public")->delete (str_replace ("/storage/", "", $old_song));
$response = ActionsUser::update_profile ();
if (isset ($response["error"]))

View File

@ -42,7 +42,10 @@ class User extends Authenticatable
"interests_books",
"interests_heroes",
"blurbs"
"blurbs",
"profile_song",
"notification_sound"
];
/**

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string ("profile_song")->nullable ();
$table->string ("notification_sound")->nullable ();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn ("profile_song");
$table->dropColumn ("notification_sound");
});
}
};

View File

@ -30,6 +30,13 @@
<p class="error">{{ $message }}</p>
@enderror
<small>Max file size: 4MB (jpg/png/gif)</small>
<br><br>
<small>Select song:</small>
<input type="file" name="song" accept="audio/*"><br>
@error("song")
<p class="error">{{ $message }}</p>
@enderror
<small>Max file size: 1MB</small>
<br>
<h1>Bio:</h1>
<br>

View File

@ -35,12 +35,18 @@
@endif
<p><b>Joined: </b> {{ $user->created_at->diffForHumans () }}</p>
</div>
<audio src="{{ $user->profile_song ? '/storage/songs/' . $user->profile_song : '#' }}" id="music" autoplay loop controls></audio>
<script>
let music = document.getElementById ('music');
music.volume = 0.1;
music.play ()
</script>
@endif
</div>
<audio src="#" id="music" autoplay loop controls></audio>
<div class="mood">
@if ($user != null)
<p><b>Mood:</b> {{ $user->mood }}</p>