fix: deep link
This commit is contained in:
@@ -132,15 +132,24 @@ public function show($id)
|
||||
return response()->json($category);
|
||||
}
|
||||
|
||||
// Public (no auth) deep link lookup by ID. Hidden (deeplink-only) categories
|
||||
// are the only ones served here, since they are discovered via the deep link.
|
||||
// Public (no auth) deep link lookup by ID. Serves any category — hidden
|
||||
// (deeplink-only) ones included — so https://aramejan.com/category/{id}
|
||||
// resolves for every shareable category. A visible category only lists its
|
||||
// visible media; inside a hidden category everything is shown, since the
|
||||
// deep link is the only way in.
|
||||
public function publicShow($id)
|
||||
{
|
||||
$category = Category::with(['subcategories' => function ($q) {
|
||||
$q->orderBy('name')->with(['media' => function ($m) {
|
||||
$category = Category::findOrFail($id);
|
||||
$includeHiddenMedia = (bool) $category->is_deeplink_only;
|
||||
|
||||
$category->load(['subcategories' => function ($q) use ($includeHiddenMedia) {
|
||||
$q->orderBy('name')->with(['media' => function ($m) use ($includeHiddenMedia) {
|
||||
if (! $includeHiddenMedia) {
|
||||
$m->where('is_deeplink_only', false);
|
||||
}
|
||||
$m->with(['image', 'detailImage', 'tags'])->latest();
|
||||
}]);
|
||||
}])->where('id', $id)->where('is_deeplink_only', true)->firstOrFail();
|
||||
}]);
|
||||
|
||||
return response()->json([
|
||||
'category' => [
|
||||
@@ -169,7 +178,9 @@ public function grouped($id)
|
||||
{
|
||||
$category = Category::with(['subcategories' => function ($q) {
|
||||
$q->orderBy('name')->with(['media' => function ($m) {
|
||||
$m->with(['image', 'detailImage', 'tags'])->latest();
|
||||
// Deep-link-only media stays out of the normal category screen.
|
||||
$m->where('is_deeplink_only', false)
|
||||
->with(['image', 'detailImage', 'tags'])->latest();
|
||||
}]);
|
||||
}])->findOrFail($id);
|
||||
|
||||
|
||||
@@ -99,6 +99,11 @@ public function index(Request $request)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
// Same external_url fallback as the normal listing below.
|
||||
$hidden->each(function ($m) {
|
||||
$m->external_url = $m->external_url ?: ($m->url ?? '');
|
||||
});
|
||||
|
||||
return response()->json($hidden);
|
||||
}
|
||||
|
||||
@@ -491,8 +496,9 @@ public function show($id)
|
||||
}
|
||||
|
||||
// Public (no auth) deep link lookup by ID. Returns the same shape as show()
|
||||
// minus the user-specific fields. Hidden (deeplink-only) media is included,
|
||||
// since the deep link is how such media is discovered.
|
||||
// minus the user-specific fields. Serves any publicly visible media plus the
|
||||
// hidden (deeplink-only) ones, since the deep link is how those are discovered
|
||||
// — https://aramejan.com/media/{id} must resolve for every shareable media.
|
||||
public function publicShow($id)
|
||||
{
|
||||
$media = Media::with([
|
||||
@@ -506,7 +512,10 @@ public function publicShow($id)
|
||||
},
|
||||
])
|
||||
->where('id', $id)
|
||||
->where('is_deeplink_only', true)
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('is_deeplink_only', true);
|
||||
})
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -9,7 +9,7 @@ class SubCategoryController extends Controller
|
||||
{
|
||||
public function index(Request $request, $categoryId = null)
|
||||
{
|
||||
$query = SubCategory::with('category')->withCount('media');
|
||||
$query = SubCategory::with('category')->withCount(['media' => fn ($q) => $q->where('is_deeplink_only', false)]);
|
||||
|
||||
$categoryId = $categoryId ?? $request->input('category_id');
|
||||
|
||||
@@ -51,7 +51,7 @@ public function store(Request $request)
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$subCategory = SubCategory::with('category')->withCount('media')->findOrFail($id);
|
||||
$subCategory = SubCategory::with('category')->withCount(['media' => fn ($q) => $q->where('is_deeplink_only', false)])->findOrFail($id);
|
||||
|
||||
return response()->json($subCategory);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user