diff --git a/manifest.json b/manifest.json index 9dfee6e..6f36ce5 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-transcription", "name": "Transcription", - "version": "3.1.3", + "version": "3.1.4", "minAppVersion": "0.15.0", "description": "Transcription 3.0, now with Swiftink.io domain-aware speech-to-text! Create high-quality text transcriptions from any media file, on any device. Best-in-class ASR", "author": "djmango", diff --git a/package.json b/package.json index 73c6bbc..888d4b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-transcription", - "version": "3.1.3", + "version": "3.1.4", "description": "Obsidian plugin to create high-quality text transcriptions from any media file, on any device", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 646073a..92073c1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -173,14 +173,18 @@ export default class Transcription extends Plugin { }) .catch((error) => { // First check if 402 is in the error message, if so alert the user that they need to pay - if (error && error.message.includes("402")) { + if ( + error && + error.message && + error.message.includes("402") + ) { new Notice( "You have exceeded the free tier. Please upgrade to a paid plan at swiftink.io/pricing to continue transcribing files. Thanks for using Swiftink!", 10000, ); } else { if (this.settings.debug) console.log(error); - new Notice(`Error transcribing file: ${error.message}`); + new Notice(`Error transcribing file: ${error}`); } }); }; diff --git a/src/settings.ts b/src/settings.ts index 536f41f..5926f9e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -29,6 +29,10 @@ const DEFAULT_SETTINGS: TranscriptionSettings = { embedKeywords: true, }; +const SWIFTINK_AUTH_CALLBACK = + "https://swiftink.io/login/?callback=obsidian://swiftink_auth"; +// "http://localhost:4200/login/?callback=obsidian://swiftink_auth", + class TranscriptionSettingTab extends PluginSettingTab { plugin: Transcription; @@ -120,11 +124,7 @@ class TranscriptionSettingTab extends PluginSettingTab { bt.setButtonText("Sign in with Email"); bt.setClass("swiftink-unauthed-only"); bt.onClick(async () => { - window.open( - "https://swiftink.io/login/?callback=obsidian://swiftink_auth", - // "http://localhost:4200/login/?callback=obsidian://swiftink_auth", - "_blank", - ); + window.open(SWIFTINK_AUTH_CALLBACK, "_blank"); }); }) .addButton((bt) => { @@ -389,4 +389,4 @@ class TranscriptionSettingTab extends PluginSettingTab { } export type { TranscriptionSettings }; -export { DEFAULT_SETTINGS, TranscriptionSettingTab }; +export { DEFAULT_SETTINGS, SWIFTINK_AUTH_CALLBACK, TranscriptionSettingTab }; diff --git a/src/transcribe.ts b/src/transcribe.ts index d41c4b2..613aba7 100644 --- a/src/transcribe.ts +++ b/src/transcribe.ts @@ -1,4 +1,4 @@ -import { TranscriptionSettings } from "src/settings"; +import { TranscriptionSettings, SWIFTINK_AUTH_CALLBACK } from "src/settings"; import { Notice, requestUrl, RequestUrlParam, TFile, Vault } from "obsidian"; import { format } from "date-fns"; import { paths, components } from "./types/swiftink"; @@ -127,14 +127,19 @@ export class TranscriptionEngine { // const api_base = 'http://localhost:8000' const api_base = "https://api.swiftink.io"; - const token = await this.supabase.auth.getSession().then((res) => { - return res.data?.session?.access_token; + const session = await this.supabase.auth.getSession().then((res) => { + return res.data; }); - const id = await this.supabase.auth.getSession().then((res) => { - return res.data?.session?.user?.id; - }); - if (token === undefined) return Promise.reject("No token found"); - if (id === undefined) return Promise.reject("No user id found"); + + if (session == null || session.session == null) { + window.open(SWIFTINK_AUTH_CALLBACK, "_blank"); + return Promise.reject( + "No user session found. Please log in and try again.", + ); + } + + const token = session.session.access_token; + const id = session.session.user.id; const fileStream = await this.vault.readBinary(file); const filename = file.name.replace(/[^a-zA-Z0-9.]+/g, "-"); diff --git a/versions.json b/versions.json index 8c976b5..b667f19 100644 --- a/versions.json +++ b/versions.json @@ -1,25 +1,26 @@ { - "1.0.0": "0.15.0", - "1.0.0": "0.15.0", - "1.0.0": "0.15.0", - "1.0.0": "0.15.0", - "1.0.2": "0.15.0", - "1.0.3": "0.15.0", - "2.0.0": "0.15.0", - "2.0.1": "0.15.0", - "2.0.1": "0.15.0", - "2.0.3": "0.15.0", - "2.2.2": "0.15.0", - "2.2.3": "0.15.0", - "3.0.0": "0.15.0", - "3.0.1": "0.15.0", - "3.0.2": "0.15.0", - "3.0.3": "0.15.0", - "3.0.4": "0.15.0", - "3.0.5": "0.15.0", - "3.0.6": "0.15.0", - "3.1.0": "0.15.0", - "3.1.1": "0.15.0", - "3.1.2": "0.15.0", - "3.1.3": "0.15.0" + "1.0.0": "0.15.0", + "1.0.0": "0.15.0", + "1.0.0": "0.15.0", + "1.0.0": "0.15.0", + "1.0.2": "0.15.0", + "1.0.3": "0.15.0", + "2.0.0": "0.15.0", + "2.0.1": "0.15.0", + "2.0.1": "0.15.0", + "2.0.3": "0.15.0", + "2.2.2": "0.15.0", + "2.2.3": "0.15.0", + "3.0.0": "0.15.0", + "3.0.1": "0.15.0", + "3.0.2": "0.15.0", + "3.0.3": "0.15.0", + "3.0.4": "0.15.0", + "3.0.5": "0.15.0", + "3.0.6": "0.15.0", + "3.1.0": "0.15.0", + "3.1.1": "0.15.0", + "3.1.2": "0.15.0", + "3.1.3": "0.15.0", + "3.1.4": "0.15.0" }