feat: deep link added
This commit is contained in:
@@ -37,6 +37,7 @@ public function store(Request $request)
|
||||
'file' => 'nullable|file|extensions:mp3,wav,ogg,flac,aac,m4a,opus,mpga,wma,mp4,mov,m4v,webm,mkv,avi,3gp|max:512000',
|
||||
'external_url' => 'nullable|string',
|
||||
'visibility' => 'nullable|in:public,private',
|
||||
'is_deeplink_only' => 'nullable|boolean',
|
||||
|
||||
'tags' => 'nullable|array',
|
||||
'tags.*' => 'string',
|
||||
@@ -66,7 +67,8 @@ public function store(Request $request)
|
||||
'detail_image_id' => $detailImageId,
|
||||
'duration' => $data['duration'] ?? null,
|
||||
'visibility' => $data['visibility'] ?? 'public',
|
||||
'is_premium'=> $data['is_premium'] ?? false
|
||||
'is_premium'=> $data['is_premium'] ?? false,
|
||||
'is_deeplink_only' => $data['is_deeplink_only'] ?? false
|
||||
]);
|
||||
|
||||
$media->categories()->sync($data['category_ids'] ?? []);
|
||||
@@ -89,11 +91,23 @@ public function store(Request $request)
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Admin listing of deep-link (hidden) media: ?deeplink_only=1 returns only
|
||||
// the hidden records so the admin can manage their share links.
|
||||
if ($request->boolean('deeplink_only')) {
|
||||
$hidden = Media::with(['image', 'detailImage', 'categories', 'subCategories', 'tags'])
|
||||
->where('is_deeplink_only', true)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
return response()->json($hidden);
|
||||
}
|
||||
|
||||
$query = Media::with(['image', 'detailImage', 'categories', 'subCategories', 'myNote', 'tags','comments'])
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
});
|
||||
})
|
||||
->where('is_deeplink_only', false);
|
||||
|
||||
$this->applyMediaFilters($query, $request);
|
||||
|
||||
@@ -213,6 +227,7 @@ public function newest(Request $request)
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
})
|
||||
->where('is_deeplink_only', false)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($perPage);
|
||||
|
||||
@@ -298,7 +313,8 @@ public function filters(Request $request)
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
});
|
||||
})
|
||||
->where('is_deeplink_only', false);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -310,7 +326,7 @@ public function filters(Request $request)
|
||||
$q->where(function ($inner) {
|
||||
$inner->where('media.visibility', 'public')
|
||||
->orWhere('media.user_id', auth()->id());
|
||||
});
|
||||
})->where('media.is_deeplink_only', false);
|
||||
};
|
||||
|
||||
$categories = Category::query()
|
||||
@@ -354,6 +370,7 @@ public function filters(Request $request)
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
})
|
||||
->where('is_deeplink_only', false)
|
||||
->groupBy('duration_range')
|
||||
->pluck('total', 'duration_range');
|
||||
|
||||
@@ -381,7 +398,8 @@ public function search(Request $request)
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
});
|
||||
})
|
||||
->where('is_deeplink_only', false);
|
||||
|
||||
$this->applyMediaFilters($query, $request);
|
||||
|
||||
@@ -412,7 +430,8 @@ public function show($id)
|
||||
->where('id', $id)
|
||||
->where(function($query) {
|
||||
$query->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
->orWhere('user_id', auth()->id())
|
||||
->orWhere('is_deeplink_only', true);
|
||||
})
|
||||
->firstOrFail();
|
||||
|
||||
@@ -471,6 +490,56 @@ 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.
|
||||
public function publicShow($id)
|
||||
{
|
||||
$media = Media::with([
|
||||
'image',
|
||||
'detailImage',
|
||||
'categories',
|
||||
'subCategories',
|
||||
'tags',
|
||||
'comments' => function($query) {
|
||||
$query->with('user')->latest()->limit(10);
|
||||
},
|
||||
])
|
||||
->where('id', $id)
|
||||
->where('is_deeplink_only', true)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json([
|
||||
'id' => $media->id,
|
||||
'title' => $media->title,
|
||||
'caption' => $media->caption,
|
||||
'type' => $media->type,
|
||||
'file_path' => $media->file_path,
|
||||
'external_url' => $media->external_url,
|
||||
'duration' => $media->duration,
|
||||
'visibility' => $media->visibility,
|
||||
'is_premium' => $media->is_premium,
|
||||
'is_deeplink_only' => $media->is_deeplink_only,
|
||||
'deep_link' => $media->deep_link,
|
||||
'created_at' => $media->created_at,
|
||||
'updated_at' => $media->updated_at,
|
||||
'image' => $media->image,
|
||||
'detail_image' => $media->detailImage,
|
||||
'categories' => $media->categories,
|
||||
'sub_categories' => $media->subCategories,
|
||||
'tags' => $media->tags,
|
||||
'comments' => $media->comments,
|
||||
'statistics' => [
|
||||
'average_rating' => $media->average_rating,
|
||||
'total_ratings' => $media->ratings_count,
|
||||
'total_comments' => $media->comments_count,
|
||||
'total_likes' => $media->likes_count,
|
||||
'total_saves' => $media->saved_count,
|
||||
'rating_distribution' => $media->rating_distribution,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// Media that shares categories / subcategories / tags with the given one,
|
||||
// ranked by how much they overlap. Excludes the media itself.
|
||||
private function similarMedia(Media $media, int $limit = 5)
|
||||
@@ -488,6 +557,7 @@ private function similarMedia(Media $media, int $limit = 5)
|
||||
return Media::query()
|
||||
->where('media.id', '!=', $media->id)
|
||||
->where('media.type', $media->type)
|
||||
->where('media.is_deeplink_only', false)
|
||||
->where(function ($q) use ($userId) {
|
||||
$q->where('visibility', 'public')->orWhere('user_id', $userId);
|
||||
})
|
||||
@@ -593,6 +663,7 @@ public function update(Request $request, $id)
|
||||
'file' => 'nullable|file|extensions:mp3,wav,ogg,flac,aac,m4a,opus,mpga,wma,mp4,mov,m4v,webm,mkv,avi,3gp|max:512000',
|
||||
'external_url' => 'nullable|string',
|
||||
'visibility' => 'nullable|in:public,private',
|
||||
'is_deeplink_only' => 'nullable|boolean',
|
||||
'tags' => 'nullable|array',
|
||||
'tags.*' => 'string',
|
||||
]);
|
||||
@@ -616,6 +687,7 @@ public function update(Request $request, $id)
|
||||
'duration' => $data['duration'] ?? $media->duration,
|
||||
'external_url' => $data['external_url'] ?? $media->external_url,
|
||||
'visibility' => $data['visibility'] ?? $media->visibility,
|
||||
'is_deeplink_only' => array_key_exists('is_deeplink_only', $data) ? $data['is_deeplink_only'] : $media->is_deeplink_only,
|
||||
'file_path' => $data['file_path'] ?? $media->file_path,
|
||||
];
|
||||
|
||||
@@ -741,6 +813,7 @@ public function popular(Request $request)
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')->orWhere('user_id', auth()->id());
|
||||
})
|
||||
->where('is_deeplink_only', false)
|
||||
->withCount('plays as listeners_count') // distinct users who played
|
||||
->withSum('plays as plays_count', 'play_count') // total plays
|
||||
->with(['image', 'detailImage', 'categories', 'subCategories', 'tags'])
|
||||
@@ -760,7 +833,7 @@ public function recentlyPlayed(Request $request)
|
||||
|
||||
$plays = MediaPlay::where('user_id', auth()->id())
|
||||
->whereNotNull('last_played_at')
|
||||
->with(['media' => fn ($q) => $q->with(['image', 'detailImage', 'categories', 'subCategories', 'tags'])])
|
||||
->with(['media' => fn ($q) => $q->where('is_deeplink_only', false)->with(['image', 'detailImage', 'categories', 'subCategories', 'tags'])])
|
||||
->orderByDesc('last_played_at')
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
Reference in New Issue
Block a user