diff --git a/api/auth/services/lnurlAuth.service.js b/api/auth/services/lnurlAuth.service.js index b6bda5a..c8f3ee0 100644 --- a/api/auth/services/lnurlAuth.service.js +++ b/api/auth/services/lnurlAuth.service.js @@ -56,8 +56,10 @@ function removeExpiredHashes() { }) } + + async function generateAuthUrl() { - const hostname = 'https://auth.bolt.fun/.netlify/functions/login'; + const hostname = CONSTS.LNURL_AUTH_HOST ?? 'https://auth.bolt.fun/.netlify/functions/login'; const secret = await generateK1(); const hash = createHash(secret); await addHash(hash) diff --git a/prisma/seed/data.js b/prisma/seed/data.js index 40d1fe0..4f22d06 100644 --- a/prisma/seed/data.js +++ b/prisma/seed/data.js @@ -1,3 +1,4 @@ +const { randomItem, randomItems, random, getCoverImage } = require("./helpers") const categories = [ { @@ -46,6 +47,68 @@ const categories = [ } ] +const tags = [ + { + id: 1, + title: 'Bitcoin', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: "🅱", + isOfficial: true, + }, + { + id: 2, + title: 'Lightning', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: "⚡", + isOfficial: true, + }, + { + id: 3, + title: 'Webln', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: "🔗", + isOfficial: true, + }, + { + id: 4, + title: 'Gaming', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: "🎮", + isOfficial: true, + }, + { + + id: 5, + title: 'Design', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: '🎨', + isOfficial: true, + }, + { + + id: 6, + title: 'Launch', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: '🚀', + isOfficial: true, + }, + { + + id: 7, + title: 'Brainstory', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: '🧠', + isOfficial: true, + }, + { + + id: 8, + title: 'Development', + description: 'Lorem ipsum dolor sit amort consectetur, adipisicing elit. Possimus officia sit numquam nobis iure atque ab sunt nihil voluptatibus', + icon: '💻', + isOfficial: true, + } +] const projects = [ { @@ -56,9 +119,8 @@ const projects = [ "website": "https://geyser.fund/", "lightning_address": "divineorgan67@walletofsatoshi.com", "votes_count": 232, - "category": { - "id": 1 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 16, @@ -68,9 +130,8 @@ const projects = [ "website": "https://getalby.com/", "lightning_address": "hello@getalby.com", "votes_count": 215, - "category": { - "id": 9 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 20, @@ -80,9 +141,8 @@ const projects = [ "website": "https://lightning.video/", "lightning_address": "moritz@getalby.com", "votes_count": 175, - "category": { - "id": 7 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 1, @@ -92,9 +152,8 @@ const projects = [ "website": "https://kollider.xyz/", "lightning_address": "johns@getalby.com", "votes_count": 120, - "category": { - "id": 1 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 12, @@ -104,9 +163,8 @@ const projects = [ "website": "https://www.bitrefill.com/buy", "lightning_address": "moritz@getalby.com", "votes_count": 25, - "category": { - "id": 8 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 7, @@ -116,9 +174,8 @@ const projects = [ "website": "https://www.wavlake.com/", "lightning_address": "moritz@getalby.com", "votes_count": 25, - "category": { - "id": 7 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 3, @@ -128,9 +185,8 @@ const projects = [ "website": "https://sparkshot.io/", "lightning_address": "johns@getalby.com", "votes_count": 11, - "category": { - "id": 3 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 17, @@ -140,9 +196,8 @@ const projects = [ "website": "https://lightning.gifts/", "lightning_address": "moritz@getalby.com", "votes_count": 10, - "category": { - "id": 8 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 4, @@ -152,9 +207,8 @@ const projects = [ "website": "https://amboss.space/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 6 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 5, @@ -164,9 +218,8 @@ const projects = [ "website": "https://www.lnblackjack.com/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 4 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 19, @@ -176,9 +229,8 @@ const projects = [ "website": "https://yalls.org/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 2 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 13, @@ -188,9 +240,8 @@ const projects = [ "website": "https://lightningnetworkstores.com/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 8 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 9, @@ -200,9 +251,8 @@ const projects = [ "website": "https://lightning-poker.com/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 4 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 6, @@ -212,9 +262,8 @@ const projects = [ "website": "https://lngames.net/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 4 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 21, @@ -224,9 +273,8 @@ const projects = [ "website": "https://www.starbackr.com/", "lightning_address": "moritz@geralby.com", "votes_count": 0, - "category": { - "id": 7 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 8, @@ -236,9 +284,8 @@ const projects = [ "website": "https://loft.trade/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 1 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 10, @@ -248,9 +295,8 @@ const projects = [ "website": "https://lightning-roulette.com/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 4 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 14, @@ -260,9 +306,8 @@ const projects = [ "website": "https://kriptode.com/satsforlikes/index.html", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 9 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 18, @@ -272,9 +317,8 @@ const projects = [ "website": "https://scarce.city/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 3 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 15, @@ -284,9 +328,8 @@ const projects = [ "website": "https://lnshort.it/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 9 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 11, @@ -296,9 +339,8 @@ const projects = [ "website": "https://stacker.news/", "lightning_address": "moritz@getalby.com", "votes_count": 0, - "category": { - "id": 7 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) }, { "id": 2, @@ -308,14 +350,78 @@ const projects = [ "website": "https://lnmarkets.com/", "lightning_address": "johns@getalby.com", "votes_count": 0, - "category": { - "id": 1 - } + "category_id": randomItem(categories).id, + tags: randomItems(random(2, 3), tags) } ] +const hackathons = [ + { + title: 'Fulmo Hackday', + start_date: new Date(2022, 2, 22), + end_date: new Date(2022, 2, 28), + location: "Instanbul, Turkey", + cover_image: getCoverImage(), + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quam felis ut interdum commodo, scelerisque.", + tags: randomItems(3, tags), + website: "https://bolt.fun/hackathons/shock-the-web" + }, + { + title: 'Lightning Leagues', + start_date: new Date(2022, 2, 22), + end_date: new Date(2022, 2, 28), + location: "Instanbul, Turkey", + cover_image: getCoverImage(), + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quam felis ut interdum commodo, scelerisque.", + tags: randomItems(3, tags), + website: "https://bolt.fun/hackathons/shock-the-web" + }, + { + title: 'Surfing on Lightning', + start_date: new Date(2022, 2, 22), + end_date: new Date(2022, 2, 28), + location: "Instanbul, Turkey", + cover_image: getCoverImage(), + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quam felis ut interdum commodo, scelerisque.", + tags: randomItems(3, tags), + website: "https://bolt.fun/hackathons/shock-the-web" + }, + { + title: 'Lightning Startups', + start_date: new Date(2022, 2, 22), + end_date: new Date(2022, 2, 28), + location: "Instanbul, Turkey", + cover_image: getCoverImage(), + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quam felis ut interdum commodo, scelerisque.", + tags: randomItems(3, tags), + website: "https://bolt.fun/hackathons/shock-the-web" + }, + { + title: 'Design-a-thon', + start_date: new Date(2022, 2, 22), + end_date: new Date(2022, 2, 28), + location: "Instanbul, Turkey", + cover_image: getCoverImage(), + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quam felis ut interdum commodo, scelerisque.", + tags: randomItems(3, tags), + website: "https://bolt.fun/hackathons/shock-the-web" + }, + { + title: 'Lightning Olympics', + start_date: new Date(2022, 2, 22), + end_date: new Date(2022, 2, 28), + location: "Instanbul, Turkey", + cover_image: getCoverImage(), + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quam felis ut interdum commodo, scelerisque.", + tags: randomItems(3, tags), + website: "https://bolt.fun/hackathons/shock-the-web" + }, +] + module.exports = { categories, - projects + projects, + tags, + hackathons, } \ No newline at end of file diff --git a/prisma/seed/helpers.js b/prisma/seed/helpers.js new file mode 100644 index 0000000..8c83c3b --- /dev/null +++ b/prisma/seed/helpers.js @@ -0,0 +1,51 @@ +function random(min, max) { + return Math.random() * (max - min) + min; +} + +function randomItem(args) { + return args[Math.floor(Math.random() * args.length)]; +} + +function randomItems(cnt, args) { + return shuffle(args).slice(0, Math.floor(cnt)); +} + +function shuffle(_array) { + let array = [..._array] + let currentIndex = array.length, randomIndex; + + // While there remain elements to shuffle. + while (currentIndex !== 0) { + + // Pick a remaining element. + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex--; + + // And swap it with the current element. + [array[currentIndex], array[randomIndex]] = [ + array[randomIndex], array[currentIndex]]; + } + + return array; +} + + +let coverImgsCntr = -1; + +function getCoverImage() { + const coverImgs = [ + 'https://picsum.photos/id/10/1600/900', + 'https://picsum.photos/id/1000/1600/900', + 'https://picsum.photos/id/1002/1600/900', + 'https://picsum.photos/id/1018/1600/900', + ] + + return coverImgs[(++coverImgsCntr) % coverImgs.length] +} + +module.exports = { + random, + randomItem, + randomItems, + getCoverImage, +} \ No newline at end of file diff --git a/prisma/seed/index.js b/prisma/seed/index.js index 894d82e..6ee6d59 100644 --- a/prisma/seed/index.js +++ b/prisma/seed/index.js @@ -1,6 +1,10 @@ const { PrismaClient } = require("@prisma/client"); const { generatePrivateKey, getPublicKey } = require("../../api/utils/nostr-tools"); -const { categories, projects } = require("./data"); +const { categories, projects, tags, hackathons } = require("./data"); +const Chance = require('chance'); +const { getCoverImage, randomItems, random } = require("./helpers"); + +const chance = new Chance(); const prisma = new PrismaClient() @@ -41,9 +45,22 @@ async function generateNostrKeys() { async function main() { - console.log("Purging old data"); - await purge() + // console.log("Purging old data"); + // await purge() + // await createCategories(); + + // await createTags(); + + // await createProjects(); + + // await createStories(); + + // await createHackathons(); + +} + +async function createCategories() { console.log("Creating Categories"); await prisma.category.createMany({ data: categories.map(item => ({ @@ -53,50 +70,89 @@ async function main() { icon: '🎭' })) }) +} +async function createTags() { + console.log("Creating Tags"); + await prisma.tag.createMany({ + data: tags.map(item => ({ + id: item.id, + title: item.title, + description: item.description, + isOfficial: item.isOfficial, + icon: item.icon, + })) + }) +} +async function createProjects() { console.log("Creating Projects"); - projects.forEach(async item => { - const { category, ...feilds } = item + + for (let i = 0; i < projects.length; i++) { + const item = projects[i]; + const { tags, ...feilds } = item await prisma.project.create({ data: { ...feilds, tags: { - connectOrCreate: [ - { - where: { - title: 'Tag 1' - }, - create: { - title: "Tag 1" - } - }, - { - where: { - title: 'Tag 2' - }, - create: { - title: "Tag 2" - } - }, - { - where: { - title: 'Tag 3' - }, - create: { - title: "Tag 3" - } - },] + connect: tags.map(t => ({ + id: t.id + })) }, - category_id: category.id, description: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.", screenshots: Array(4).fill('https://via.placeholder.com/1280x729.png?text=Project+Screenshot') } }) - }) - + } } +async function createStories() { + console.log("Creating Stories"); + + const user = await prisma.user.findFirst(); + + for (let i = 0; i < 15; i++) { + const randomTags = randomItems(random(2, 5), tags) + await prisma.story.create({ + data: { + body: chance.paragraph(), + excerpt: chance.paragraph({ sentences: 1 }), + title: chance.sentence({ words: chance.integer({ min: 3, max: 7 }) }), + cover_image: getCoverImage(), + is_published: true, + tags: { + connect: randomTags.map(t => ({ id: t.id })) + }, + user_id: user.id, + votes_count: Math.floor(random(10, 6600)), + } + }) + } +} + +async function createHackathons() { + console.log("Creating Hackathons"); + + for (let i = 0; i < hackathons.length; i++) { + const item = hackathons[i]; + const { tags, ...feilds } = item + await prisma.hackathon.create({ + data: { + ...feilds, + tags: { + connect: tags.map(t => ({ + id: t.id + })) + }, + description: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.", + } + }) + } +} + + + + main() .catch((e) => { console.error(e) diff --git a/src/features/Projects/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx b/src/features/Projects/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx index fbefc41..0b5bac8 100644 --- a/src/features/Projects/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx +++ b/src/features/Projects/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx @@ -26,9 +26,10 @@ export default function ProjectsSection() { - + {shockTheWebCategory && + } {restCategories.map(({ id, title, project, }) => { if (project) return