Skip to content

Commit

Permalink
run extractPDF on all text files
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis committed Dec 3, 2024
1 parent c4ff0c0 commit 789134d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import DatasetIcon from '@/assets/svg/icons/dataset.svg?component';
import { uploadArtifactToProject } from '@/services/artifact';
import { createModel, createModelAndModelConfig, processAndAddModelToProject, validateAMRFile } from '@/services/model';
import { createProvenance, RelationshipType } from '@/services/provenance';
import { isTextFile } from '@/utils/file';
defineProps<{
visible: boolean;
Expand Down Expand Up @@ -216,9 +217,7 @@ async function upload() {
const createdAssets = await Promise.all(createAssetsPromises);
createdAssets.forEach((_, index) => {
const { name, id } = (results.value ?? [])[index];
if (name && name.toLowerCase().endsWith('.pdf')) {
extractPDF(id);
}
if (name && isTextFile(name)) extractPDF(id);
});
emit('close');
const resourceMsg = createdAssets.length > 1 ? 'resources were' : 'resource was';
Expand Down
7 changes: 7 additions & 0 deletions packages/client/hmi-client/src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ export async function fileToJson(file: File): Promise<Record<string, unknown>> {
reader.readAsText(file);
});
}

/**
* Check if a filename ends with a pdf, txt, or md extension
*/
export function isTextFile(filename: string): boolean {
return /\.(pdf|txt|md)$/.test(filename.trim());
}

0 comments on commit 789134d

Please sign in to comment.