- Installed p7h/nas-file-manager package via private VCS repo - Published config/nas-file-manager.php with super_admin middleware restriction - Added NAS env vars to .env.example - Created admin/nas-storage page with connection info panel and file browser widget - Added NAS Storage link to admin sidebar (super_admin only) - Added SuperAdminController@nasStorage method and admin.nas-storage route - Includes all accumulated branch changes: profile wall, 2FA, audit logs, settings panel, country/phone/timezone components, posts, slideshow, playlist shares, video downloads/shares, comment likes, notifications, social links, and more Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
127 lines
3.8 KiB
PHP
127 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Post;
|
|
use App\Models\PostImage;
|
|
use App\Models\PostVideo;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class PostController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function store(Request $request, User $user)
|
|
{
|
|
if (Auth::id() !== $user->id) {
|
|
abort(403);
|
|
}
|
|
|
|
$request->validate([
|
|
'body' => 'nullable|string|max:2000',
|
|
'images' => 'nullable|array|max:10',
|
|
'images.*' => 'image|mimes:jpg,jpeg,png,webp,gif|max:8192',
|
|
'video_ids' => 'nullable|array|max:10',
|
|
'video_ids.*' => 'exists:videos,id',
|
|
// Legacy fields
|
|
'video_id' => 'nullable|exists:videos,id',
|
|
'image' => 'nullable|image|mimes:jpg,jpeg,png,webp,gif|max:8192',
|
|
]);
|
|
|
|
$hasImages = $request->hasFile('images');
|
|
$hasVideoIds = $request->filled('video_ids');
|
|
$hasLegacyImg = $request->hasFile('image');
|
|
$hasLegacyVid = $request->filled('video_id');
|
|
|
|
if (! $request->body && ! $hasImages && ! $hasLegacyImg && ! $hasVideoIds && ! $hasLegacyVid) {
|
|
return back()->withErrors(['body' => 'Post cannot be empty.']);
|
|
}
|
|
|
|
$data = [
|
|
'user_id' => $user->id,
|
|
'body' => $request->body,
|
|
'video_id' => $request->video_id ?? null,
|
|
];
|
|
|
|
// Legacy single image (backward compat)
|
|
if ($hasLegacyImg) {
|
|
$filename = uniqid('post_', true) . '.' . $request->file('image')->getClientOriginalExtension();
|
|
$request->file('image')->storeAs('public/post_images', $filename);
|
|
$data['image'] = $filename;
|
|
}
|
|
|
|
$post = Post::create($data);
|
|
|
|
// New multi-image
|
|
if ($hasImages) {
|
|
foreach ($request->file('images') as $idx => $file) {
|
|
$filename = uniqid('post_', true) . '.' . $file->getClientOriginalExtension();
|
|
$file->storeAs('public/post_images', $filename);
|
|
PostImage::create([
|
|
'post_id' => $post->id,
|
|
'filename' => $filename,
|
|
'sort_order' => $idx,
|
|
]);
|
|
}
|
|
}
|
|
|
|
// New multi-video
|
|
if ($hasVideoIds) {
|
|
foreach ($request->input('video_ids') as $idx => $videoId) {
|
|
PostVideo::create([
|
|
'post_id' => $post->id,
|
|
'video_id' => $videoId,
|
|
'sort_order' => $idx,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return back()->with('toast_success', 'Post shared!');
|
|
}
|
|
|
|
public function destroy(Post $post)
|
|
{
|
|
if (Auth::id() !== $post->user_id && ! Auth::user()->isAdmin()) {
|
|
abort(403);
|
|
}
|
|
|
|
if ($post->image) {
|
|
Storage::delete('public/post_images/' . $post->image);
|
|
}
|
|
|
|
// Delete multi-image files
|
|
foreach ($post->postImages as $postImage) {
|
|
Storage::delete('public/post_images/' . $postImage->filename);
|
|
}
|
|
|
|
$post->delete();
|
|
|
|
return back()->with('toast_success', 'Post deleted.');
|
|
}
|
|
|
|
public function react(Post $post)
|
|
{
|
|
$user = Auth::user();
|
|
$existing = $post->reactions()->where('user_id', $user->id)->first();
|
|
|
|
if ($existing) {
|
|
$existing->delete();
|
|
$liked = false;
|
|
} else {
|
|
$post->reactions()->create(['user_id' => $user->id, 'type' => 'like']);
|
|
$liked = true;
|
|
}
|
|
|
|
return response()->json([
|
|
'liked' => $liked,
|
|
'count' => $post->reactions()->count(),
|
|
]);
|
|
}
|
|
}
|