mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-04-18 15:31:17 -04:00
initial commit
This commit is contained in:
parent
5c09c5a22f
commit
e89fb616e7
14 changed files with 1977 additions and 0 deletions
3
file-uploader/.gitignore
vendored
Normal file
3
file-uploader/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules
|
||||||
|
# Keep environment variables out of version control
|
||||||
|
.env
|
1718
file-uploader/package-lock.json
generated
Normal file
1718
file-uploader/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
23
file-uploader/package.json
Normal file
23
file-uploader/package.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"name": "file-uploader",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"dependencies": {
|
||||||
|
"@prisma/client": "^6.5.0",
|
||||||
|
"ejs": "^3.1.10",
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"express-session": "^1.18.1",
|
||||||
|
"express-validator": "^7.2.1",
|
||||||
|
"passport": "^0.7.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prisma": "^6.5.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "User" (
|
||||||
|
"id" SERIAL NOT NULL,
|
||||||
|
"username" VARCHAR(50) NOT NULL,
|
||||||
|
"email" TEXT NOT NULL,
|
||||||
|
"password" TEXT NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "File" (
|
||||||
|
"id" SERIAL NOT NULL,
|
||||||
|
"name" VARCHAR(255) NOT NULL,
|
||||||
|
"url" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"ownerId" INTEGER,
|
||||||
|
"folderId" INTEGER,
|
||||||
|
|
||||||
|
CONSTRAINT "File_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Folder" (
|
||||||
|
"id" SERIAL NOT NULL,
|
||||||
|
"name" VARCHAR(255) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "Folder_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "File" ADD CONSTRAINT "File_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "File" ADD CONSTRAINT "File_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "Folder"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
3
file-uploader/prisma/migrations/migration_lock.toml
Normal file
3
file-uploader/prisma/migrations/migration_lock.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Please do not edit this file manually
|
||||||
|
# It should be added in your version-control system (e.g., Git)
|
||||||
|
provider = "postgresql"
|
40
file-uploader/prisma/schema.prisma
Normal file
40
file-uploader/prisma/schema.prisma
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// This is your Prisma schema file,
|
||||||
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||||
|
|
||||||
|
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
||||||
|
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
||||||
|
|
||||||
|
generator client {
|
||||||
|
provider = "prisma-client-js"
|
||||||
|
output = "../node_modules/.prisma/client"
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
|
}
|
||||||
|
|
||||||
|
model User {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
username String @unique @db.VarChar(50)
|
||||||
|
email String @unique
|
||||||
|
password String
|
||||||
|
files File[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model File {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
name String @db.VarChar(255)
|
||||||
|
url String
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
owner User? @relation(fields: [ownerId], references: [id])
|
||||||
|
ownerId Int?
|
||||||
|
folder Folder? @relation(fields: [folderId], references: [id])
|
||||||
|
folderId Int?
|
||||||
|
}
|
||||||
|
|
||||||
|
model Folder {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
name String @db.VarChar(255)
|
||||||
|
File File[]
|
||||||
|
}
|
19
file-uploader/src/controllers/authController.js
Normal file
19
file-uploader/src/controllers/authController.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
const db = require("../models/auth")
|
||||||
|
|
||||||
|
const loginGet = (req, res, next) => {
|
||||||
|
res.send("Login Route")
|
||||||
|
}
|
||||||
|
|
||||||
|
const registerGet = (req, res) => {
|
||||||
|
res.render("register")
|
||||||
|
}
|
||||||
|
|
||||||
|
const registerPost = async (req, res, next) => {
|
||||||
|
const { username, email, password, "password-confirmation": passwordConfirmation } = req.body;
|
||||||
|
|
||||||
|
await db.createUser({ username: username, password: password, email: email })
|
||||||
|
|
||||||
|
res.redirect("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { loginGet, registerPost, registerGet }
|
8
file-uploader/src/controllers/indexController.js
Normal file
8
file-uploader/src/controllers/indexController.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const db = require("../models/auth")
|
||||||
|
const indexGet = async (req, res) => {
|
||||||
|
const data = await db.allUsers()
|
||||||
|
console.dir(data)
|
||||||
|
res.render("main")
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { indexGet }
|
23
file-uploader/src/index.js
Normal file
23
file-uploader/src/index.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
const express = require("express");
|
||||||
|
const session = require("express-session")
|
||||||
|
const passport = require("passport")
|
||||||
|
const path = require("node:path");
|
||||||
|
|
||||||
|
const port = process.env.APP_PORT || 3000;
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
const authRouter = require("./routes/authRouter")
|
||||||
|
const indexRouter = require("./routes/indexRouter")
|
||||||
|
|
||||||
|
app.set("views", path.join(__dirname, "views"));
|
||||||
|
app.set("view engine", "ejs");
|
||||||
|
app.use(express.urlencoded({ extended: false }))
|
||||||
|
|
||||||
|
|
||||||
|
app.use("/", indexRouter);
|
||||||
|
app.use("/auth", authRouter);
|
||||||
|
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`App listening on ${port}`);
|
||||||
|
});
|
35
file-uploader/src/models/auth.js
Normal file
35
file-uploader/src/models/auth.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
const { PrismaClient } = require("@prisma/client");
|
||||||
|
// const { Prisma } = require("prisma");
|
||||||
|
|
||||||
|
const primsa = new PrismaClient()
|
||||||
|
|
||||||
|
// async function main() {
|
||||||
|
// const allUsers = await primsa.user.findMany()
|
||||||
|
// console.log(allUsers)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// main()
|
||||||
|
// .then(async () => {
|
||||||
|
// await primsa.$disconnect()
|
||||||
|
// })
|
||||||
|
// .catch(async (e) => {
|
||||||
|
// console.error(e)
|
||||||
|
// await primsa.$disconnect()
|
||||||
|
// process.exit(1)
|
||||||
|
// })
|
||||||
|
|
||||||
|
async function createUser(user) {
|
||||||
|
await primsa.user.create({
|
||||||
|
data: {
|
||||||
|
username: user.username,
|
||||||
|
email: user?.email,
|
||||||
|
password: user.password
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function allUsers() {
|
||||||
|
return await primsa.user.findMany()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { createUser, allUsers }
|
11
file-uploader/src/routes/authRouter.js
Normal file
11
file-uploader/src/routes/authRouter.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
const { Router } = require("express");
|
||||||
|
const authController = require("../controllers/authController")
|
||||||
|
|
||||||
|
const authRouter = Router();
|
||||||
|
|
||||||
|
authRouter.get("/login", authController.loginGet)
|
||||||
|
authRouter.get("/register", authController.registerGet)
|
||||||
|
authRouter.post("/register", authController.registerPost)
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = authRouter;
|
8
file-uploader/src/routes/indexRouter.js
Normal file
8
file-uploader/src/routes/indexRouter.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const { Router } = require("express")
|
||||||
|
const indexController = require("../controllers/indexController")
|
||||||
|
|
||||||
|
indexRouter = Router()
|
||||||
|
indexRouter.get("/", indexController.indexGet)
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = indexRouter
|
21
file-uploader/src/views/main.ejs
Normal file
21
file-uploader/src/views/main.ejs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="/auth/login" method="post">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input type="text" name="username">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" id="password">
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
<a href="/auth/register">Click here to register</a>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
24
file-uploader/src/views/register.ejs
Normal file
24
file-uploader/src/views/register.ejs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="/auth/register" method="post">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input type="text" name="username">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" id="password">
|
||||||
|
<label for="password-confirmation">Password Confirmation</label>
|
||||||
|
<input type="password-confirmation" name="password-confirmation" id="password-confirmation">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="email" name="email" id="email">
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue