Upload beautify
This commit is contained in:
@@ -4,64 +4,15 @@ namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Support\AvatarUrl;
|
||||
|
||||
class AvatarController extends Controller
|
||||
{
|
||||
public function show(Request $request, $id, $name = null)
|
||||
{
|
||||
$user_id = (int) $id;
|
||||
$userId = (int) $id;
|
||||
$target = AvatarUrl::forUser($userId, null, 128);
|
||||
|
||||
// default avatar in project public gfx
|
||||
$defaultAvatar = public_path('gfx/avatar.jpg');
|
||||
|
||||
try {
|
||||
$icon = DB::table('users')->where('user_id', $user_id)->value('icon');
|
||||
} catch (\Throwable $e) {
|
||||
$icon = null;
|
||||
}
|
||||
|
||||
$candidates = [];
|
||||
if (!empty($icon)) {
|
||||
// common legacy locations to check
|
||||
$candidates[] = base_path('oldSite/www/files/usericons/' . $icon);
|
||||
$candidates[] = base_path('oldSite/www/files/usericons/' . rawurlencode($icon));
|
||||
$candidates[] = base_path('oldSite/www/files/usericons/' . basename($icon));
|
||||
$candidates[] = public_path('avatar/' . $user_id . '/' . $icon);
|
||||
$candidates[] = public_path('avatar/' . $user_id . '/' . basename($icon));
|
||||
$candidates[] = storage_path('app/public/usericons/' . $icon);
|
||||
$candidates[] = storage_path('app/public/usericons/' . basename($icon));
|
||||
}
|
||||
|
||||
// find first readable file
|
||||
$found = null;
|
||||
foreach ($candidates as $path) {
|
||||
if ($path && file_exists($path) && is_readable($path)) {
|
||||
$found = $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
$type = @exif_imagetype($found);
|
||||
if ($type) {
|
||||
$mime = image_type_to_mime_type($type);
|
||||
} else {
|
||||
$f = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$mime = finfo_file($f, $found) ?: 'application/octet-stream';
|
||||
finfo_close($f);
|
||||
}
|
||||
|
||||
return response()->file($found, ['Content-Type' => $mime]);
|
||||
}
|
||||
|
||||
// fallback to default
|
||||
if (file_exists($defaultAvatar) && is_readable($defaultAvatar)) {
|
||||
return response()->file($defaultAvatar, ['Content-Type' => 'image/jpeg']);
|
||||
}
|
||||
|
||||
// final fallback: 404
|
||||
abort(404);
|
||||
return redirect()->away($target, 301);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class BuddiesController extends Controller
|
||||
->leftJoin('users as t2', 't1.user_id', '=', 't2.id')
|
||||
->leftJoin('user_profiles as p', 'p.user_id', '=', 't2.id')
|
||||
->where('t1.friend_id', $user->id)
|
||||
->select('t1.id', 't1.user_id', 't1.friend_id', 't2.name as uname', 'p.avatar as icon', 't1.date_added')
|
||||
->select('t1.id', 't1.user_id', 't1.friend_id', 't2.name as uname', 'p.avatar_hash as icon', 't1.date_added')
|
||||
->orderByDesc('t1.date_added');
|
||||
|
||||
$followers = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
||||
use App\Models\ArtworkComment;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LatestCommentsController extends Controller
|
||||
{
|
||||
@@ -36,7 +37,7 @@ class LatestCommentsController extends Controller
|
||||
'comment_description' => $c->content,
|
||||
'commenter_id' => $c->user_id,
|
||||
'country' => $user->country ?? null,
|
||||
'icon' => $user->avatar ?? null,
|
||||
'icon' => $user ? DB::table('user_profiles')->where('user_id', $user->id)->value('avatar_hash') : null,
|
||||
'uname' => $user->username ?? $user->name ?? 'User',
|
||||
'signature' => $user->signature ?? null,
|
||||
'user_type' => $user->role ?? null,
|
||||
|
||||
@@ -23,7 +23,7 @@ class MyBuddiesController extends Controller
|
||||
->leftJoin('users as t2', 't1.friend_id', '=', 't2.id')
|
||||
->leftJoin('user_profiles as p', 'p.user_id', '=', 't2.id')
|
||||
->where('t1.user_id', $user->id)
|
||||
->select('t1.id', 't1.friend_id', 't1.user_id', 't2.name as uname', 'p.avatar as icon', 't1.date_added')
|
||||
->select('t1.id', 't1.friend_id', 't1.user_id', 't2.name as uname', 'p.avatar_hash as icon', 't1.date_added')
|
||||
->orderByDesc('t1.date_added');
|
||||
|
||||
$buddies = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Models\User;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
@@ -63,7 +64,7 @@ class ProfileController extends Controller
|
||||
'user_id' => $user->id,
|
||||
'uname' => $user->name,
|
||||
'real_name' => $user->name,
|
||||
'icon' => $user->avatar ?? null,
|
||||
'icon' => DB::table('user_profiles')->where('user_id', $user->id)->value('avatar_hash'),
|
||||
'about_me' => $user->bio ?? null,
|
||||
];
|
||||
|
||||
|
||||
@@ -4,11 +4,10 @@ namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Models\User;
|
||||
use App\Services\AvatarService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class UserController extends Controller
|
||||
@@ -72,12 +71,12 @@ class UserController extends Controller
|
||||
|
||||
// Files: avatar/photo/emoticon
|
||||
if ($request->hasFile('avatar')) {
|
||||
$f = $request->file('avatar');
|
||||
$name = $user->id . '.' . $f->getClientOriginalExtension();
|
||||
$f->move(public_path('avatar'), $name);
|
||||
// store filename in profile avatar (legacy field) — modern avatar pipeline will later migrate
|
||||
$profileUpdates['avatar'] = $name;
|
||||
$user->icon = $name;
|
||||
try {
|
||||
$hash = app(AvatarService::class)->storeFromUploadedFile((int) $user->id, $request->file('avatar'));
|
||||
$user->icon = $hash;
|
||||
} catch (\Throwable $e) {
|
||||
$request->session()->flash('error', 'Avatar upload failed.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->hasFile('personal_picture')) {
|
||||
@@ -141,7 +140,7 @@ class UserController extends Controller
|
||||
if (isset($profile->birthdate)) $user->birth = $profile->birthdate;
|
||||
if (isset($profile->gender)) $user->gender = $profile->gender;
|
||||
if (isset($profile->country_code)) $user->country_code = $profile->country_code;
|
||||
if (isset($profile->avatar)) $user->icon = $profile->avatar;
|
||||
if (isset($profile->avatar_hash)) $user->icon = $profile->avatar_hash;
|
||||
if (isset($profile->cover_image)) $user->picture = $profile->cover_image;
|
||||
if (isset($profile->signature)) $user->signature = $profile->signature;
|
||||
if (isset($profile->description)) $user->description = $profile->description;
|
||||
|
||||
Reference in New Issue
Block a user