|
1 | 1 | import { invoke } from '@tauri-apps/api/tauri'; |
2 | 2 | import * as commands from './commands'; |
3 | | -import { AccessToken } from './commands'; |
| 3 | +import { AccessToken, SaveAccessTokenResponse, SaveTokenResponse } from './commands'; |
| 4 | +import StoreDb from './StoreDb'; |
| 5 | +import settings from '../config/settings'; |
| 6 | + |
| 7 | + |
| 8 | +const storeConstant = settings.storage.constants; |
| 9 | + |
| 10 | +export async function save_auth_code(code: string) : Promise<SaveTokenResponse> { |
| 11 | + // return await commands.saveCode(code); |
| 12 | + await StoreDb.set(storeConstant.authcode, code); |
| 13 | + return { message: "Code saved", token: code, success: true }; |
| 14 | + |
4 | 15 |
|
5 | | -export async function save_auth_code(code: string) { |
6 | | - return await commands.saveCode(code); |
7 | 16 | } |
8 | 17 |
|
9 | | -export async function get_auth_code() { |
10 | | - return await commands.loadCode(); |
| 18 | +export async function get_auth_code() : Promise<string> { |
| 19 | + // return await commands.loadCode(); |
| 20 | + return await StoreDb.get<string>(storeConstant.authcode) ?? ""; |
| 21 | + |
11 | 22 | } |
12 | 23 |
|
13 | | -export async function save_access_token(token: string|AccessToken) { |
14 | | - const accessTokenText: string = typeof token === "string" ? token : JSON.stringify(token, null, 2); |
15 | | - return await commands.saveAccessToken(accessTokenText); |
| 24 | +export async function save_access_token(token: string|AccessToken) : Promise<SaveAccessTokenResponse> { |
| 25 | + const accessTokenText: AccessToken = typeof token === "string" ? JSON.parse(token) : token; |
| 26 | + // return await commands.saveAccessToken(accessTokenText); |
| 27 | + await StoreDb.set(storeConstant.access_token, accessTokenText); |
| 28 | + return { message: "Token saved", success: true, token: token as AccessToken }; |
16 | 29 | } |
17 | 30 |
|
18 | | -export async function get_access_token() { |
19 | | - return await commands.loadAccessToken(); |
| 31 | +export async function get_access_token() : Promise<AccessToken> { |
| 32 | + // return await commands.loadAccessToken(); |
| 33 | + return await StoreDb.get<AccessToken>(storeConstant.access_token) ?? {} as AccessToken; |
20 | 34 | } |
21 | 35 |
|
22 | 36 | export async function test_command() { |
|
0 commit comments