tauri-kargo-tools 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/api.ts +28 -10
  2. package/package.json +1 -1
package/dist/api.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // dist/client.ts
2
- import * as T from "./types.ts";
2
+ import * as T from "./types";
3
3
 
4
4
  export type FetchLike = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
5
5
 
@@ -125,15 +125,33 @@ export class TauriKargoClient {
125
125
  }
126
126
 
127
127
  /** Écrire un fichier binaire */
128
- async writeFileBinary(file: string, data: ArrayBuffer | Uint8Array): Promise<T.FileWriteResp> {
129
- const body = data instanceof Uint8Array ? data : new Uint8Array(data);
130
- const res = await this.req(`/api/file/${encodeURIComponent(file)}`, {
131
- method: "POST",
132
- headers: { "content-type": "application/octet-stream" },
133
- body,
134
- });
135
- return this.parseJsonOrThrow<T.FileWriteResp>(res);
136
- }
128
+ async writeFileBinary(
129
+ file: string,
130
+ data: Blob
131
+ ): Promise<T.FileWriteResp> {
132
+ // Normalise en Blob (OK WebView2/WebKit/Chromium)
133
+ const blob = data
134
+
135
+ const res = await fetch(`${this.baseUrl}/api/file/${encodeURIComponent(file)}`, {
136
+ method: "POST",
137
+ // Laisser fetch gérer le Content-Length; Content-Type vient du blob
138
+ headers: { "content-type": blob.type || "application/octet-stream" },
139
+ body: blob,
140
+ });
141
+
142
+ if (!res.ok) {
143
+ const text = await res.text().catch(() => "<no-body>");
144
+ throw new Error(`WRITE ${file} failed: ${res.status} ${text}`);
145
+ }
146
+
147
+ // La route renvoie du JSON en cas d’écriture
148
+ const ct = res.headers.get("content-type") || "";
149
+ if (ct.includes("application/json")) {
150
+ return (await res.json()) as T.FileWriteResp;
151
+ }
152
+ // Fallback s'il répond "text/plain" avec un JSON sérialisé
153
+ return JSON.parse(await res.text()) as T.FileWriteResp;
154
+ }
137
155
 
138
156
  /** DELETE /api/file/{file} */
139
157
  async deleteFile(file: string): Promise<T.FileDeleteResp> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-kargo-tools",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "",
5
5
  "files": ["dist"],
6
6
  "exports": { "./*": "./dist/*" },