changes
ci / docker_image (push) Successful in 2m35s
ci / deploy (push) Successful in 31s

This commit is contained in:
2025-03-20 21:30:54 -05:00
parent cd1fbeb3b0
commit 8932165f7b
18 changed files with 162 additions and 84 deletions
+5 -1
View File
@@ -1,7 +1,7 @@
import bcrypt from 'bcrypt';
import sql from '$lib/db/db.server';
import { error } from '@sveltejs/kit';
import { saveAvatar, saveLogo } from '$lib/index.server';
import { deleteLogo, saveAvatar, saveLogo } from '$lib/index.server';
import {
EmploymentType,
type User,
@@ -295,6 +295,8 @@ export async function editCompany(company: Company): Promise<number> {
RETURNING id;
`;
await saveLogo(company);
return response[0].id;
}
@@ -303,6 +305,8 @@ export async function deleteCompany(id: number): Promise<void> {
DELETE FROM companies
WHERE id = ${id};
`;
await deleteLogo(<Company>{ id: id });
}
export async function getCompany(id: number): Promise<Company> {
+17 -4
View File
@@ -15,13 +15,26 @@ export async function saveAvatar(user: User): Promise<void> {
}
export async function saveLogo(company: Company): Promise<void> {
const url = `https://ui-avatars.com/api/?background=random&format=svg&name=${encodeURIComponent(company.name!)}`;
const response = await fetch(url, { headers: { accept: 'image/svg+xml' } });
const avatar = await response.text();
const filePath = path.join('static', 'uploads', 'logos', `${company.id}.svg`);
// const url = `https://ui-avatars.com/api/?background=random&format=svg&name=${encodeURIComponent(company.name!)}`;
// const response = await fetch(url, { headers: { accept: 'image/svg+xml' } });
// const avatar = await response.text();
// const filePath = path.join('static', 'uploads', 'logos', `${company.id}.svg`);
const url = `https://img.logo.dev/${new URL(company.website!).hostname}`;
console.log(url);
const response = await fetch(url, { headers: { accept: 'image/jpeg' } });
const avatar = await response.buffer();
const filePath = path.join('static', 'uploads', 'logos', `${company.id}.jpg`);
fs.writeFileSync(filePath, avatar);
}
export async function deleteLogo(company: Company): Promise<void> {
// const url = `https://ui-avatars.com/api/?background=random&format=svg&name=${encodeURIComponent(company.name!)}`;
// const response = await fetch(url, { headers: { accept: 'image/svg+xml' } });
// const avatar = await response.text();
const filePath = path.join('static', 'uploads', 'logos', `${company.id}.jpg`);
fs.rmSync(filePath);
}
// TODO: change to return null instead of -1
export function getUserPerms(cookies: Cookies): number {
if (process.env.JWT_SECRET === undefined) {