mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
Cookie Support (#19)
This commit is contained in:
@@ -3,6 +3,7 @@ import { invoke } from '@tauri-apps/api';
|
||||
export function trackEvent(
|
||||
resource:
|
||||
| 'App'
|
||||
| 'CookieJar'
|
||||
| 'Sidebar'
|
||||
| 'Workspace'
|
||||
| 'Environment'
|
||||
|
||||
@@ -9,7 +9,14 @@ export const AUTH_TYPE_NONE = null;
|
||||
export const AUTH_TYPE_BASIC = 'basic';
|
||||
export const AUTH_TYPE_BEARER = 'bearer';
|
||||
|
||||
export type Model = Settings | Workspace | HttpRequest | HttpResponse | KeyValue | Environment;
|
||||
export type Model =
|
||||
| Settings
|
||||
| Workspace
|
||||
| HttpRequest
|
||||
| HttpResponse
|
||||
| KeyValue
|
||||
| Environment
|
||||
| CookieJar;
|
||||
|
||||
export interface BaseModel {
|
||||
readonly id: string;
|
||||
@@ -34,6 +41,33 @@ export interface Workspace extends BaseModel {
|
||||
settingRequestTimeout: number;
|
||||
}
|
||||
|
||||
export interface CookieJar extends BaseModel {
|
||||
readonly model: 'cookie_jar';
|
||||
workspaceId: string;
|
||||
name: string;
|
||||
cookies: Cookie[];
|
||||
}
|
||||
|
||||
export interface Cookie {
|
||||
raw_cookie: string;
|
||||
domain: { HostOnly: string } | { Suffix: string } | 'NotPresent' | 'Empty';
|
||||
expires: { AtUtc: string } | 'SessionEnd';
|
||||
path: [string, boolean];
|
||||
}
|
||||
|
||||
export function cookieDomain(cookie: Cookie): string {
|
||||
if (cookie.domain === 'NotPresent' || cookie.domain === 'Empty') {
|
||||
return 'n/a';
|
||||
}
|
||||
if ('HostOnly' in cookie.domain) {
|
||||
return cookie.domain.HostOnly;
|
||||
}
|
||||
if ('Suffix' in cookie.domain) {
|
||||
return cookie.domain.Suffix;
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
export interface EnvironmentVariable {
|
||||
name: string;
|
||||
value: string;
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { Environment, Folder, HttpRequest, Settings, Workspace } from './models';
|
||||
import type {
|
||||
Cookie,
|
||||
CookieJar,
|
||||
Environment,
|
||||
Folder,
|
||||
HttpRequest,
|
||||
Settings,
|
||||
Workspace,
|
||||
} from './models';
|
||||
|
||||
export async function getSettings(): Promise<Settings> {
|
||||
return invoke('get_settings', {});
|
||||
@@ -40,3 +48,12 @@ export async function getWorkspace(id: string | null): Promise<Workspace | null>
|
||||
}
|
||||
return workspace;
|
||||
}
|
||||
|
||||
export async function getCookieJar(id: string | null): Promise<CookieJar | null> {
|
||||
if (id === null) return null;
|
||||
const cookieJar: CookieJar = (await invoke('get_cookie_jar', { id })) ?? null;
|
||||
if (cookieJar == null) {
|
||||
return null;
|
||||
}
|
||||
return cookieJar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user