mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
This allows not enabling Dashboard and Files. It also sorts the apps in the menu according to the order in the `config.core.enabledApps` array. Since this will require a major version upgrade (`v3.0.0`), I also took the opportunity to upgrade PostgreSQL. You can [follow this guide on how to upgrade PostgreSQL on Docker containers](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/). Finally, this has some minor security improvements (confirming API endpoints won't work if their app is disabled in the config). Closes #114 Closes #108
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { Handlers } from 'fresh/server.ts';
|
|
|
|
import { FreshContextState } from '/lib/types.ts';
|
|
import { Contact, ContactModel } from '/lib/models/contacts.ts';
|
|
import { concurrentPromises } from '/lib/utils/misc.ts';
|
|
import { getIdFromVCard, splitTextIntoVCards } from '/lib/utils/contacts.ts';
|
|
import { AppConfig } from '/lib/config.ts';
|
|
|
|
interface Data {}
|
|
|
|
export interface RequestBody {
|
|
vCards: string;
|
|
addressBookId: string;
|
|
}
|
|
|
|
export interface ResponseBody {
|
|
success: boolean;
|
|
contacts: Contact[];
|
|
}
|
|
|
|
export const handler: Handlers<Data, FreshContextState> = {
|
|
async POST(request, context) {
|
|
if (!context.state.user) {
|
|
return new Response('Unauthorized', { status: 401 });
|
|
}
|
|
|
|
if (!(await AppConfig.isAppEnabled('contacts'))) {
|
|
return new Response('Forbidden', { status: 403 });
|
|
}
|
|
|
|
const requestBody = await request.clone().json() as RequestBody;
|
|
|
|
if (!requestBody.vCards || !requestBody.addressBookId) {
|
|
return new Response('Bad request', { status: 400 });
|
|
}
|
|
|
|
const userId = context.state.user.id;
|
|
|
|
const vCards = splitTextIntoVCards(requestBody.vCards);
|
|
|
|
await concurrentPromises(
|
|
vCards.map((vCard) => async () => {
|
|
const contactId = getIdFromVCard(vCard);
|
|
|
|
await ContactModel.create(userId, requestBody.addressBookId, contactId, vCard);
|
|
}),
|
|
5,
|
|
);
|
|
|
|
const contacts = await ContactModel.list(userId, requestBody.addressBookId);
|
|
|
|
const responseBody: ResponseBody = { success: true, contacts };
|
|
|
|
return new Response(JSON.stringify(responseBody));
|
|
},
|
|
};
|