mirror of
https://github.com/mossy1022/Smart-Memos.git
synced 2026-07-22 05:16:24 +00:00
Attempt to make iOS Compatible
This commit is contained in:
parent
73da7f05d6
commit
0a4e4c94ef
4 changed files with 69 additions and 50 deletions
15
Utils.ts
15
Utils.ts
|
|
@ -1,10 +1,11 @@
|
|||
import { App, TFile, TFolder } from 'obsidian';
|
||||
import { App, TFile, TFolder, normalizePath } from 'obsidian';
|
||||
|
||||
export async function saveFile(app: App, audioBlob: Blob, fileName: string, path: string): Promise<TFile> {
|
||||
try {
|
||||
const filePath = `${path}/${fileName}`;
|
||||
const normalizedPath = normalizePath(path);
|
||||
const filePath = `${normalizedPath}/${fileName}`;
|
||||
|
||||
await directoryExistsAtPath(app, path);
|
||||
await ensureDirectoryExists(app, normalizedPath);
|
||||
|
||||
const arrayBuffer = await audioBlob.arrayBuffer();
|
||||
const uint8Array = new Uint8Array(arrayBuffer);
|
||||
|
|
@ -20,12 +21,13 @@ export async function saveFile(app: App, audioBlob: Blob, fileName: string, path
|
|||
}
|
||||
}
|
||||
|
||||
async function directoryExistsAtPath(app: App, folderPath: string) {
|
||||
async function ensureDirectoryExists(app: App, folderPath: string) {
|
||||
const parts = folderPath.split('/');
|
||||
let currentPath = '';
|
||||
|
||||
for (const part of parts) {
|
||||
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
||||
|
||||
try {
|
||||
const folder = app.vault.getAbstractFileByPath(currentPath);
|
||||
if (!folder) {
|
||||
|
|
@ -36,8 +38,13 @@ async function directoryExistsAtPath(app: App, folderPath: string) {
|
|||
throw new Error(`${currentPath} is not a folder`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.message.includes('Folder already exists')) {
|
||||
// Folder already exists, continue to the next part
|
||||
console.log(`Handled existing folder: ${currentPath}`);
|
||||
} else {
|
||||
console.error(`Error ensuring directory exists: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
main.ts
28
main.ts
|
|
@ -111,7 +111,6 @@ export default class SmartMemosPlugin extends Plugin {
|
|||
// Add a new method to handle the audio recording and processing
|
||||
async handleAudioRecording(audioFile: Blob, transcribe: boolean) {
|
||||
try {
|
||||
|
||||
console.log('Handling audio recording:', audioFile);
|
||||
|
||||
if (!audioFile) {
|
||||
|
|
@ -121,7 +120,6 @@ export default class SmartMemosPlugin extends Plugin {
|
|||
|
||||
this.audioFile = audioFile;
|
||||
|
||||
|
||||
// Save the audio recording as a .wav file
|
||||
const fileName = `recording-${Date.now()}.wav`;
|
||||
const file = await saveFile(this.app, this.audioFile, fileName, this.appJsonObj.attachmentFolderPath);
|
||||
|
|
@ -142,6 +140,7 @@ export default class SmartMemosPlugin extends Plugin {
|
|||
if (transcribe) {
|
||||
this.transcribeRecording(file);
|
||||
}
|
||||
|
||||
// Handle the saved audio file
|
||||
// You can replace this with your own handling logic
|
||||
console.log(file);
|
||||
|
|
@ -300,25 +299,37 @@ async transcribeRecording(audioFile: TFile) {
|
|||
async findFilePath(text: string, regex: RegExp[]) {
|
||||
let filename = '';
|
||||
let result: RegExpExecArray | null;
|
||||
|
||||
// Find 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.');
|
||||
}
|
||||
|
||||
|
||||
// Use the attachment folder path from the plugin settings
|
||||
// Check if the filename already contains the attachment folder path
|
||||
let fullPath;
|
||||
if (filename.includes(this.appJsonObj.attachmentFolderPath)) {
|
||||
fullPath = filename;
|
||||
console.log('full path 1: ', fullPath);
|
||||
} else {
|
||||
// Use the attachment folder path from the plugin settings
|
||||
fullPath = this.appJsonObj.attachmentFolderPath + '/' + filename;
|
||||
|
||||
// Ensure no leading or trailing slashes in the attachment folder path and filename
|
||||
const folderPath = this.appJsonObj.attachmentFolderPath.replace(/\/$/, ''); // Remove trailing slash if any
|
||||
const filePath = filename.replace(/^\//, ''); // Remove leading slash if any
|
||||
|
||||
// Construct the full path
|
||||
fullPath = `${folderPath}/${filePath}`;
|
||||
fullPath = normalizePath(fullPath); // Normalize the full path
|
||||
|
||||
console.log('fill path 2: ', fullPath);
|
||||
|
||||
}
|
||||
|
||||
// Attempt to find the file in the vault
|
||||
const file = this.app.vault.getAbstractFileByPath(fullPath);
|
||||
if (file instanceof TFile) {
|
||||
return file;
|
||||
|
|
@ -327,6 +338,7 @@ async transcribeRecording(audioFile: TFile) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
async generateText(prompt: string, editor: Editor, currentLn: number, contextPrompt?: string) {
|
||||
if (prompt.length < 1) throw new Error('Cannot find prompt.');
|
||||
if ( this.settings.apiKey.length <= 1) throw new Error('OpenAI API Key is not provided.');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "smart-memos",
|
||||
"name": "Smart Memos",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"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.0",
|
||||
"version": "1.1.1",
|
||||
"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