carnet panel contact
This commit is contained in:
parent
a10660a27f
commit
64b5fcd4e8
@ -393,18 +393,33 @@ export default function CarnetPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { content } = await response.json();
|
const { content } = await response.json();
|
||||||
const contacts = parseVCardContent(content);
|
|
||||||
|
// Split the content into individual vCards
|
||||||
|
const vcards = content.split('BEGIN:VCARD').filter(section => section.trim());
|
||||||
|
|
||||||
// Update or add the contact
|
// Update or add the contact
|
||||||
const existingIndex = contacts.findIndex(c => c.id === contact.id);
|
let updatedVcards: string[] = [];
|
||||||
if (existingIndex >= 0) {
|
let contactUpdated = false;
|
||||||
contacts[existingIndex] = contact;
|
|
||||||
} else {
|
for (const section of vcards) {
|
||||||
contacts.push(contact);
|
const vcard = parseVCard('BEGIN:VCARD' + section);
|
||||||
|
if (vcard.uid?.[0]?.value === contact.id) {
|
||||||
|
// Replace the existing contact
|
||||||
|
updatedVcards.push(generateVCardContent(contact));
|
||||||
|
contactUpdated = true;
|
||||||
|
} else {
|
||||||
|
// Keep the existing contact
|
||||||
|
updatedVcards.push('BEGIN:VCARD' + section);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate new VCF content
|
// If contact wasn't found, add it as new
|
||||||
const vcfContent = contacts.map(c => generateVCardContent(c)).join('\n');
|
if (!contactUpdated) {
|
||||||
|
updatedVcards.push(generateVCardContent(contact));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join all vCards back together
|
||||||
|
const vcfContent = updatedVcards.join('\n');
|
||||||
|
|
||||||
// Save the updated VCF file
|
// Save the updated VCF file
|
||||||
const saveResponse = await fetch('/api/nextcloud/files', {
|
const saveResponse = await fetch('/api/nextcloud/files', {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user