mirror of
https://github.com/tauri-apps/tauri-plugin-http.git
synced 2026-01-31 00:45:17 +01:00
fix(updater): Use escaped installer path to start the nsis updater (#727)
Port of v1 change: https://github.com/tauri-apps/tauri/pull/7956 Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/6877612128 Co-authored-by: amrbashir <amrbashir@users.noreply.github.com>
This commit is contained in:
83
dist-js/index.cjs
Normal file
83
dist-js/index.cjs
Normal file
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
var primitives = require('@tauri-apps/api/primitives');
|
||||
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
/**
|
||||
* Make HTTP requests with the Rust backend.
|
||||
*
|
||||
* ## Security
|
||||
*
|
||||
* This API has a scope configuration that forces you to restrict the URLs and paths that can be accessed using glob patterns.
|
||||
*
|
||||
* For instance, this scope configuration only allows making HTTP requests to the GitHub API for the `tauri-apps` organization:
|
||||
* ```json
|
||||
* {
|
||||
* "plugins": {
|
||||
* "http": {
|
||||
* "scope": ["https://api.github.com/repos/tauri-apps/*"]
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
* Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
/**
|
||||
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
||||
* `Response` to that `Request`, whether it is successful or not.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const response = await fetch("http://my.json.host/data.json");
|
||||
* console.log(response.status); // e.g. 200
|
||||
* console.log(response.statusText); // e.g. "OK"
|
||||
* const jsonData = await response.json();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function fetch(input, init) {
|
||||
const maxRedirections = init?.maxRedirections;
|
||||
const connectTimeout = init?.maxRedirections;
|
||||
// Remove these fields before creating the request
|
||||
if (init) {
|
||||
delete init.maxRedirections;
|
||||
delete init.connectTimeout;
|
||||
}
|
||||
const req = new Request(input, init);
|
||||
const buffer = await req.arrayBuffer();
|
||||
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
||||
const rid = await primitives.invoke("plugin:http|fetch", {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
headers: Array.from(req.headers.entries()),
|
||||
data: reqData,
|
||||
maxRedirections,
|
||||
connectTimeout,
|
||||
});
|
||||
req.signal.addEventListener("abort", () => {
|
||||
primitives.invoke("plugin:http|fetch_cancel", {
|
||||
rid,
|
||||
});
|
||||
});
|
||||
const { status, statusText, url, headers } = await primitives.invoke("plugin:http|fetch_send", {
|
||||
rid,
|
||||
});
|
||||
const body = await primitives.invoke("plugin:http|fetch_read_body", {
|
||||
rid,
|
||||
});
|
||||
const res = new Response(new Uint8Array(body), {
|
||||
headers,
|
||||
status,
|
||||
statusText,
|
||||
});
|
||||
// url is read only but seems like we can do this
|
||||
Object.defineProperty(res, "url", { value: url });
|
||||
return res;
|
||||
}
|
||||
|
||||
exports.fetch = fetch;
|
||||
@@ -39,8 +39,8 @@ import { invoke } from '@tauri-apps/api/primitives';
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function fetch(input, init) {
|
||||
const maxRedirections = init === null || init === void 0 ? void 0 : init.maxRedirections;
|
||||
const connectTimeout = init === null || init === void 0 ? void 0 : init.maxRedirections;
|
||||
const maxRedirections = init?.maxRedirections;
|
||||
const connectTimeout = init?.maxRedirections;
|
||||
// Remove these fields before creating the request
|
||||
if (init) {
|
||||
delete init.maxRedirections;
|
||||
@@ -79,4 +79,3 @@ async function fetch(input, init) {
|
||||
}
|
||||
|
||||
export { fetch };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
121
dist-js/index.min.js
vendored
121
dist-js/index.min.js
vendored
@@ -1,121 +0,0 @@
|
||||
/******************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
/* global Reflect, Promise, SuppressedError, Symbol */
|
||||
|
||||
|
||||
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
||||
var e = new Error(message);
|
||||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a message to the backend.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { invoke } from '@tauri-apps/api/primitives';
|
||||
* await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
|
||||
* ```
|
||||
*
|
||||
* @param cmd The command name.
|
||||
* @param args The optional arguments to pass to the command.
|
||||
* @param options The request options.
|
||||
* @return A promise resolving or rejecting to the backend response.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function invoke(cmd, args = {}, options) {
|
||||
return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
|
||||
}
|
||||
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
/**
|
||||
* Make HTTP requests with the Rust backend.
|
||||
*
|
||||
* ## Security
|
||||
*
|
||||
* This API has a scope configuration that forces you to restrict the URLs and paths that can be accessed using glob patterns.
|
||||
*
|
||||
* For instance, this scope configuration only allows making HTTP requests to the GitHub API for the `tauri-apps` organization:
|
||||
* ```json
|
||||
* {
|
||||
* "plugins": {
|
||||
* "http": {
|
||||
* "scope": ["https://api.github.com/repos/tauri-apps/*"]
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
* Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
/**
|
||||
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
||||
* `Response` to that `Request`, whether it is successful or not.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const response = await fetch("http://my.json.host/data.json");
|
||||
* console.log(response.status); // e.g. 200
|
||||
* console.log(response.statusText); // e.g. "OK"
|
||||
* const jsonData = await response.json();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function fetch(input, init) {
|
||||
const maxRedirections = init === null || init === void 0 ? void 0 : init.maxRedirections;
|
||||
const connectTimeout = init === null || init === void 0 ? void 0 : init.maxRedirections;
|
||||
// Remove these fields before creating the request
|
||||
if (init) {
|
||||
delete init.maxRedirections;
|
||||
delete init.connectTimeout;
|
||||
}
|
||||
const req = new Request(input, init);
|
||||
const buffer = await req.arrayBuffer();
|
||||
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
||||
const rid = await invoke("plugin:http|fetch", {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
headers: Array.from(req.headers.entries()),
|
||||
data: reqData,
|
||||
maxRedirections,
|
||||
connectTimeout,
|
||||
});
|
||||
req.signal.addEventListener("abort", () => {
|
||||
invoke("plugin:http|fetch_cancel", {
|
||||
rid,
|
||||
});
|
||||
});
|
||||
const { status, statusText, url, headers } = await invoke("plugin:http|fetch_send", {
|
||||
rid,
|
||||
});
|
||||
const body = await invoke("plugin:http|fetch_read_body", {
|
||||
rid,
|
||||
});
|
||||
const res = new Response(new Uint8Array(body), {
|
||||
headers,
|
||||
status,
|
||||
statusText,
|
||||
});
|
||||
// url is read only but seems like we can do this
|
||||
Object.defineProperty(res, "url", { value: url });
|
||||
return res;
|
||||
}
|
||||
|
||||
export { fetch };
|
||||
//# sourceMappingURL=index.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.mjs","sources":["../guest-js/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AAmBH;;;;;;;;;;;;;AAaG;AACI,eAAe,KAAK,CACzB,KAA6B,EAC7B,IAAkC,EAAA;IAElC,MAAM,eAAe,GAAG,IAAI,KAAA,IAAA,IAAJ,IAAI,KAAJ,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,IAAI,CAAE,eAAe,CAAC;IAC9C,MAAM,cAAc,GAAG,IAAI,KAAA,IAAA,IAAJ,IAAI,KAAJ,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,IAAI,CAAE,eAAe,CAAC;;AAG7C,IAAA,IAAI,IAAI,EAAE;QACR,OAAO,IAAI,CAAC,eAAe,CAAC;QAC5B,OAAO,IAAI,CAAC,cAAc,CAAC;AAC5B,KAAA;IAED,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACrC,IAAA,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;AAE9E,IAAA,MAAM,GAAG,GAAG,MAAM,MAAM,CAAS,mBAAmB,EAAE;QACpD,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAC1C,QAAA,IAAI,EAAE,OAAO;QACb,eAAe;QACf,cAAc;AACf,KAAA,CAAC,CAAC;IAEH,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAK;QACxC,MAAM,CAAC,0BAA0B,EAAE;YACjC,GAAG;AACJ,SAAA,CAAC,CAAC;AACL,KAAC,CAAC,CAAC;AASH,IAAA,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CACvD,wBAAwB,EACxB;QACE,GAAG;AACJ,KAAA,CACF,CAAC;AAEF,IAAA,MAAM,IAAI,GAAG,MAAM,MAAM,CAAW,6BAA6B,EAAE;QACjE,GAAG;AACJ,KAAA,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;QAC7C,OAAO;QACP,MAAM;QACN,UAAU;AACX,KAAA,CAAC,CAAC;;AAGH,IAAA,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AAElD,IAAA,OAAO,GAAG,CAAC;AACb;;;;"}
|
||||
1
node_modules/tslib
generated
vendored
1
node_modules/tslib
generated
vendored
@@ -1 +0,0 @@
|
||||
../../../node_modules/.pnpm/tslib@2.6.2/node_modules/tslib
|
||||
11
package.json
11
package.json
@@ -6,26 +6,19 @@
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
],
|
||||
"type": "module",
|
||||
"browser": "dist-js/index.min.js",
|
||||
"module": "dist-js/index.mjs",
|
||||
"types": "dist-js/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist-js/index.mjs",
|
||||
"types": "./dist-js/index.d.ts",
|
||||
"browser": "./dist-js/index.min.js"
|
||||
"import": "./dist-js/index.js",
|
||||
"require": "./dist-js/index.cjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"files": [
|
||||
"dist-js",
|
||||
"!dist-js/**/*.map",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"devDependencies": {
|
||||
"tslib": "2.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "2.0.0-alpha.11"
|
||||
}
|
||||
|
||||
7
rollup.config.js
Normal file
7
rollup.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { createConfig } from "../../shared/rollup.config.js";
|
||||
|
||||
export default createConfig();
|
||||
@@ -1,11 +0,0 @@
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
import { createConfig } from "../../shared/rollup.config.mjs";
|
||||
|
||||
export default createConfig({
|
||||
input: "guest-js/index.ts",
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_HTTP__=function(e){"use strict";async function t(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}return"function"==typeof SuppressedError&&SuppressedError,e.fetch=async function(e,n){const r=null==n?void 0:n.maxRedirections,i=null==n?void 0:n.maxRedirections;n&&(delete n.maxRedirections,delete n.connectTimeout);const a=new Request(e,n),s=await a.arrayBuffer(),o=s.byteLength?Array.from(new Uint8Array(s)):null,u=await t("plugin:http|fetch",{method:a.method,url:a.url,headers:Array.from(a.headers.entries()),data:o,maxRedirections:r,connectTimeout:i});a.signal.addEventListener("abort",(()=>{t("plugin:http|fetch_cancel",{rid:u})}));const{status:d,statusText:c,url:_,headers:l}=await t("plugin:http|fetch_send",{rid:u}),f=await t("plugin:http|fetch_read_body",{rid:u}),h=new Response(new Uint8Array(f),{headers:l,status:d,statusText:c});return Object.defineProperty(h,"url",{value:_}),h},e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_HTTP__})}
|
||||
if("__TAURI__"in window){var __TAURI_PLUGIN_HTTP__=function(e){"use strict";async function t(e,t={},r){return window.__TAURI_INTERNALS__.invoke(e,t,r)}return"function"==typeof SuppressedError&&SuppressedError,e.fetch=async function(e,r){const n=r?.maxRedirections,i=r?.maxRedirections;r&&(delete r.maxRedirections,delete r.connectTimeout);const a=new Request(e,r),s=await a.arrayBuffer(),o=s.byteLength?Array.from(new Uint8Array(s)):null,u=await t("plugin:http|fetch",{method:a.method,url:a.url,headers:Array.from(a.headers.entries()),data:o,maxRedirections:n,connectTimeout:i});a.signal.addEventListener("abort",(()=>{t("plugin:http|fetch_cancel",{rid:u})}));const{status:_,statusText:d,url:c,headers:f}=await t("plugin:http|fetch_send",{rid:u}),h=await t("plugin:http|fetch_read_body",{rid:u}),p=new Response(new Uint8Array(h),{headers:f,status:_,statusText:d});return Object.defineProperty(p,"url",{value:c}),p},e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_PLUGIN_HTTP__})}
|
||||
|
||||
Reference in New Issue
Block a user