tauri-kargo-tools 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api.ts +33 -30
- package/src/test/index.ts +8 -0
- package/src/types.ts +5 -1
- package/src/vue-model.ts +16 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class TauriKargoClient {
|
|
|
21
21
|
|
|
22
22
|
constructor(opts: ClientOptions = {}) {
|
|
23
23
|
const port = opts.port ?? 8080;
|
|
24
|
-
this.baseUrl = opts.baseUrl ?? (opts.port
|
|
24
|
+
this.baseUrl = opts.baseUrl ?? (opts.port ? `http://127.0.0.1:${port}` : '');
|
|
25
25
|
this.headers = opts.headers ?? {};
|
|
26
26
|
this.fetchImpl = opts.fetchImpl ?? (globalThis.fetch?.bind(globalThis) as FetchLike);
|
|
27
27
|
if (!this.fetchImpl) throw new Error("No fetch implementation available.");
|
|
@@ -29,7 +29,7 @@ export class TauriKargoClient {
|
|
|
29
29
|
|
|
30
30
|
/* =============== Helpers HTTP =============== */
|
|
31
31
|
|
|
32
|
-
private
|
|
32
|
+
private req(path: string, init: RequestInit): Promise<Response> {
|
|
33
33
|
const url = this.baseUrl + path;
|
|
34
34
|
const headers = { ...this.headers, ...(init.headers || {}) } as Record<string, string>;
|
|
35
35
|
return this.fetchImpl(url, { ...init, headers });
|
|
@@ -91,7 +91,10 @@ export class TauriKargoClient {
|
|
|
91
91
|
setCurrentDirectory(body: T.CurrentDirReq): Promise<T.CurrentDirResp> {
|
|
92
92
|
return this.postJson<T.CurrentDirResp>("/api/current-directory", body);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
/**POST /api/directory/create*/
|
|
95
|
+
createDirectory(path: string): Promise<T.CreateDirResp> {
|
|
96
|
+
return this.postJson<T.CreateDirResp>("/api/directory/create", { path: path });
|
|
97
|
+
}
|
|
95
98
|
/**
|
|
96
99
|
* Lire un fichier texte relatif au répertoire courant.
|
|
97
100
|
* (POST sans corps ⇒ READ ; renvoie text/plain ou octet-stream)
|
|
@@ -125,33 +128,33 @@ export class TauriKargoClient {
|
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
/** Écrire un fichier binaire */
|
|
128
|
-
async writeFileBinary(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
): Promise<T.FileWriteResp> {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
131
|
+
async writeFileBinary(
|
|
132
|
+
file: string,
|
|
133
|
+
data: Blob
|
|
134
|
+
): Promise<T.FileWriteResp> {
|
|
135
|
+
// Normalise en Blob (OK WebView2/WebKit/Chromium)
|
|
136
|
+
const blob = data
|
|
137
|
+
|
|
138
|
+
const res = await fetch(`${this.baseUrl}/api/file/${encodeURIComponent(file)}`, {
|
|
139
|
+
method: "POST",
|
|
140
|
+
// Laisser fetch gérer le Content-Length; Content-Type vient du blob
|
|
141
|
+
headers: { "content-type": blob.type || "application/octet-stream" },
|
|
142
|
+
body: blob,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (!res.ok) {
|
|
146
|
+
const text = await res.text().catch(() => "<no-body>");
|
|
147
|
+
throw new Error(`WRITE ${file} failed: ${res.status} ${text}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// La route renvoie du JSON en cas d’écriture
|
|
151
|
+
const ct = res.headers.get("content-type") || "";
|
|
152
|
+
if (ct.includes("application/json")) {
|
|
153
|
+
return (await res.json()) as T.FileWriteResp;
|
|
154
|
+
}
|
|
155
|
+
// Fallback s'il répond "text/plain" avec un JSON sérialisé
|
|
156
|
+
return JSON.parse(await res.text()) as T.FileWriteResp;
|
|
157
|
+
}
|
|
155
158
|
|
|
156
159
|
/** DELETE /api/file/{file} */
|
|
157
160
|
async deleteFile(file: string): Promise<T.FileDeleteResp> {
|
package/src/test/index.ts
CHANGED
|
@@ -126,6 +126,14 @@ test.test("Test read file", async () => {
|
|
|
126
126
|
|
|
127
127
|
}), false, "pas dans rep")
|
|
128
128
|
}
|
|
129
|
+
const repCreateDir = await client.createDirectory("toto/titi");
|
|
130
|
+
rep = await client.explorer({})
|
|
131
|
+
if (rep.type === "directory") {
|
|
132
|
+
test.assertEquals(rep.content.some((e) => e.name === "toto"), true)
|
|
133
|
+
|
|
134
|
+
} else {
|
|
135
|
+
throw new Error('error pas rep')
|
|
136
|
+
}
|
|
129
137
|
rep = await client.explorer({ type: "array", path: "C:/Users/david/Documents/GitHub/tauriKargoExamples/examples/test-api-file-typescript" })
|
|
130
138
|
console.log(rep)
|
|
131
139
|
|
package/src/types.ts
CHANGED
package/src/vue-model.ts
CHANGED
|
@@ -233,6 +233,22 @@ export class Vue<T extends object> {
|
|
|
233
233
|
return this;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/* ------------ Label ------------ */
|
|
237
|
+
staticLabel(label: string, opt?: {
|
|
238
|
+
/** Identifiants CSS/DOM */
|
|
239
|
+
id?: string; class?: string | string[];
|
|
240
|
+
width?: number | string; height?: number | string;
|
|
241
|
+
visible?: KeysOfType<T, boolean>; enable?: KeysOfType<T, boolean>;
|
|
242
|
+
useVisibility?: boolean;
|
|
243
|
+
}): this {
|
|
244
|
+
const node: StaticLabelNode<T>= {
|
|
245
|
+
kind: 'staticLabel',
|
|
246
|
+
label,
|
|
247
|
+
...opt
|
|
248
|
+
};
|
|
249
|
+
this.cursor.push(node as unknown as UINode<T>);
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
236
252
|
|
|
237
253
|
|
|
238
254
|
/* ------------ BootVue (label dynamique) ------------ */
|