Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/api/ingestion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Command } from '@tauri-apps/api/shell';

import { getUploadsDir } from '../filesystem';
import { ReferenceItem } from '../types/ReferenceItem';
import { RawPdfIngestionResponse } from './types';

function parsePdfIngestionResponse(response: RawPdfIngestionResponse): ReferenceItem[] {
return response.references.map((reference) => ({
id: reference.filename_md5,
title: reference.title ?? reference.source_filename.replace('.pdf', ''),
authors: reference.authors.map((author) => ({ fullName: author.full_name, surname: author.surname })),
}));
}

export async function runPDFIngestion(): Promise<ReferenceItem[]> {
const uploadsDir = await getUploadsDir();
const command = new Command('call-sidecar', ['ingest', '--pdf_directory', `${uploadsDir.toString()}`]);
console.log('command', command);
const output = await command.execute();
const response = JSON.parse(output.stdout) as RawPdfIngestionResponse;
console.log('response', response);
return parsePdfIngestionResponse(response);
}
2 changes: 1 addition & 1 deletion src/types/PdfIngestion.ts → src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface PdfIngestionResponse {
export interface RawPdfIngestionResponse {
project_name: string;
references: RawReference[];
}
Expand Down
23 changes: 1 addition & 22 deletions src/filesystem.tsx → src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ import {
writeTextFile,
} from '@tauri-apps/api/fs';
import { appDataDir, join } from '@tauri-apps/api/path';
import { Command } from '@tauri-apps/api/shell';

import { INITIAL_CONTENT } from './TipTapEditor/TipTapEditorConfigs';
import { FileEntry } from './types/FileEntry';
import { PdfIngestionResponse } from './types/PdfIngestion';
import { ReferenceItem } from './types/ReferenceItem';

const PROJECT_NAME = 'project-x';
const UPLOADS_DIR = 'uploads';

async function getBaseDir() {
return join(await appDataDir(), PROJECT_NAME);
}
async function getUploadsDir() {
export async function getUploadsDir() {
return join(await getBaseDir(), UPLOADS_DIR);
}
export async function ensureProjectFileStructure() {
Expand Down Expand Up @@ -58,16 +55,6 @@ export async function uploadFiles(files: FileList) {
}
}

export async function runPDFIngestion(): Promise<ReferenceItem[]> {
const uploadsDir = await getUploadsDir();
const command = new Command('call-sidecar', ['ingest', '--pdf_directory', `${uploadsDir.toString()}`]);
console.log('command', command);
const output = await command.execute();
const response = JSON.parse(output.stdout) as PdfIngestionResponse;
console.log('response', response);
return parsePdfIngestionResponse(response);
}

export async function readFileEntryAsBinary(file: FileEntry) {
return readBinaryFile(file.path);
}
Expand Down Expand Up @@ -126,11 +113,3 @@ function sortedFileEntries(entries: FileEntry[]): FileEntry[] {
}
});
}

function parsePdfIngestionResponse(response: PdfIngestionResponse): ReferenceItem[] {
return response.references.map((reference) => ({
id: reference.filename_md5,
title: reference.title ?? reference.source_filename.replace('.pdf', ''),
authors: reference.authors.map((author) => ({ fullName: author.full_name, surname: author.surname })),
}));
}
3 changes: 2 additions & 1 deletion src/panels/ReferencesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { useAtomValue, useSetAtom } from 'jotai';
import { useState } from 'react';
import { FileUploader } from 'react-drag-drop-files';

import { runPDFIngestion } from '../api/ingestion';
import { getReferencesAtom, setReferencesAtom } from '../atoms/referencesState';
import { PanelSection } from '../components/PanelSection';
import { PanelWrapper } from '../components/PanelWrapper';
import { Spinner } from '../components/Spinner';
import { ensureProjectFileStructure, runPDFIngestion, uploadFiles } from '../filesystem';
import { ensureProjectFileStructure, uploadFiles } from '../filesystem';
import { ReferenceItem } from '../types/ReferenceItem';

const BASE_DIR = await ensureProjectFileStructure();
Expand Down