-
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.
chore: add Prettier configuration and update package dependencies
- Loading branch information
1 parent
5aa70d6
commit 05bc40b
Showing
13 changed files
with
318 additions
and
302 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "semi": false } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import "reflect-metadata"; | ||
import fastify from "fastify"; | ||
import fastifyMultipart from "@fastify/multipart"; | ||
import fastifyCors from "@fastify/cors"; | ||
import fastifyJwt from "@fastify/jwt"; | ||
import {ZodError} from "zod"; | ||
import dotenv from "dotenv"; | ||
|
||
import {appRoutes} from "#/http/routes"; | ||
|
||
dotenv.config(); | ||
|
||
export const app = fastify(); | ||
|
||
app.register(fastifyMultipart); | ||
|
||
// Test, I don't know if I will use this yet | ||
app.register(fastifyJwt, { | ||
secret: process.env.JWT_SECRET!, | ||
}); | ||
|
||
app.register(fastifyCors, { | ||
//origin: "http://localhost:3000", | ||
methods: ["GET", "POST", "PUT", "DELETE"], | ||
}); | ||
|
||
app.register(appRoutes); | ||
|
||
app.setErrorHandler((error, _req, res) => { | ||
if (error instanceof ZodError) { | ||
return res | ||
.status(400) | ||
.send({message: "Validation error", issues: error.format()}); | ||
} | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
console.error(error); | ||
} else { | ||
// TODO: Here we can log the error to a service like Sentry/LogRocket/DataDog/NewRelic | ||
} | ||
|
||
res.status(500).send({error: "Internal server error"}); | ||
}); | ||
import "reflect-metadata" | ||
import fastify from "fastify" | ||
import fastifyMultipart from "@fastify/multipart" | ||
import fastifyCors from "@fastify/cors" | ||
import fastifyJwt from "@fastify/jwt" | ||
import { ZodError } from "zod" | ||
import dotenv from "dotenv" | ||
|
||
import { appRoutes } from "#/http/routes" | ||
|
||
dotenv.config() | ||
|
||
export const app = fastify() | ||
|
||
app.register(fastifyMultipart) | ||
|
||
// Test, I don't know if I will use this yet | ||
app.register(fastifyJwt, { | ||
secret: process.env.JWT_SECRET!, | ||
}) | ||
|
||
app.register(fastifyCors, { | ||
//origin: "http://localhost:3000", | ||
methods: ["GET", "POST", "PUT", "DELETE"], | ||
}) | ||
|
||
app.register(appRoutes) | ||
|
||
app.setErrorHandler((error, _req, res) => { | ||
if (error instanceof ZodError) { | ||
return res | ||
.status(400) | ||
.send({ message: "Validation error", issues: error.format() }) | ||
} | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
console.error(error) | ||
} else { | ||
// TODO: Here we can log the error to a service like Sentry/LogRocket/DataDog/NewRelic | ||
} | ||
|
||
res.status(500).send({ error: "Internal server error" }) | ||
}) |
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,14 +1,14 @@ | ||
import mysql from "mysql2/promise"; | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
const pool = mysql.createPool({ | ||
host: process.env.DB_HOST, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
port: Number(process.env.DB_PORT), | ||
}); | ||
|
||
export default pool; | ||
import mysql from "mysql2/promise" | ||
import dotenv from "dotenv" | ||
|
||
dotenv.config() | ||
|
||
const pool = mysql.createPool({ | ||
host: process.env.DB_HOST, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
port: Number(process.env.DB_PORT), | ||
}) | ||
|
||
export default pool |
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,51 +1,51 @@ | ||
import {prisma} from "#/lib/prisma"; | ||
import {File} from "@prisma/client"; | ||
|
||
export async function searchFileHash( | ||
hash: string, | ||
currentFileName: string | ||
): Promise<File | null> { | ||
const fileRecord = await prisma.file.findUnique({ | ||
where: {hash}, | ||
}); | ||
|
||
if (!fileRecord) { | ||
return null; | ||
} | ||
|
||
return { | ||
id: fileRecord?.id, | ||
originalFileName: currentFileName, | ||
status: fileRecord?.status, | ||
hash: fileRecord?.hash, | ||
ownerIp: fileRecord?.ownerIp, | ||
scannedAt: fileRecord?.scannedAt, | ||
}; | ||
} | ||
|
||
export async function insertFileRecord(props: { | ||
currentFileName: string; | ||
hash: string; | ||
status: string; | ||
ownerIp: string; | ||
}): Promise<File> { | ||
const {hash, status, currentFileName, ownerIp} = props; | ||
|
||
const fileRecord = await prisma.file.create({ | ||
data: { | ||
hash, | ||
status, | ||
originalFileName: currentFileName, | ||
ownerIp, | ||
}, | ||
}); | ||
|
||
return { | ||
id: fileRecord.id, | ||
originalFileName: fileRecord.originalFileName, | ||
status: fileRecord.status, | ||
hash: fileRecord.hash, | ||
ownerIp: fileRecord.ownerIp, | ||
scannedAt: fileRecord.scannedAt, | ||
}; | ||
} | ||
import { prisma } from "#/lib/prisma" | ||
import { File } from "@prisma/client" | ||
|
||
export async function searchFileHash( | ||
hash: string, | ||
currentFileName: string, | ||
): Promise<File | null> { | ||
const fileRecord = await prisma.file.findUnique({ | ||
where: { hash }, | ||
}) | ||
|
||
if (!fileRecord) { | ||
return null | ||
} | ||
|
||
return { | ||
id: fileRecord?.id, | ||
originalFileName: currentFileName, | ||
status: fileRecord?.status, | ||
hash: fileRecord?.hash, | ||
ownerIp: fileRecord?.ownerIp, | ||
scannedAt: fileRecord?.scannedAt, | ||
} | ||
} | ||
|
||
export async function insertFileRecord(props: { | ||
currentFileName: string | ||
hash: string | ||
status: string | ||
ownerIp: string | ||
}): Promise<File> { | ||
const { hash, status, currentFileName, ownerIp } = props | ||
|
||
const fileRecord = await prisma.file.create({ | ||
data: { | ||
hash, | ||
status, | ||
originalFileName: currentFileName, | ||
ownerIp, | ||
}, | ||
}) | ||
|
||
return { | ||
id: fileRecord.id, | ||
originalFileName: fileRecord.originalFileName, | ||
status: fileRecord.status, | ||
hash: fileRecord.hash, | ||
ownerIp: fileRecord.ownerIp, | ||
scannedAt: fileRecord.scannedAt, | ||
} | ||
} |
Oops, something went wrong.