Skip to content

Commit

Permalink
chore: add Prettier configuration and update package dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroskullx committed Dec 23, 2024
1 parent 5aa70d6 commit 05bc40b
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 302 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "semi": false }
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/node": "^22.10.2",
"eslint": "9.17.0",
"globals": "15.14.0",
"prettier": "3.4.2",
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
Expand Down
86 changes: 43 additions & 43 deletions src/app.ts
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" })
})
28 changes: 14 additions & 14 deletions src/config/db.ts
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
102 changes: 51 additions & 51 deletions src/http/controller/file.ts
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,
}
}
Loading

0 comments on commit 05bc40b

Please sign in to comment.