mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Hide private videos from non-owners
This commit is contained in:
1 parent
45749f1977
commit
d53ce6742a
3 files changed
+76
-15
No files matched your search
+36
-2
@@ -1689,6 +1689,17 @@ function renderChannelVideosFromList({
|
||||
? app.getUnsupportedBtihMessage()
|
||||
: "This magnet link is missing a compatible BitTorrent v1 info hash.";
|
||||
|
||||
const fallbackNormalizePubkey = (value) =>
|
||||
typeof value === "string" && value
|
||||
? value.trim().toLowerCase()
|
||||
: "";
|
||||
const normalizePubkey =
|
||||
typeof app?.normalizeHexPubkey === "function"
|
||||
? (value) => app.normalizeHexPubkey(value) || fallbackNormalizePubkey(value)
|
||||
: fallbackNormalizePubkey;
|
||||
const normalizedViewerPubkey = normalizePubkey(app?.pubkey);
|
||||
let renderIndex = 0;
|
||||
|
||||
const extractPlaybackDetail = (trigger, video) => {
|
||||
if (
|
||||
app?.videoListView &&
|
||||
@@ -1768,10 +1779,24 @@ function renderChannelVideosFromList({
|
||||
}
|
||||
};
|
||||
|
||||
videos.forEach((video, index) => {
|
||||
videos.forEach((video) => {
|
||||
if (!video || !video.id || !video.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedVideoPubkey = normalizePubkey(video.pubkey);
|
||||
const canEdit =
|
||||
Boolean(normalizedVideoPubkey) &&
|
||||
Boolean(normalizedViewerPubkey) &&
|
||||
normalizedVideoPubkey === normalizedViewerPubkey;
|
||||
|
||||
if (video.isPrivate && !canEdit) {
|
||||
return;
|
||||
}
|
||||
|
||||
app?.videosMap?.set(video.id, video);
|
||||
|
||||
const canEdit = video.pubkey === app?.pubkey;
|
||||
const index = renderIndex++;
|
||||
let hasOlder = false;
|
||||
if (canEdit && video.videoRootId) {
|
||||
hasOlder = app?.hasOlderVersion?.(video, allKnownEventsArray) || false;
|
||||
@@ -1882,6 +1907,15 @@ function renderChannelVideosFromList({
|
||||
}
|
||||
});
|
||||
|
||||
if (renderIndex === 0) {
|
||||
if (allowEmptyMessage) {
|
||||
container.dataset.hasChannelVideos = "false";
|
||||
container.innerHTML = `<p class="text-gray-500">No videos to display.</p>`;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
container.appendChild(fragment);
|
||||
|
||||
attachHealthBadges(container);
|
||||
|
||||
@@ -80,6 +80,15 @@ function ensureSet(value) {
|
||||
return new Set();
|
||||
}
|
||||
|
||||
function normalizeHexPubkey(pubkey) {
|
||||
if (typeof pubkey !== "string") {
|
||||
return "";
|
||||
}
|
||||
|
||||
const trimmed = pubkey.trim();
|
||||
return trimmed ? trimmed.toLowerCase() : "";
|
||||
}
|
||||
|
||||
function normalizeUntil(timestamp) {
|
||||
const value = Number(timestamp);
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
@@ -197,6 +206,21 @@ export class NostrService {
|
||||
}
|
||||
}
|
||||
|
||||
if (video.isPrivate === true) {
|
||||
const normalizedVideoPubkey = normalizeHexPubkey(video.pubkey);
|
||||
const normalizedViewerPubkey = normalizeHexPubkey(
|
||||
this.nostrClient?.pubkey
|
||||
);
|
||||
|
||||
if (
|
||||
!normalizedViewerPubkey ||
|
||||
!normalizedVideoPubkey ||
|
||||
normalizedVideoPubkey !== normalizedViewerPubkey
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.accessControl && typeof this.accessControl.canAccess === "function") {
|
||||
try {
|
||||
if (!this.accessControl.canAccess(video)) {
|
||||
|
||||
@@ -254,28 +254,31 @@ export class VideoListView {
|
||||
|
||||
const source = Array.isArray(videos) ? videos : [];
|
||||
const dedupedVideos = this.utils.dedupeVideos(source);
|
||||
this.currentVideos = dedupedVideos.slice();
|
||||
const displayVideos = dedupedVideos.filter(
|
||||
(video) => this.utils.canEditVideo(video) || !video?.isPrivate
|
||||
);
|
||||
|
||||
this.syncViewCountSubscriptions(dedupedVideos);
|
||||
this.cleanupThumbnailCache(dedupedVideos);
|
||||
this.syncViewCountSubscriptions(displayVideos);
|
||||
this.cleanupThumbnailCache(displayVideos);
|
||||
|
||||
if (!dedupedVideos.length) {
|
||||
if (!displayVideos.length) {
|
||||
this.renderedVideoIds.clear();
|
||||
this.videoCardInstances = [];
|
||||
if (this.lastRenderedVideoSignature === EMPTY_VIDEO_LIST_SIGNATURE) {
|
||||
return dedupedVideos;
|
||||
return displayVideos;
|
||||
}
|
||||
this.lastRenderedVideoSignature = EMPTY_VIDEO_LIST_SIGNATURE;
|
||||
this.container.innerHTML = `
|
||||
<p class="flex justify-center items-center h-full w-full text-center text-gray-500">
|
||||
No public videos available yet. Be the first to upload one!
|
||||
</p>`;
|
||||
return dedupedVideos;
|
||||
return displayVideos;
|
||||
}
|
||||
|
||||
dedupedVideos.sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0));
|
||||
displayVideos.sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0));
|
||||
this.currentVideos = displayVideos.slice();
|
||||
|
||||
const signaturePayload = dedupedVideos.map((video) => ({
|
||||
const signaturePayload = displayVideos.map((video) => ({
|
||||
id: typeof video?.id === "string" ? video.id : "",
|
||||
createdAt: Number.isFinite(video?.created_at)
|
||||
? video.created_at
|
||||
@@ -290,7 +293,7 @@ export class VideoListView {
|
||||
const signature = JSON.stringify(signaturePayload);
|
||||
|
||||
if (signature === this.lastRenderedVideoSignature) {
|
||||
return dedupedVideos;
|
||||
return displayVideos;
|
||||
}
|
||||
this.lastRenderedVideoSignature = signature;
|
||||
|
||||
@@ -300,7 +303,7 @@ export class VideoListView {
|
||||
const allEvents = this.utils.getAllEvents();
|
||||
const fragment = this.document?.createDocumentFragment?.();
|
||||
if (!fragment) {
|
||||
return dedupedVideos;
|
||||
return displayVideos;
|
||||
}
|
||||
|
||||
const authorSet = new Set();
|
||||
@@ -308,7 +311,7 @@ export class VideoListView {
|
||||
const canManageBlacklist = this.utils.canManageBlacklist();
|
||||
this.videoCardInstances = [];
|
||||
|
||||
dedupedVideos.forEach((video, index) => {
|
||||
displayVideos.forEach((video, index) => {
|
||||
if (!video || !video.id || !video.title) {
|
||||
return;
|
||||
}
|
||||
@@ -457,10 +460,10 @@ export class VideoListView {
|
||||
if (authorSet.size) {
|
||||
this.utils.batchFetchProfiles(authorSet);
|
||||
}
|
||||
this.utils.refreshDiscussionCounts(dedupedVideos);
|
||||
this.utils.refreshDiscussionCounts(displayVideos);
|
||||
this.pruneDetachedViewCountElements();
|
||||
|
||||
return dedupedVideos;
|
||||
return displayVideos;
|
||||
}
|
||||
|
||||
updateVideo(videoId, patch) {
|
||||
|
||||
Reference in new issue
Block a user