mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
Fixes to naddr encoding
This commit is contained in:
parent
90fb210de4
commit
65692026b6
@ -40,12 +40,12 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
|||||||
}, [course]);
|
}, [course]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (course && course?.id) {
|
if (course && course?.d) {
|
||||||
const nAddress = nip19.naddrEncode({
|
const nAddress = nip19.naddrEncode({
|
||||||
pubkey: course.pubkey,
|
pubkey: course.pubkey,
|
||||||
kind: course.kind,
|
kind: course.kind,
|
||||||
identifier: course.id,
|
identifier: course.d,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
setNAddress(nAddress);
|
setNAddress(nAddress);
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,11 @@ export function DocumentTemplate({ document, isLesson, showMetaTags }) {
|
|||||||
const isMobile = windowWidth < 768;
|
const isMobile = windowWidth < 768;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (document && document?.id) {
|
if (document && document?.d) {
|
||||||
const nAddress = nip19.naddrEncode({
|
const nAddress = nip19.naddrEncode({
|
||||||
pubkey: document.pubkey,
|
pubkey: document.pubkey,
|
||||||
kind: document.kind,
|
kind: document.kind,
|
||||||
identifier: document.id,
|
identifier: document.d
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
|
||||||
});
|
});
|
||||||
setNAddress(nAddress);
|
setNAddress(nAddress);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,11 @@ export function VideoTemplate({ video, isLesson, showMetaTags }) {
|
|||||||
const isMobile = windowWidth < 768;
|
const isMobile = windowWidth < 768;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (video && video?.id) {
|
if (video && video?.d) {
|
||||||
const nAddress = nip19.naddrEncode({
|
const nAddress = nip19.naddrEncode({
|
||||||
pubkey: video.pubkey,
|
pubkey: video.pubkey,
|
||||||
kind: video.kind,
|
kind: video.kind,
|
||||||
identifier: video.id,
|
identifier: video.d
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
|
||||||
});
|
});
|
||||||
setNAddress(nAddress);
|
setNAddress(nAddress);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ export default function CourseDetails({ processedEvent, paidCourse, lessons, dec
|
|||||||
pubkey: processedEvent.pubkey,
|
pubkey: processedEvent.pubkey,
|
||||||
kind: processedEvent.kind,
|
kind: processedEvent.kind,
|
||||||
identifier: processedEvent.d,
|
identifier: processedEvent.d,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
setNAddress(naddr);
|
setNAddress(naddr);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ const DocumentLesson = ({ lesson, course, decryptionPerformed, isPaid, setComple
|
|||||||
pubkey: lesson.pubkey,
|
pubkey: lesson.pubkey,
|
||||||
kind: lesson.kind,
|
kind: lesson.kind,
|
||||||
identifier: lesson.d,
|
identifier: lesson.d,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
})
|
})
|
||||||
setNAddress(addr);
|
setNAddress(addr);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ export default function DraftCourseDetails({ processedEvent, draftId, lessons })
|
|||||||
pubkey: resource.pubkey,
|
pubkey: resource.pubkey,
|
||||||
kind: resource.kind,
|
kind: resource.kind,
|
||||||
identifier: dTag,
|
identifier: dTag,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
|
|
||||||
const userResponse = await axios.get(`/api/users/${user.pubkey}`);
|
const userResponse = await axios.get(`/api/users/${user.pubkey}`);
|
||||||
|
@ -94,7 +94,7 @@ const VideoLesson = ({ lesson, course, decryptionPerformed, isPaid, setCompleted
|
|||||||
pubkey: lesson.pubkey,
|
pubkey: lesson.pubkey,
|
||||||
kind: lesson.kind,
|
kind: lesson.kind,
|
||||||
identifier: lesson.d,
|
identifier: lesson.d,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
setNAddress(addr);
|
setNAddress(addr);
|
||||||
}, [lesson]);
|
}, [lesson]);
|
||||||
|
@ -20,20 +20,20 @@ const ContentListItem = (content) => {
|
|||||||
let nAddress;
|
let nAddress;
|
||||||
if (isPublishedCourse) {
|
if (isPublishedCourse) {
|
||||||
nAddress = nip19.naddrEncode({
|
nAddress = nip19.naddrEncode({
|
||||||
identifier: content.id,
|
identifier: content?.d || content.id,
|
||||||
kind: content.kind,
|
kind: content.kind,
|
||||||
pubkey: content.pubkey,
|
pubkey: content.pubkey,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
router.push(`/course/${nAddress}`);
|
router.push(`/course/${nAddress}`);
|
||||||
} else if (isDraftCourse) {
|
} else if (isDraftCourse) {
|
||||||
router.push(`/course/${content.id}/draft`);
|
router.push(`/course/${content.id}/draft`);
|
||||||
} else if (isResource) {
|
} else if (isResource) {
|
||||||
nAddress = nip19.naddrEncode({
|
nAddress = nip19.naddrEncode({
|
||||||
identifier: content.id,
|
identifier: content.d,
|
||||||
kind: content.kind,
|
kind: content.kind,
|
||||||
pubkey: content.pubkey,
|
pubkey: content.pubkey,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
router.push(`/details/${nAddress}`);
|
router.push(`/details/${nAddress}`);
|
||||||
} else if (isDraft) {
|
} else if (isDraft) {
|
||||||
|
@ -33,9 +33,9 @@ const ProgressListItem = ({ dTag, category }) => {
|
|||||||
const encodeNaddr = () => {
|
const encodeNaddr = () => {
|
||||||
return nip19.naddrEncode({
|
return nip19.naddrEncode({
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
identifier: event.id,
|
identifier: event.d,
|
||||||
kind: 30004,
|
kind: 30004,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ const PurchasedListItem = ({ eventId, category }) => {
|
|||||||
const encodeNaddr = () => {
|
const encodeNaddr = () => {
|
||||||
setNaddr(nip19.naddrEncode({
|
setNaddr(nip19.naddrEncode({
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
identifier: event.id,
|
identifier: event.d,
|
||||||
kind: event.kind,
|
kind: event.kind,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ const ZapForm = ({ event }) => {
|
|||||||
kind: event?.kind,
|
kind: event?.kind,
|
||||||
pubkey: event?.pubkey,
|
pubkey: event?.pubkey,
|
||||||
identifier: event.d,
|
identifier: event.d,
|
||||||
relays: [...appConfig.defaultRelayUrls]
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -38,23 +38,15 @@ const useCourseData = (ndk, fetchAuthor, router) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return data.identifier;
|
return data.identifier;
|
||||||
} else if (slug.includes("-")) {
|
} else {
|
||||||
try {
|
return slug;
|
||||||
const res = await axios.get(`/api/courses/${slug}`);
|
|
||||||
return res.data?.noteId;
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching course:', err);
|
|
||||||
showToast('error', 'Error', 'Course not found');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return slug;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchCourse = async (courseId) => {
|
const fetchCourse = async (courseId) => {
|
||||||
try {
|
try {
|
||||||
await ndk.connect();
|
await ndk.connect();
|
||||||
const event = await ndk.fetchEvent({ ids: [courseId] });
|
const event = await ndk.fetchEvent({ "#d": [courseId] });
|
||||||
if (!event) return null;
|
if (!event) return null;
|
||||||
|
|
||||||
const author = await fetchAuthor(event.pubkey);
|
const author = await fetchAuthor(event.pubkey);
|
||||||
|
@ -11,7 +11,6 @@ import { useRouter } from "next/router";
|
|||||||
import { ProgressSpinner } from 'primereact/progressspinner';
|
import { ProgressSpinner } from 'primereact/progressspinner';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||||
import appConfig from "@/config/appConfig";
|
|
||||||
|
|
||||||
// todo: /decrypt is still being called way too much on this page, need to clean up state management
|
// todo: /decrypt is still being called way too much on this page, need to clean up state management
|
||||||
|
|
||||||
@ -58,8 +57,7 @@ const Details = () => {
|
|||||||
const naddr = nip19.naddrEncode({
|
const naddr = nip19.naddrEncode({
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
kind: event.kind,
|
kind: event.kind,
|
||||||
identifier: event.d,
|
identifier: event.d
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
|
||||||
});
|
});
|
||||||
setNAddress(naddr);
|
setNAddress(naddr);
|
||||||
}
|
}
|
||||||
@ -94,7 +92,7 @@ const Details = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
id = data?.identifier;
|
id = null;
|
||||||
setNAddress(slug);
|
setNAddress(slug);
|
||||||
} else {
|
} else {
|
||||||
id = slug;
|
id = slug;
|
||||||
@ -102,7 +100,14 @@ const Details = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await ndk.connect();
|
await ndk.connect();
|
||||||
const event = await ndk.fetchEvent({ ids: [id] });
|
let filter;
|
||||||
|
if (id) {
|
||||||
|
filter = { ids: [id] };
|
||||||
|
} else {
|
||||||
|
const decoded = nip19.decode(slug);
|
||||||
|
filter = { "#d": [decoded?.data?.identifier] };
|
||||||
|
}
|
||||||
|
const event = await ndk.fetchEvent(filter);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
const parsedEvent = parseEvent(event);
|
const parsedEvent = parseEvent(event);
|
||||||
|
@ -128,7 +128,7 @@ export default function Draft() {
|
|||||||
pubkey: resource.pubkey,
|
pubkey: resource.pubkey,
|
||||||
kind: resource.kind,
|
kind: resource.kind,
|
||||||
identifier: dTag,
|
identifier: dTag,
|
||||||
relayUrls: appConfig.defaultRelayUrls
|
relays: appConfig.defaultRelayUrls
|
||||||
});
|
});
|
||||||
|
|
||||||
const userResponse = await axios.get(`/api/users/${user.pubkey}`);
|
const userResponse = await axios.get(`/api/users/${user.pubkey}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user