mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +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]);
|
||||
|
||||
useEffect(() => {
|
||||
if (course && course?.id) {
|
||||
if (course && course?.d) {
|
||||
const nAddress = nip19.naddrEncode({
|
||||
pubkey: course.pubkey,
|
||||
kind: course.kind,
|
||||
identifier: course.id,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
identifier: course.d,
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
setNAddress(nAddress);
|
||||
}
|
||||
|
@ -24,12 +24,11 @@ export function DocumentTemplate({ document, isLesson, showMetaTags }) {
|
||||
const isMobile = windowWidth < 768;
|
||||
|
||||
useEffect(() => {
|
||||
if (document && document?.id) {
|
||||
if (document && document?.d) {
|
||||
const nAddress = nip19.naddrEncode({
|
||||
pubkey: document.pubkey,
|
||||
kind: document.kind,
|
||||
identifier: document.id,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
identifier: document.d
|
||||
});
|
||||
setNAddress(nAddress);
|
||||
}
|
||||
|
@ -25,12 +25,11 @@ export function VideoTemplate({ video, isLesson, showMetaTags }) {
|
||||
const isMobile = windowWidth < 768;
|
||||
|
||||
useEffect(() => {
|
||||
if (video && video?.id) {
|
||||
if (video && video?.d) {
|
||||
const nAddress = nip19.naddrEncode({
|
||||
pubkey: video.pubkey,
|
||||
kind: video.kind,
|
||||
identifier: video.id,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
identifier: video.d
|
||||
});
|
||||
setNAddress(nAddress);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ export default function CourseDetails({ processedEvent, paidCourse, lessons, dec
|
||||
pubkey: processedEvent.pubkey,
|
||||
kind: processedEvent.kind,
|
||||
identifier: processedEvent.d,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
setNAddress(naddr);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ const DocumentLesson = ({ lesson, course, decryptionPerformed, isPaid, setComple
|
||||
pubkey: lesson.pubkey,
|
||||
kind: lesson.kind,
|
||||
identifier: lesson.d,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
})
|
||||
setNAddress(addr);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ export default function DraftCourseDetails({ processedEvent, draftId, lessons })
|
||||
pubkey: resource.pubkey,
|
||||
kind: resource.kind,
|
||||
identifier: dTag,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
|
||||
const userResponse = await axios.get(`/api/users/${user.pubkey}`);
|
||||
|
@ -94,7 +94,7 @@ const VideoLesson = ({ lesson, course, decryptionPerformed, isPaid, setCompleted
|
||||
pubkey: lesson.pubkey,
|
||||
kind: lesson.kind,
|
||||
identifier: lesson.d,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
setNAddress(addr);
|
||||
}, [lesson]);
|
||||
|
@ -20,20 +20,20 @@ const ContentListItem = (content) => {
|
||||
let nAddress;
|
||||
if (isPublishedCourse) {
|
||||
nAddress = nip19.naddrEncode({
|
||||
identifier: content.id,
|
||||
identifier: content?.d || content.id,
|
||||
kind: content.kind,
|
||||
pubkey: content.pubkey,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
router.push(`/course/${nAddress}`);
|
||||
} else if (isDraftCourse) {
|
||||
router.push(`/course/${content.id}/draft`);
|
||||
} else if (isResource) {
|
||||
nAddress = nip19.naddrEncode({
|
||||
identifier: content.id,
|
||||
identifier: content.d,
|
||||
kind: content.kind,
|
||||
pubkey: content.pubkey,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
router.push(`/details/${nAddress}`);
|
||||
} else if (isDraft) {
|
||||
|
@ -33,9 +33,9 @@ const ProgressListItem = ({ dTag, category }) => {
|
||||
const encodeNaddr = () => {
|
||||
return nip19.naddrEncode({
|
||||
pubkey: event.pubkey,
|
||||
identifier: event.id,
|
||||
identifier: event.d,
|
||||
kind: 30004,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ const PurchasedListItem = ({ eventId, category }) => {
|
||||
const encodeNaddr = () => {
|
||||
setNaddr(nip19.naddrEncode({
|
||||
pubkey: event.pubkey,
|
||||
identifier: event.id,
|
||||
identifier: event.d,
|
||||
kind: event.kind,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ const ZapForm = ({ event }) => {
|
||||
kind: event?.kind,
|
||||
pubkey: event?.pubkey,
|
||||
identifier: event.d,
|
||||
relays: [...appConfig.defaultRelayUrls]
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
|
||||
return (
|
||||
|
@ -38,23 +38,15 @@ const useCourseData = (ndk, fetchAuthor, router) => {
|
||||
return null;
|
||||
}
|
||||
return data.identifier;
|
||||
} else if (slug.includes("-")) {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
return slug;
|
||||
}
|
||||
return slug;
|
||||
};
|
||||
|
||||
const fetchCourse = async (courseId) => {
|
||||
try {
|
||||
await ndk.connect();
|
||||
const event = await ndk.fetchEvent({ ids: [courseId] });
|
||||
const event = await ndk.fetchEvent({ "#d": [courseId] });
|
||||
if (!event) return null;
|
||||
|
||||
const author = await fetchAuthor(event.pubkey);
|
||||
|
@ -11,7 +11,6 @@ import { useRouter } from "next/router";
|
||||
import { ProgressSpinner } from 'primereact/progressspinner';
|
||||
import axios from 'axios';
|
||||
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
|
||||
|
||||
@ -58,8 +57,7 @@ const Details = () => {
|
||||
const naddr = nip19.naddrEncode({
|
||||
pubkey: event.pubkey,
|
||||
kind: event.kind,
|
||||
identifier: event.d,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
identifier: event.d
|
||||
});
|
||||
setNAddress(naddr);
|
||||
}
|
||||
@ -94,7 +92,7 @@ const Details = () => {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
id = data?.identifier;
|
||||
id = null;
|
||||
setNAddress(slug);
|
||||
} else {
|
||||
id = slug;
|
||||
@ -102,7 +100,14 @@ const Details = () => {
|
||||
|
||||
try {
|
||||
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) {
|
||||
const parsedEvent = parseEvent(event);
|
||||
|
@ -128,7 +128,7 @@ export default function Draft() {
|
||||
pubkey: resource.pubkey,
|
||||
kind: resource.kind,
|
||||
identifier: dTag,
|
||||
relayUrls: appConfig.defaultRelayUrls
|
||||
relays: appConfig.defaultRelayUrls
|
||||
});
|
||||
|
||||
const userResponse = await axios.get(`/api/users/${user.pubkey}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user