mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
functions & Update settings & sendUserChanges system. I also updated *some* README stuff. & Update tos & privacy policy pages.
33 lines
792 B
TypeScript
33 lines
792 B
TypeScript
import sql from "~/server/components/postgres";
|
|
export default defineEventHandler(async (event) => {
|
|
// Check user data.
|
|
const userToken = getCookie(event, "token");
|
|
if (!userToken) {
|
|
return {
|
|
error: "ERR_NOT_ALLOWED",
|
|
};
|
|
}
|
|
const checkUserToken = await sql`
|
|
select * from usertokens
|
|
where token=${userToken}
|
|
`;
|
|
if (checkUserToken.length === 0) {
|
|
return {
|
|
error: "ERR_NOT_ALLOWED",
|
|
};
|
|
}
|
|
// Actual function
|
|
const body = await readBody(event);
|
|
if (body.jsonValue.length === 0) {
|
|
const clearBadDataRegex = /[@-_.+a-zA-Z0-9]{2,}/;
|
|
let allowed = true;
|
|
if (body.value.match()) {
|
|
allowed = false;
|
|
}
|
|
return {
|
|
body: body,
|
|
allowed: allowed,
|
|
data: body.value.match(clearBadDataRegex),
|
|
};
|
|
}
|
|
});
|