Skip to content

Commit

Permalink
Merge pull request #21 from djmango/login_timeout_fix
Browse files Browse the repository at this point in the history
🐛 (Auth) Fix auth timeout not prompting users to login again
  • Loading branch information
djmango authored Oct 3, 2023
2 parents d1ebd43 + c3946ca commit 9838f08
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
});
};
Expand Down
12 changes: 6 additions & 6 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -389,4 +389,4 @@ class TranscriptionSettingTab extends PluginSettingTab {
}

export type { TranscriptionSettings };
export { DEFAULT_SETTINGS, TranscriptionSettingTab };
export { DEFAULT_SETTINGS, SWIFTINK_AUTH_CALLBACK, TranscriptionSettingTab };
21 changes: 13 additions & 8 deletions src/transcribe.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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, "-");
Expand Down
47 changes: 24 additions & 23 deletions versions.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 9838f08

Please sign in to comment.