fix: added og headers, lots of cleanup.

This commit is contained in:
2023-12-20 01:02:15 +00:00
parent 7772be7dc5
commit f7a27e7f62
17 changed files with 817 additions and 62 deletions

View File

@@ -12,6 +12,7 @@ use Illuminate\Validation\Rules\File;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Cache;
@@ -28,11 +29,13 @@ class ArtworkController extends Controller
{
$user = auth()->user();
$artworks = Artwork::whereNotNull('approved_by')
->join('episodes', 'artworks.episode_id', '=', 'episodes.id')
->select('artworks.*', DB::raw('episodes.episode_number episode_number'))
->with('artist')
->with('podcast')
->with('episode')
->orderBy('episode_id', 'desc')
->orderBy('created_at', 'desc')
->orderBy('episode_number', 'desc')
->orderBy('artworks.created_at', 'desc')
->paginate($perPage = 52, $columns = ['*'], $pageName = 'artworks');
$podcasts = Cache::remember('publishedPodcasts', 30, function() {
return Podcast::where('published', true)->get();
@@ -107,6 +110,8 @@ class ArtworkController extends Controller
'podcast_id' => $podcast->id,
'episode_id' => $episode->id,
'filename' => $filename,
'created_at' => now(),
'updated_at' => now(),
])->create();
$img = Image::make($rawFile)->resize(3000, null, function($constraint){
$constraint->aspectRatio();
@@ -138,6 +143,12 @@ class ArtworkController extends Controller
->with('episode')
->with('artist')
->first();
if (is_null($artwork->approved_by) && $user && $user->id != $artwork->id) {
return redirect('artworks');
}
if (is_null($artwork->approved_by) && !$user) {
return redirect('artworks');
}
return view('artworks.artwork', [
'artwork' => $artwork,
'user' => $user,
@@ -194,4 +205,26 @@ class ArtworkController extends Controller
dd($request->path());
//$artwork = Artwork::where('legacy_filename', '/assets/artwork/')
}
public function downloadArchiveList(Request $request, $type = 'sd')
{
$artworks = Artwork::whereNotNull('approved_by')
->orderBy('created_at', 'desc')
->pluck('filename');
$output = '';
if ($type == 'sd') {
foreach($artworks as $artwork) {
$output .= '"https://static.noagendaartgenerator.com/thumbnails/' . $artwork . '"' . "\r\n";
}
} else {
foreach($artworks as $artwork) {
$output .= '"https://static.noagendaartgenerator.com/artworks/' . $artwork . '"' . "\r\n";
}
}
return response($output, 200)
->header('Content-type', 'text/plain')
->header('Content-Length', strlen($output))
->header('Content-Disposition', 'attachment; filename="naartgen-archivelist-' . $type . '.txt"');
}
}

View File

@@ -18,8 +18,7 @@ class PageController extends Controller
$headerCounters = $this->getHeaderCounters();
$recentEpisodes = $this->mostRecentEpisodes();
$recentSubmissions = $this->mostRecentSubmissions();
$leaderboard = $this->leaderboardTwelveMonths();
$leaderboard = $this->leaderboardTwelveMonthsLanding();
return view('home.page', [
'user' => $user,
'pageTitle' => 'Home',
@@ -31,6 +30,31 @@ class PageController extends Controller
]);
}
public function leaderboards(Request $request)
{
$user = auth()->user();
return view('leaderboards.leaderboards', [
'user' => $user,
'leaderboardAllTime' => $this->leaderboardAllTime(),
'leaderboardPastTwelveMonths' => $this->leaderboardTwelveMonths(),
'leaderboardRollingSixMonths' => $this->leaderboardRollingSixMonths(),
'leaderboardRollingNinetyDays' => $this->leaderboardRollingNinetyDays(),
]);
}
public function support(Request $request)
{
return view('home.support.page', [
'user' => auth()->user(),
'pageTitle' => 'History and Support',
'headerCounters' => $this->getHeaderCounters(),
'recentEpisodes' => $this->mostRecentEpisodes(),
'recentSubmissions' => $this->mostRecentSubmissions(),
'leaderboard' => $this->leaderboardTwelveMonthsLanding(),
'preferredTheme' => $request->session()->get('preferred_theme') ?? 'dark',
]);
}
private function mostRecentSubmissions() {
$artworks = Cache::remember('latestSubmissions', 30, function() {
return Artwork::whereNotNull('approved_by')
@@ -52,7 +76,7 @@ class PageController extends Controller
->with('podcast')
->with('artwork')
->with('artwork.artist')
->orderBy('episode_date', 'desc')
->orderBy('episode_number', 'desc')
->limit(5)
->get();
});
@@ -101,6 +125,29 @@ class PageController extends Controller
private function leaderboardTwelveMonths() {
$leaderboard = cache()->remember('leaderboardTwelveMonths', 30, function() {
$endDate = now()->endOfDay()->subYear()->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->where('episodes.episode_date', '>=', $endDate)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(50)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function leaderboardTwelveMonthsLanding() {
$leaderboard = cache()->remember('leaderboardTwelveMonthsLanding', 30, function() {
$endDate = now()->endOfDay()->subYear()->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
@@ -122,6 +169,73 @@ class PageController extends Controller
return $leaderboard;
}
private function leaderboardAllTime() {
$leaderboard = cache()->remember('leaderboardAllTime', 30, function() {
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(100)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function leaderboardRollingSixMonths() {
$leaderboard = cache()->remember('leaderboardRollingSixMonth', 30, function() {
$endDate = now()->endOfDay()->subMonths(6)->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->where('episodes.episode_date', '>=', $endDate)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(50)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function leaderboardRollingNinetyDays() {
$leaderboard = cache()->remember('leaderboardNinetyDays', 30, function() {
$endDate = now()->endOfDay()->subDays(90)->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->where('episodes.episode_date', '>=', $endDate)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(50)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function addArtistModelToLeaderboard($leaderboard) {
$artistIds = [];
foreach ($leaderboard as $lb) {