zephyr-agent 0.0.0-canary-20241121202227 → 0.0.0-canary-20241122013202
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type UploadableAsset
|
|
1
|
+
import { type UploadableAsset } from 'zephyr-edge-contract';
|
|
2
|
+
import { ZeApplicationConfig } from 'zephyr-edge-contract';
|
|
2
3
|
export interface UploadFileProps {
|
|
3
4
|
hash: string;
|
|
4
5
|
asset: UploadableAsset;
|
|
@@ -2,82 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadFile = void 0;
|
|
4
4
|
const zephyr_edge_contract_1 = require("zephyr-edge-contract");
|
|
5
|
-
const
|
|
5
|
+
const zephyr_edge_contract_2 = require("zephyr-edge-contract");
|
|
6
6
|
async function uploadFile({ hash, asset }, { EDGE_URL, jwt }) {
|
|
7
7
|
const type = 'file';
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
base: EDGE_URL,
|
|
28
|
-
query: { type, hash, filename: asset.path },
|
|
29
|
-
}, options, chunk);
|
|
30
|
-
if (!ok) {
|
|
31
|
-
// Because of `ctx.waitUntil`, the worker will continue to upload the files even if the request failed, and if we immediately throw an error the local process will be terminated, we try again here to at least have another level of effort to continue local process.
|
|
32
|
-
try {
|
|
33
|
-
(0, zephyr_edge_contract_1.ze_log)(`Failed on first time...trying to upload chunk ${chunkIndex} of file ${asset.path} of total ${totalChunks} chunks...`);
|
|
34
|
-
const [retryOk, retryCause] = await zephyr_edge_contract_1.ZeHttpRequest.from({
|
|
35
|
-
path: '/upload',
|
|
36
|
-
base: EDGE_URL,
|
|
37
|
-
query: { type, hash, filename: asset.path },
|
|
38
|
-
}, options, chunk);
|
|
39
|
-
if (!retryOk) {
|
|
40
|
-
try {
|
|
41
|
-
(0, zephyr_edge_contract_1.ze_log)(`Second time...Trying to upload chunk ${chunkIndex} of file ${asset.path} of total ${totalChunks} chunks...`);
|
|
42
|
-
const [retryOk, retryCause] = await zephyr_edge_contract_1.ZeHttpRequest.from({
|
|
43
|
-
path: '/upload',
|
|
44
|
-
base: EDGE_URL,
|
|
45
|
-
query: { type, hash, filename: asset.path },
|
|
46
|
-
}, options, chunk);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
throw new zephyr_edge_contract_1.ZephyrError(zephyr_edge_contract_1.ZeErrors.ERR_FAILED_UPLOAD, {
|
|
50
|
-
type: 'file',
|
|
51
|
-
cause: error,
|
|
52
|
-
data: {
|
|
53
|
-
chunkIndex,
|
|
54
|
-
totalChunks,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
throw new zephyr_edge_contract_1.ZephyrError(zephyr_edge_contract_1.ZeErrors.ERR_FAILED_UPLOAD, {
|
|
59
|
-
type: 'file',
|
|
60
|
-
cause: retryCause,
|
|
61
|
-
data: {
|
|
62
|
-
chunkIndex,
|
|
63
|
-
totalChunks,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
throw new zephyr_edge_contract_1.ZephyrError(zephyr_edge_contract_1.ZeErrors.ERR_FAILED_UPLOAD, {
|
|
70
|
-
type: 'file',
|
|
71
|
-
cause,
|
|
72
|
-
data: {
|
|
73
|
-
error,
|
|
74
|
-
chunkIndex,
|
|
75
|
-
totalChunks,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
(0, zephyr_edge_contract_1.ze_log)(`Chunk ${chunkIndex} of file ${asset.path} of total ${totalChunks} chunks uploaded`);
|
|
8
|
+
const options = {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: {
|
|
11
|
+
'x-file-size': asset.size.toString(),
|
|
12
|
+
'x-file-path': asset.path,
|
|
13
|
+
can_write_jwt: jwt,
|
|
14
|
+
'Content-Type': 'application/octet-stream',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const [ok, cause] = await zephyr_edge_contract_1.ZeHttpRequest.from({
|
|
18
|
+
path: '/upload',
|
|
19
|
+
base: EDGE_URL,
|
|
20
|
+
query: { type, hash, filename: asset.path },
|
|
21
|
+
}, options, asset.buffer);
|
|
22
|
+
if (!ok) {
|
|
23
|
+
throw new zephyr_edge_contract_2.ZephyrError(zephyr_edge_contract_2.ZeErrors.ERR_FAILED_UPLOAD, {
|
|
24
|
+
type: 'file',
|
|
25
|
+
cause,
|
|
26
|
+
});
|
|
81
27
|
}
|
|
82
28
|
}
|
|
83
29
|
exports.uploadFile = uploadFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-file.js","sourceRoot":"","sources":["../../../src/lib/upload/upload-file.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"upload-file.js","sourceRoot":"","sources":["../../../src/lib/upload/upload-file.ts"],"names":[],"mappings":";;;AAEA,+DAAqD;AACrD,+DAA6D;AAQtD,KAAK,UAAU,UAAU,CAC9B,EAAE,IAAI,EAAE,KAAK,EAAmB,EAChC,EAAE,QAAQ,EAAE,GAAG,EAAuB;IAEtC,MAAM,IAAI,GAAG,MAAM,CAAC;IAEpB,MAAM,OAAO,GAAsB;QACjC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;YACpC,aAAa,EAAE,KAAK,CAAC,IAAI;YACzB,aAAa,EAAE,GAAG;YAClB,cAAc,EAAE,0BAA0B;SAC3C;KACF,CAAC;IAEF,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,MAAM,oCAAa,CAAC,IAAI,CAC1C;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;KAC5C,EACD,OAAO,EACP,KAAK,CAAC,MAAM,CACb,CAAC;IAEF,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,kCAAW,CAAC,+BAAQ,CAAC,iBAAiB,EAAE;YAChD,IAAI,EAAE,MAAM;YACZ,KAAK;SACN,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAhCD,gCAgCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zephyr-agent",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20241122013202",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"socket.io-client": "^4.7.5",
|
|
27
27
|
"tslib": "^2.6.3",
|
|
28
28
|
"uuid": "^8.3.2",
|
|
29
|
-
"zephyr-edge-contract": "0.0.0-canary-
|
|
29
|
+
"zephyr-edge-contract": "0.0.0-canary-20241122013202"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/git-url-parse": "^9.0.3",
|