Clean the code via prettier.

This commit is contained in:
yuanhau 2025-05-12 21:05:45 +08:00
parent 57aa0aba18
commit eaa9b15b2d
10 changed files with 177 additions and 165 deletions

View file

@ -1,25 +1,25 @@
import sql from "~/server/components/postgres";
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const query = getQuery(event);
/*const sources = await sql`SELECT * FROM sources`;
const body = await readBody(event);
const query = getQuery(event);
/*const sources = await sql`SELECT * FROM sources`;
return sources;*/
// Fake data
return {
status: "ok",
data: [
{
id: 1,
title: "Source 1",
url: "https://source1.com",
description: "Description for Source 1",
},
{
id: 2,
title: "Source 2",
url: "https://source2.com",
description: "Description for Source 2",
}
]
}
})
// Fake data
return {
status: "ok",
data: [
{
id: 1,
title: "Source 1",
url: "https://source1.com",
description: "Description for Source 1",
},
{
id: 2,
title: "Source 2",
url: "https://source2.com",
description: "Description for Source 2",
},
],
};
});

View file

@ -1,36 +1,34 @@
import sql from "~/server/components/postgres";
import argon2 from "argon2";
export default defineEventHandler(async (event) => {
const salt = process.env.PASSWORD_HASH_SALT;
if (!salt) {
throw createError({
statusCode: 500,
message: 'Internal server error'
});
}
const body = await readBody(event);
const { username, password } = body;
if (!username || !password) {
throw createError({
statusCode: 400,
message: 'Username and password are required'
});
}
const USERNAME_PATTERN = /^[a-zA-Z0-9_]{3,20}$/;
if (!USERNAME_PATTERN.test(username)) {
throw createError({
statusCode: 400,
message: 'Invalid username.'
});
}
// Server side hashing
const hashedPassword = await argon2.hash(salt, password);
const salt = process.env.PASSWORD_HASH_SALT;
if (!salt) {
throw createError({
statusCode: 500,
message: "Internal server error",
});
}
const body = await readBody(event);
const { username, password } = body;
if (!username || !password) {
throw createError({
statusCode: 400,
message: "Username and password are required",
});
}
const USERNAME_PATTERN = /^[a-zA-Z0-9_]{3,20}$/;
if (!USERNAME_PATTERN.test(username)) {
throw createError({
statusCode: 400,
message: "Invalid username.",
});
}
// Server side hashing
const hashedPassword = await argon2.hash(salt, password);
// Check if user exists, if not, create a user
try {
console.log(username);
console.log(hashedPassword);
} catch (e) {
}
})
// Check if user exists, if not, create a user
try {
console.log(username);
console.log(hashedPassword);
} catch (e) {}
});