-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
929 additions
and
180 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,97 @@ | ||
"use server"; | ||
import prisma from "./lib/db"; | ||
import { Contest } from "./types/types"; | ||
import { Stream } from "stream"; | ||
import bucket from "./lib/storage"; | ||
import { getServerSession } from "next-auth/next"; | ||
import authOptions from "./lib/auth"; | ||
import { PrismaClient } from "@prisma/client"; | ||
import { redirect } from "next/navigation"; | ||
|
||
const prisma = new PrismaClient(); | ||
function _arrayBufferToBase64(buffer: ArrayBuffer) { | ||
var binary = ""; | ||
var bytes = new Uint8Array(buffer); | ||
var len = bytes.byteLength; | ||
for (var i = 0; i < len; i++) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return btoa(binary); | ||
} | ||
|
||
async function upload(file: File, name: string, contentType: string) { | ||
const arrayBuffer = await file.arrayBuffer(); | ||
|
||
let base64 = _arrayBufferToBase64(arrayBuffer); | ||
var bufferStream = new Stream.PassThrough(); | ||
bufferStream.end(Buffer.from(base64, "base64")); | ||
|
||
var uFile = bucket.file(name); | ||
bufferStream | ||
.pipe( | ||
uFile.createWriteStream({ | ||
metadata: { | ||
contentType: contentType, | ||
}, | ||
}), | ||
) | ||
.on("error", function (err) { | ||
console.log(err); | ||
}) | ||
.on("finish", function () { | ||
console.log("upload done"); | ||
return "sampleurl"; | ||
}); | ||
} | ||
|
||
export async function createContest(formData: FormData) { | ||
console.log(formData); | ||
//return prisma.contest.create({ data: formData }); | ||
prisma.$connect(); | ||
const session = await getServerSession(authOptions); | ||
if (!session) { | ||
throw Error("user must be authentificated!"); | ||
} | ||
|
||
const mail = session.user?.email || "noMail"; | ||
const logo = formData.get("logo") as File; | ||
const pdf = formData.get("regulations") as File; | ||
const name = formData.get("name") as string; | ||
await upload(logo, name + "logo", "image/jpeg"); | ||
await upload(pdf, name + "regulations", "application/pdf"); | ||
await prisma.contest | ||
.create({ | ||
data: { | ||
name: name, | ||
author: mail, | ||
hasAward: false, | ||
restrictUsersSchool: Boolean( | ||
formData.get("restrictHighSchool") as string, | ||
), | ||
restrictUsersStudents: Boolean( | ||
formData.get("restrictHighSchool") as string, | ||
), | ||
startDate: new Date(formData.get("startDate") as string).toISOString(), | ||
endDate: new Date(formData.get("endDate") as string).toISOString(), | ||
location: "", | ||
logoURL: | ||
"https://storage.googleapis.com/" + | ||
process.env.BUCKET_NAME + | ||
"/" + | ||
name + | ||
"logo", | ||
regulationsURL: | ||
"https://storage.googleapis.com/" + | ||
process.env.BUCKET_NAME + | ||
"/" + | ||
name + | ||
"regulations", | ||
Instagram: formData.get("instagram") as string, | ||
Facebook: formData.get("facebook") as string, | ||
LinkedIn: formData.get("linkedIn") as string, | ||
}, | ||
}) | ||
.then((t) => { | ||
console.log(t); | ||
prisma.$disconnect(); | ||
}); | ||
redirect("/"); | ||
} | ||
|
||
export async function fetchContests(tags: Array<{ author: string }>) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,14 @@ | ||
import prisma from "../lib/db"; | ||
import { Contest } from "../types/types"; | ||
import Card from "./Card"; | ||
|
||
export default function Explore({ data }: { data?: Array<Contest> }) { | ||
export default async function Explore({ data }: { data?: Array<Contest> }) { | ||
const contests = await prisma.contest.findMany(); | ||
return ( | ||
<div className="grid min-h-screen w-full flex-1 grid-cols-1 gap-2 px-2 py-2 sm:grid-cols-3 sm:pt-20"> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<Card /> | ||
<div className="grid min-h-screen w-full flex-1 grid-cols-1 grid-rows-4 gap-2 px-2 py-2 sm:grid-cols-3 sm:pt-20"> | ||
{contests.map((contest) => { | ||
return <Card key={contest.name} contest={contest as Contest} />; | ||
})} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.