Align Journal.App with SQLCipher backend contract (remove dataDirectory coupling)
This commit is contained in:
parent
aafb08e63f
commit
b60f42f6fe
@ -8,14 +8,11 @@ export function hydrateWorkspace(password: string): Promise<unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RuntimeConfigRaw = {
|
type RuntimeConfigRaw = {
|
||||||
dataDirectory?: string;
|
|
||||||
vaultDirectory?: string;
|
vaultDirectory?: string;
|
||||||
DataDirectory?: string;
|
|
||||||
VaultDirectory?: string;
|
VaultDirectory?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type RuntimeConfig = {
|
type RuntimeConfig = {
|
||||||
dataDirectory: string;
|
|
||||||
vaultDirectory: string;
|
vaultDirectory: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,7 +31,6 @@ async function getRuntimeConfig(
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dataDirectory: pickCase(data, "dataDirectory", "DataDirectory", ""),
|
|
||||||
vaultDirectory: pickCase(data, "vaultDirectory", "VaultDirectory", ""),
|
vaultDirectory: pickCase(data, "vaultDirectory", "VaultDirectory", ""),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -46,7 +42,6 @@ export async function unlockVaultWorkspace(password: string): Promise<void> {
|
|||||||
payload: {
|
payload: {
|
||||||
password,
|
password,
|
||||||
vaultDirectory: config.vaultDirectory,
|
vaultDirectory: config.vaultDirectory,
|
||||||
dataDirectory: config.dataDirectory,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -58,7 +53,6 @@ export async function unlockVaultWorkspace(password: string): Promise<void> {
|
|||||||
action: "db.hydrate_workspace",
|
action: "db.hydrate_workspace",
|
||||||
payload: {
|
payload: {
|
||||||
password,
|
password,
|
||||||
dataDirectory: config.dataDirectory,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -75,7 +69,6 @@ export async function persistAndClearVault(
|
|||||||
payload: {
|
payload: {
|
||||||
password,
|
password,
|
||||||
vaultDirectory: config.vaultDirectory,
|
vaultDirectory: config.vaultDirectory,
|
||||||
dataDirectory: config.dataDirectory,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options,
|
options,
|
||||||
@ -84,9 +77,7 @@ export async function persistAndClearVault(
|
|||||||
await sendCommand<boolean>(
|
await sendCommand<boolean>(
|
||||||
{
|
{
|
||||||
action: "vault.clear_data_directory",
|
action: "vault.clear_data_directory",
|
||||||
payload: {
|
payload: {},
|
||||||
dataDirectory: config.dataDirectory,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -35,7 +35,6 @@ export type EntrySaveResultDto = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type EntrySearchRequestDto = {
|
export type EntrySearchRequestDto = {
|
||||||
dataDirectory: string;
|
|
||||||
query?: string;
|
query?: string;
|
||||||
section?: string;
|
section?: string;
|
||||||
startDate?: string;
|
startDate?: string;
|
||||||
@ -214,12 +213,10 @@ function normalizeEntrySearchResult(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listEntries(
|
export async function listEntries(): Promise<EntryListItemDto[]> {
|
||||||
dataDirectory?: string,
|
|
||||||
): Promise<EntryListItemDto[]> {
|
|
||||||
const data = await sendCommand<EntryListItemDtoRaw[]>({
|
const data = await sendCommand<EntryListItemDtoRaw[]>({
|
||||||
action: "entries.list",
|
action: "entries.list",
|
||||||
payload: { dataDirectory },
|
payload: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
@ -46,12 +46,10 @@ function normalizeTemplateItem(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listEntryTemplates(
|
export async function listEntryTemplates(): Promise<EntryTemplateItemDto[]> {
|
||||||
dataDirectory?: string,
|
|
||||||
): Promise<EntryTemplateItemDto[]> {
|
|
||||||
const data = await sendCommand<EntryTemplateItemDtoRaw[]>({
|
const data = await sendCommand<EntryTemplateItemDtoRaw[]>({
|
||||||
action: "templates.list",
|
action: "templates.list",
|
||||||
payload: { dataDirectory },
|
payload: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -78,7 +76,6 @@ export async function saveEntryTemplate(payload: {
|
|||||||
name: string;
|
name: string;
|
||||||
content: string;
|
content: string;
|
||||||
filePath?: string;
|
filePath?: string;
|
||||||
dataDirectory?: string;
|
|
||||||
}): Promise<EntryTemplateSaveResultDto> {
|
}): Promise<EntryTemplateSaveResultDto> {
|
||||||
const data = await sendCommand<EntryTemplateSaveResultDtoRaw>({
|
const data = await sendCommand<EntryTemplateSaveResultDtoRaw>({
|
||||||
action: "templates.save",
|
action: "templates.save",
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
import { listFragments, type FragmentDto } from "$lib/backend/fragments";
|
import { listFragments, type FragmentDto } from "$lib/backend/fragments";
|
||||||
import { listLists, type ListDocumentDto } from "$lib/backend/lists";
|
import { listLists, type ListDocumentDto } from "$lib/backend/lists";
|
||||||
import { listTodoLists, type TodoListDto } from "$lib/backend/todos";
|
import { listTodoLists, type TodoListDto } from "$lib/backend/todos";
|
||||||
import { sendCommand } from "$lib/backend/client";
|
|
||||||
import CalendarWidget from "$lib/components/CalendarWidget.svelte";
|
import CalendarWidget from "$lib/components/CalendarWidget.svelte";
|
||||||
import {
|
import {
|
||||||
entriesBusyStore,
|
entriesBusyStore,
|
||||||
@ -231,16 +230,6 @@
|
|||||||
return { startDate: toIsoDate(monthStart), endDate: toIsoDate(monthEnd) };
|
return { startDate: toIsoDate(monthStart), endDate: toIsoDate(monthEnd) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDataDirectory(): Promise<string> {
|
|
||||||
const config = await sendCommand<{
|
|
||||||
dataDirectory?: string;
|
|
||||||
DataDirectory?: string;
|
|
||||||
}>({
|
|
||||||
action: "config.get",
|
|
||||||
});
|
|
||||||
return (config.dataDirectory ?? config.DataDirectory ?? "").trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toFragmentTimelineItem(fragment: FragmentDto): SidePanelItem {
|
function toFragmentTimelineItem(fragment: FragmentDto): SidePanelItem {
|
||||||
const split = fragment.description.split(/\n{2,}/);
|
const split = fragment.description.split(/\n{2,}/);
|
||||||
const title = (split[0] ?? "").trim() || "Untitled Fragment";
|
const title = (split[0] ?? "").trim() || "Untitled Fragment";
|
||||||
@ -348,16 +337,10 @@
|
|||||||
calendarBusy = true;
|
calendarBusy = true;
|
||||||
calendarError = "";
|
calendarError = "";
|
||||||
try {
|
try {
|
||||||
const dataDirectory = await getDataDirectory();
|
|
||||||
if (requestId !== calendarRefreshRequestId) return;
|
if (requestId !== calendarRefreshRequestId) return;
|
||||||
if (!dataDirectory) {
|
|
||||||
calendarTimelineItems = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { startDate, endDate } = getActiveDateRange();
|
const { startDate, endDate } = getActiveDateRange();
|
||||||
const entryItems = await searchEntriesAsItems({
|
const entryItems = await searchEntriesAsItems({
|
||||||
dataDirectory,
|
|
||||||
query: calendarQuery.trim() || undefined,
|
query: calendarQuery.trim() || undefined,
|
||||||
});
|
});
|
||||||
if (requestId !== calendarRefreshRequestId) return;
|
if (requestId !== calendarRefreshRequestId) return;
|
||||||
|
|||||||
@ -88,10 +88,10 @@ export function createEntryDraft(): EntryItem {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function hydrateEntries(dataDirectory?: string): Promise<void> {
|
export async function hydrateEntries(): Promise<void> {
|
||||||
entriesBusyStore.set(true);
|
entriesBusyStore.set(true);
|
||||||
try {
|
try {
|
||||||
const items = await listEntriesCommand(dataDirectory);
|
const items = await listEntriesCommand();
|
||||||
const mapped = items.map(fromListDto);
|
const mapped = items.map(fromListDto);
|
||||||
entriesStore.set(mapped);
|
entriesStore.set(mapped);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -162,18 +162,13 @@ export async function searchEntriesAsItems(
|
|||||||
payload: EntrySearchRequestDto,
|
payload: EntrySearchRequestDto,
|
||||||
): Promise<EntryItem[]> {
|
): Promise<EntryItem[]> {
|
||||||
const results = await searchEntriesCommand(payload);
|
const results = await searchEntriesCommand(payload);
|
||||||
const dataDirectory = payload.dataDirectory?.trim() ?? "";
|
const toSearchPath = (fileName: string): string =>
|
||||||
const separator = dataDirectory.includes("\\") ? "\\" : "/";
|
`db://entry/${encodeURIComponent(fileName)}`;
|
||||||
const basePath = dataDirectory.replace(/[\\/]+$/, "");
|
|
||||||
const mapped = results.map((result) => ({
|
const mapped = results.map((result) => ({
|
||||||
id: basePath
|
id: toStoreId(toSearchPath(result.fileName)),
|
||||||
? toStoreId(`${basePath}${separator}${result.fileName}`)
|
|
||||||
: `entries/search/${encodeURIComponent(result.fileName)}`,
|
|
||||||
label: toLabel(result.fileName),
|
label: toLabel(result.fileName),
|
||||||
initialContent: result.entry.rawContent,
|
initialContent: result.entry.rawContent,
|
||||||
filePath: basePath
|
filePath: toSearchPath(result.fileName),
|
||||||
? `${basePath}${separator}${result.fileName}`
|
|
||||||
: undefined,
|
|
||||||
date: result.entry.date,
|
date: result.entry.date,
|
||||||
}));
|
}));
|
||||||
return mapped;
|
return mapped;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user