mirror of
https://github.com/mossy1022/Smart-Memos.git
synced 2026-07-22 05:16:24 +00:00
Updated and simplified findfile path to fix possible issues with unecesary complexity. Added console logs to help troubleshoot in case user recieves errors.
This commit is contained in:
parent
51622fa78f
commit
56b10c03e6
3 changed files with 28 additions and 58 deletions
82
main.ts
82
main.ts
|
|
@ -248,53 +248,39 @@ export default class SmartMemosPlugin extends Plugin {
|
|||
|
||||
|
||||
async findFilePath(text: string, regex: RegExp[]) {
|
||||
const fullPath = await this.getAttachmentDir().then((attachmentPath) => {
|
||||
let filename = '';
|
||||
let result: RegExpExecArray | null;
|
||||
for (const reg of regex) {
|
||||
while ((result = reg.exec(text)) !== null) {
|
||||
filename = normalizePath(decodeURI(result[0])).trim();
|
||||
}
|
||||
console.log('dir text: ', text);
|
||||
|
||||
let filename = '';
|
||||
let result: RegExpExecArray | null;
|
||||
|
||||
// Extract the filename using the provided regex patterns
|
||||
for (const reg of regex) {
|
||||
while ((result = reg.exec(text)) !== null) {
|
||||
filename = normalizePath(decodeURI(result[0])).trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename == '') throw new Error('No file found in the text.');
|
||||
if (filename === '') throw new Error('No file found in the text.');
|
||||
|
||||
const fileInSpecificFolder = filename.includes('/');
|
||||
const AttInRootFolder = attachmentPath === '' || attachmentPath === '/';
|
||||
const AttInCurrentFolder = attachmentPath.startsWith('./');
|
||||
const AttInSpecificFolder = !AttInRootFolder && !AttInCurrentFolder;
|
||||
console.log('file name: ', filename);
|
||||
|
||||
let fullPath = '';
|
||||
// Use the filename directly as the full path
|
||||
const fullPath = filename;
|
||||
|
||||
if (AttInRootFolder || fileInSpecificFolder) fullPath = filename;
|
||||
else {
|
||||
if (AttInSpecificFolder) fullPath = attachmentPath + '/' + filename;
|
||||
if (AttInCurrentFolder) {
|
||||
const attFolder = attachmentPath.substring(2);
|
||||
if (attFolder.length == 0) fullPath = this.getCurrentPath() + '/' + filename;
|
||||
else fullPath = this.getCurrentPath() + '/' + attFolder + '/' + filename;
|
||||
}
|
||||
}
|
||||
console.log('full path: ', fullPath);
|
||||
|
||||
// Check if the file exists in the constructed path
|
||||
const exists = this.app.vault.getAbstractFileByPath(fullPath) instanceof TAbstractFile;
|
||||
if (exists) return fullPath;
|
||||
else {
|
||||
// If not found, search through all files in the vault
|
||||
let path = '';
|
||||
let found = false;
|
||||
this.app.vault.getFiles().forEach((file) => {
|
||||
if (file.name === filename.split('/').pop()) {
|
||||
path = file.path;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (found) return path;
|
||||
else throw new Error('File not found');
|
||||
}
|
||||
});
|
||||
return fullPath as string;
|
||||
// Check if the file exists at the constructed path
|
||||
const fileExists = this.app.vault.getAbstractFileByPath(fullPath) instanceof TAbstractFile;
|
||||
if (fileExists) return fullPath;
|
||||
|
||||
// If not found, search through all files in the vault
|
||||
const allFiles = this.app.vault.getFiles();
|
||||
const foundFile = allFiles.find(file => file.name === filename.split('/').pop());
|
||||
if (foundFile) return foundFile.path;
|
||||
|
||||
throw new Error('File not found');
|
||||
}
|
||||
|
||||
|
||||
async generateTranscript(audioBuffer: ArrayBuffer, filetype: string) {
|
||||
if (this.settings.apiKey.length <= 1) throw new Error('OpenAI API Key is not provided.');
|
||||
|
|
@ -366,22 +352,6 @@ export default class SmartMemosPlugin extends Plugin {
|
|||
return results.join(' ');
|
||||
}
|
||||
|
||||
async getAttachmentDir() {
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
if (!activeFile) throw new Error('No active file');
|
||||
const dir = this.app.vault.getAvailablePathForAttachments(activeFile.basename, activeFile?.extension, activeFile); // getAvailablePathForAttachments is undocumented
|
||||
console.log('dir: ', dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
getCurrentPath() {
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
if (!activeFile) throw new Error('No active file');
|
||||
const currentPath = activeFile.path.split('/');
|
||||
currentPath.pop();
|
||||
const currentPathString = currentPath.join('/');
|
||||
return currentPathString;
|
||||
}
|
||||
|
||||
|
||||
async generateText(prompt: string, editor: Editor, currentLn: number, contextPrompt?: string) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "smart-memos",
|
||||
"name": "Smart Memos",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Create personalized and intelligent analysis, summaries, and more for audio recordings that can be imported or spoken directly into a note",
|
||||
"author": "Evan Moscoso",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "smart-memos",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"description": "Create personalized and intelligent analysis, summaries, and more for audio recordings that can be imported or spoken directly into a note",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue