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.
- package/dist/api.ts +28 -10
- 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
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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> {
|