changes
This commit is contained in:
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user