mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
Clean up decryption on details page
This commit is contained in:
parent
23d30fa351
commit
aa27ff91f8
@ -48,7 +48,7 @@ module.exports = removeImports({
|
||||
headers: [
|
||||
{
|
||||
key: "Access-Control-Allow-Origin",
|
||||
value: "*"
|
||||
value: process.env.BACKEND_URL
|
||||
},
|
||||
{
|
||||
key: "Access-Control-Allow-Methods",
|
||||
|
@ -11,7 +11,7 @@ const appConfig = {
|
||||
"wss://purplerelay.com/",
|
||||
"wss://relay.devs.tools/"
|
||||
],
|
||||
authorPubkeys: ["f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741", "c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345"],
|
||||
authorPubkeys: ["f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741", "c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345", "468f729dd409053dac5e7470622c3996aad88db6ed1de9165cb1921b5ab4fd5e"],
|
||||
customLightningAddresses: [
|
||||
{
|
||||
// todo remove need for lowercase
|
||||
|
@ -30,21 +30,15 @@ const Details = () => {
|
||||
const { showToast } = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchLessons = async () => {
|
||||
try {
|
||||
const res = await axios.get('/api/lessons');
|
||||
if (res.data) {
|
||||
const lessonData = res.data.map(lesson => ({
|
||||
resourceId: lesson?.resourceId,
|
||||
courseId: lesson?.courseId || null
|
||||
}));
|
||||
setLessons(lessonData);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('err', err);
|
||||
axios.get('/api/lessons').then(res => {
|
||||
if (res.data) {
|
||||
res.data.forEach(lesson => {
|
||||
setLessons(prev => [...prev, { resourceId: lesson?.resourceId, courseId: lesson?.courseId || null }]);
|
||||
});
|
||||
}
|
||||
};
|
||||
fetchLessons();
|
||||
}).catch(err => {
|
||||
console.error('err', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const fetchAuthor = useCallback(async (pubkey) => {
|
||||
@ -112,7 +106,21 @@ const Details = () => {
|
||||
const parsedEvent = parseEvent(event);
|
||||
setEvent(parsedEvent);
|
||||
await fetchAuthor(event.pubkey);
|
||||
setAuthorView(session?.user?.pubkey === event.pubkey);
|
||||
|
||||
const isAuthor = session?.user?.pubkey === event.pubkey;
|
||||
setAuthorView(isAuthor);
|
||||
|
||||
if (parsedEvent.price || (isAuthor && event.kind === 30402)) {
|
||||
const shouldDecrypt = isAuthor ||
|
||||
session?.user?.role?.subscribed ||
|
||||
session?.user?.purchased?.some(purchase => purchase.resourceId === parsedEvent.d) ||
|
||||
lessons.some(lesson => lesson.resourceId === parsedEvent.d && session?.user?.purchased?.some(purchase => purchase.courseId === lesson.courseId));
|
||||
|
||||
if (shouldDecrypt && !decryptedContent) {
|
||||
const decrypted = await decryptContent(event.content);
|
||||
setDecryptedContent(decrypted);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching event:', error);
|
||||
@ -123,34 +131,7 @@ const Details = () => {
|
||||
};
|
||||
|
||||
fetchAndProcessEvent();
|
||||
}, [router.isReady, router.query, ndk, session?.user?.pubkey, fetchAuthor, showToast]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleDecryption = async () => {
|
||||
if (!event || !session || !lessons.length) return;
|
||||
|
||||
const isAuthor = session?.user?.pubkey === event.pubkey;
|
||||
|
||||
if (event.price || (isAuthor && event.kind === 30402)) {
|
||||
const shouldDecrypt = isAuthor ||
|
||||
session?.user?.role?.subscribed ||
|
||||
session?.user?.purchased?.some(purchase => purchase.resourceId === event.d) ||
|
||||
lessons.some(lesson =>
|
||||
lesson.resourceId === event.d &&
|
||||
session?.user?.purchased?.some(purchase =>
|
||||
purchase.courseId === lesson.courseId
|
||||
)
|
||||
);
|
||||
|
||||
if (shouldDecrypt) {
|
||||
const decrypted = await decryptContent(event.content);
|
||||
setDecryptedContent(decrypted);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
handleDecryption();
|
||||
}, [event, session, lessons, decryptContent]);
|
||||
}, [router.isReady, router.query, ndk, session, decryptContent, fetchAuthor, showToast]);
|
||||
|
||||
const handlePaymentSuccess = (response) => {
|
||||
if (response && response?.preimage) {
|
||||
@ -204,4 +185,4 @@ const Details = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
||||
export default Details;
|
Loading…
x
Reference in New Issue
Block a user