mirror of
https://github.com/broekema41/obsidian-vcf-contacts.git
synced 2026-07-22 05:42:58 +00:00
Refs #32: repair the build and allowing for use the vcard module
This commit is contained in:
parent
dc3c16ae9b
commit
a01db62ede
10 changed files with 25 additions and 23 deletions
|
|
@ -2,7 +2,7 @@ import { VCardForObsidianRecord, VCardSupportedKey } from "src/contacts/vcard";
|
|||
import { ensureHasName } from "src/contacts/vcard/shared/ensureHasName";
|
||||
import { sortVCardOFields } from "src/contacts/vcard/shared/sortVcardFields";
|
||||
import { StructuredFields } from "src/contacts/vcard/shared/structuredFields";
|
||||
import { convertToLatestVCFPhotoFormat } from "src/util/avatarActions";
|
||||
import { photoLineFromV3toV4 } from "src/util/photoLineFromV3toV4";
|
||||
|
||||
function unfoldVCardLines(vCardData: string): string[] {
|
||||
// Normalize line endings to \n first (handles \r, \r\n)
|
||||
|
|
@ -112,7 +112,7 @@ function parseVCardLine(line: string): VCardForObsidianRecord {
|
|||
|
||||
const typeValues:string = params["type"] ? `[${params["type"].join(",")}]` : "";
|
||||
if (key.contains('PHOTO') && key.contains('ENCODING=BASE64')) {
|
||||
parsedData['PHOTO'] = convertToLatestVCFPhotoFormat(line);
|
||||
parsedData['PHOTO'] = photoLineFromV3toV4(line);
|
||||
} else if (key === 'VERSION') {
|
||||
parsedData['VERSION'] = '4.0';
|
||||
} else if (propKey in StructuredFields) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {App, normalizePath, Notice, Platform,TAbstractFile, TFile, TFolder, Vault, Workspace} from "obsidian";
|
||||
import { getFrontmatterFromFiles } from "src/contacts";
|
||||
import { getSettings } from "src/context/sharedSettingsContext";
|
||||
import { RunType } from "src/insights/insight";
|
||||
import { RunType } from "src/insights/insight.d";
|
||||
import { insightService } from "src/insights/insightService";
|
||||
import { FileExistsModal } from "src/ui/modals/fileExistsModal";;
|
||||
import { FileExistsModal } from "src/ui/modals/fileExistsModal";
|
||||
|
||||
export async function openFile(file: TFile, workspace: Workspace) {
|
||||
const leaf = workspace.getLeaf()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
import { Contact } from "src/contacts";
|
||||
import { InsighSettingProperties, InsightProcessor, InsightQueItem, RunType } from "src/insights/insight";
|
||||
import { InsighSettingProperties, InsightProcessor, InsightQueItem, RunType } from "src/insights/insight.d";
|
||||
|
||||
const processors = new Map<string, InsightProcessor>();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as React from "react";
|
||||
import { Contact, updateFrontMatterValue } from "src/contacts";
|
||||
import { getSettings } from "src/context/sharedSettingsContext";
|
||||
import { InsightProcessor, InsightQueItem, RunType } from "src/insights/insight";
|
||||
import { InsightProcessor, InsightQueItem, RunType } from "src/insights/insight.d";
|
||||
|
||||
// Zero dependency uuid generator as its not used for millions of records
|
||||
const generateUUID = (): string => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import { setSettings } from "src/context/sharedSettingsContext";
|
||||
import { InsighSettingProperties } from "src/insights/insight";
|
||||
import { InsighSettingProperties } from "src/insights/insight.d";
|
||||
import { insightService } from "src/insights/insightService";
|
||||
import ContactsPlugin from "src/main";
|
||||
import { FolderSuggest } from "src/settings/FolderSuggest";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import * as React from "react";
|
||||
import { convertToLatestVCFPhotoFormat } from "src/util/avatarActions";
|
||||
import { photoLineFromV3toV4 } from "src/util/photoLineFromV3toV4";
|
||||
|
||||
|
||||
interface AvatarProps {
|
||||
photoUrl?: string;
|
||||
|
|
@ -19,7 +20,7 @@ export const Avatar = (props: AvatarProps) => {
|
|||
<div className="avatar-initials">
|
||||
{props.photoUrl && !hasImageError ? (
|
||||
<img
|
||||
src={convertToLatestVCFPhotoFormat(props.photoUrl)}
|
||||
src={photoLineFromV3toV4(props.photoUrl)}
|
||||
onError={() => setHasImageError(true)}
|
||||
/>
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as React from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Contact } from "src/contacts";
|
||||
import { InsightQueItem, RunType } from "src/insights/insight";
|
||||
import { InsightQueItem, RunType } from "src/insights/insight.d";
|
||||
import { insightService } from "src/insights/insightService";
|
||||
|
||||
type ActionProps = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Notice } from "obsidian";
|
||||
import { Contact, updateFrontMatterValue } from "src/contacts";
|
||||
import { openFilePicker } from "src/file/file";
|
||||
import { RunType } from "src/insights/insight";
|
||||
import { RunType } from "src/insights/insight.d";
|
||||
import { insightService } from "src/insights/insightService";
|
||||
|
||||
const resizeAndCropImage = (img: HTMLImageElement, outputSize: number): HTMLCanvasElement => {
|
||||
|
|
@ -74,13 +74,4 @@ export const processAvatar = async (contact: Contact) => {
|
|||
}
|
||||
}
|
||||
|
||||
export const convertToLatestVCFPhotoFormat = (line:string) => {
|
||||
const url = line.startsWith('PHOTO;') ? line.slice(6) : line;
|
||||
const match = url.match(/^ENCODING=BASE64;(.*?):/);
|
||||
if (match) {
|
||||
const mimeType = match[1].toLowerCase(); // e.g., "jpeg"
|
||||
const base64Data = url.split(':').slice(1).join(':');
|
||||
return `data:image/${mimeType};base64,${base64Data}`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
|
|
|||
10
src/util/photoLineFromV3toV4.ts
Normal file
10
src/util/photoLineFromV3toV4.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export const photoLineFromV3toV4 = (line:string) => {
|
||||
const url = line.startsWith('PHOTO;') ? line.slice(6) : line;
|
||||
const match = url.match(/^ENCODING=BASE64;(.*?):/);
|
||||
if (match) {
|
||||
const mimeType = match[1].toLowerCase(); // e.g., "jpeg"
|
||||
const base64Data = url.split(':').slice(1).join(':');
|
||||
return `data:image/${mimeType};base64,${base64Data}`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { App } from "obsidian";
|
||||
import { createEmpty } from 'src/contacts/vcard/createEmpty';
|
||||
import { vcard } from "src/contacts/vcard";
|
||||
import { setApp } from "src/context/sharedAppContext";
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ vi.mock('src/ui/modals/contactNameModal', () => {
|
|||
});
|
||||
describe('vcard creatEmpty', () => {
|
||||
it('should ask for a firstname and lastname ', async () => {
|
||||
const empty = await createEmpty();
|
||||
const empty = await vcard.createEmpty();
|
||||
expect(empty).toBeDefined();
|
||||
|
||||
expect(empty).toEqual(expect.objectContaining({
|
||||
|
|
|
|||
Loading…
Reference in a new issue