mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +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: [
|
headers: [
|
||||||
{
|
{
|
||||||
key: "Access-Control-Allow-Origin",
|
key: "Access-Control-Allow-Origin",
|
||||||
value: "*"
|
value: process.env.BACKEND_URL
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "Access-Control-Allow-Methods",
|
key: "Access-Control-Allow-Methods",
|
||||||
|
@ -11,7 +11,7 @@ const appConfig = {
|
|||||||
"wss://purplerelay.com/",
|
"wss://purplerelay.com/",
|
||||||
"wss://relay.devs.tools/"
|
"wss://relay.devs.tools/"
|
||||||
],
|
],
|
||||||
authorPubkeys: ["f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741", "c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345"],
|
authorPubkeys: ["f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741", "c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345", "468f729dd409053dac5e7470622c3996aad88db6ed1de9165cb1921b5ab4fd5e"],
|
||||||
customLightningAddresses: [
|
customLightningAddresses: [
|
||||||
{
|
{
|
||||||
// todo remove need for lowercase
|
// todo remove need for lowercase
|
||||||
|
@ -30,21 +30,15 @@ const Details = () => {
|
|||||||
const { showToast } = useToast();
|
const { showToast } = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchLessons = async () => {
|
axios.get('/api/lessons').then(res => {
|
||||||
try {
|
if (res.data) {
|
||||||
const res = await axios.get('/api/lessons');
|
res.data.forEach(lesson => {
|
||||||
if (res.data) {
|
setLessons(prev => [...prev, { resourceId: lesson?.resourceId, courseId: lesson?.courseId || null }]);
|
||||||
const lessonData = res.data.map(lesson => ({
|
});
|
||||||
resourceId: lesson?.resourceId,
|
|
||||||
courseId: lesson?.courseId || null
|
|
||||||
}));
|
|
||||||
setLessons(lessonData);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('err', err);
|
|
||||||
}
|
}
|
||||||
};
|
}).catch(err => {
|
||||||
fetchLessons();
|
console.error('err', err);
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchAuthor = useCallback(async (pubkey) => {
|
const fetchAuthor = useCallback(async (pubkey) => {
|
||||||
@ -112,7 +106,21 @@ const Details = () => {
|
|||||||
const parsedEvent = parseEvent(event);
|
const parsedEvent = parseEvent(event);
|
||||||
setEvent(parsedEvent);
|
setEvent(parsedEvent);
|
||||||
await fetchAuthor(event.pubkey);
|
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) {
|
} catch (error) {
|
||||||
console.error('Error fetching event:', error);
|
console.error('Error fetching event:', error);
|
||||||
@ -123,34 +131,7 @@ const Details = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchAndProcessEvent();
|
fetchAndProcessEvent();
|
||||||
}, [router.isReady, router.query, ndk, session?.user?.pubkey, fetchAuthor, showToast]);
|
}, [router.isReady, router.query, ndk, session, decryptContent, 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]);
|
|
||||||
|
|
||||||
const handlePaymentSuccess = (response) => {
|
const handlePaymentSuccess = (response) => {
|
||||||
if (response && response?.preimage) {
|
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