web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit 63813081fc00aa98de5f2207aa1331e4c4fb8c6a
parent 6187afae3148bc37730afdf81eed54775b89c2b6
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Sat, 26 Oct 2024 19:53:02 +0000

client: add client fs open method

Diffstat:
Mclient/src/fs/tauri.ts | 15++++++++++++---
Mclient/src/fs/types.ts | 5+++++
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/client/src/fs/tauri.ts b/client/src/fs/tauri.ts @@ -1,10 +1,10 @@ -import { exists as fs_exists } from '@tauri-apps/plugin-fs'; -import type { IClientFs } from "./types"; +import { BaseDirectory, exists as fs_exists, open as fs_open } from '@tauri-apps/plugin-fs'; +import type { IClientFs, IClientFsOpenResult } from "./types"; export class TauriClientFs implements IClientFs { public async exists(path: string): Promise<boolean> { try { - const res = await fs_exists(path); + const res = await fs_exists(path, { baseDir: BaseDirectory.AppData }); return res; } catch (e) { console.log(`e exists`, e) @@ -12,4 +12,13 @@ export class TauriClientFs implements IClientFs { }; } + public async open(path: string): Promise<IClientFsOpenResult | undefined> { + try { + const res = await fs_open(path, { read: true, baseDir: BaseDirectory.AppData }); + return res; + } catch (e) { + console.log(`e open`, e) + return undefined; + }; + } } diff --git a/client/src/fs/types.ts b/client/src/fs/types.ts @@ -1,3 +1,8 @@ +import type { FileHandle } from "@tauri-apps/plugin-fs"; + +export type IClientFsOpenResult = FileHandle; + export type IClientFs = { exists(path: string): Promise<boolean>; + open(path: string): Promise<IClientFsOpenResult | undefined>; }; \ No newline at end of file