zen-fs-config 0.3.13 → 0.3.14
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/index.js +24 -18
- package/dist/index.mjs +24 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -422,38 +422,44 @@ registerBackend("GitHub", async (options) => {
|
|
|
422
422
|
});
|
|
423
423
|
registerBackend("Gitee", async (options) => {
|
|
424
424
|
const zenGitee = await import("zen-fs-gitee");
|
|
425
|
-
const {
|
|
426
|
-
const
|
|
427
|
-
|
|
425
|
+
const { GiteeFS } = zenGitee;
|
|
426
|
+
const origInit = GiteeFS.prototype.init;
|
|
427
|
+
const patched = /* @__PURE__ */ new WeakSet();
|
|
428
|
+
GiteeFS.prototype.init = async function() {
|
|
429
|
+
let firstErr;
|
|
428
430
|
try {
|
|
429
|
-
return await
|
|
431
|
+
return await origInit.call(this);
|
|
430
432
|
} catch (err) {
|
|
431
433
|
if (!err.message?.includes("404") && !err.message?.includes("Tree not found")) {
|
|
432
434
|
throw err;
|
|
433
435
|
}
|
|
436
|
+
firstErr = err;
|
|
434
437
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
const
|
|
438
|
+
if (patched.has(this)) throw firstErr;
|
|
439
|
+
patched.add(this);
|
|
440
|
+
console.log(`[Gitee] init failed with branch="${this.api.branch}", resolving to SHA...`);
|
|
441
|
+
const baseUrl = this.api.baseUrl || "https://gitee.com/api/v5";
|
|
442
|
+
const auth = `access_token=${this.api.token}`;
|
|
443
|
+
const branchUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${this.api.branch}?${auth}`;
|
|
440
444
|
const branchRes = await fetch(branchUrl);
|
|
441
|
-
if (!branchRes.ok) throw new Error(`Gitee: branch "${this.branch}" not found (${branchRes.status})`);
|
|
445
|
+
if (!branchRes.ok) throw new Error(`Gitee: branch "${this.api.branch}" not found (${branchRes.status})`);
|
|
442
446
|
const branchData = await branchRes.json();
|
|
443
447
|
const commitSha = branchData.commit?.sha;
|
|
444
|
-
if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.branch}"`);
|
|
445
|
-
const commitUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/git/commits/${commitSha}
|
|
448
|
+
if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.api.branch}"`);
|
|
449
|
+
const commitUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/git/commits/${commitSha}?${auth}`;
|
|
446
450
|
const commitRes = await fetch(commitUrl);
|
|
447
451
|
if (!commitRes.ok) throw new Error(`Gitee: commit ${commitSha} not found (${commitRes.status})`);
|
|
448
452
|
const commitData = await commitRes.json();
|
|
449
453
|
const treeSha = commitData.tree?.sha;
|
|
450
454
|
if (!treeSha) throw new Error(`Gitee: could not get tree SHA from commit ${commitSha}`);
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
455
|
+
const realBranch = this.api.branch;
|
|
456
|
+
this.api.branch = treeSha;
|
|
457
|
+
console.log(`[Gitee] Resolved branch="${realBranch}" \u2192 commit=${commitSha.slice(0, 8)} \u2192 tree=${treeSha.slice(0, 8)}`);
|
|
458
|
+
try {
|
|
459
|
+
return await origInit.call(this);
|
|
460
|
+
} finally {
|
|
461
|
+
this.api.branch = realBranch;
|
|
462
|
+
}
|
|
457
463
|
};
|
|
458
464
|
return wrapZenFSFileSystem({
|
|
459
465
|
backend: zenGitee.Gitee,
|
package/dist/index.mjs
CHANGED
|
@@ -375,38 +375,44 @@ registerBackend("GitHub", async (options) => {
|
|
|
375
375
|
});
|
|
376
376
|
registerBackend("Gitee", async (options) => {
|
|
377
377
|
const zenGitee = await import("zen-fs-gitee");
|
|
378
|
-
const {
|
|
379
|
-
const
|
|
380
|
-
|
|
378
|
+
const { GiteeFS } = zenGitee;
|
|
379
|
+
const origInit = GiteeFS.prototype.init;
|
|
380
|
+
const patched = /* @__PURE__ */ new WeakSet();
|
|
381
|
+
GiteeFS.prototype.init = async function() {
|
|
382
|
+
let firstErr;
|
|
381
383
|
try {
|
|
382
|
-
return await
|
|
384
|
+
return await origInit.call(this);
|
|
383
385
|
} catch (err) {
|
|
384
386
|
if (!err.message?.includes("404") && !err.message?.includes("Tree not found")) {
|
|
385
387
|
throw err;
|
|
386
388
|
}
|
|
389
|
+
firstErr = err;
|
|
387
390
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
const
|
|
391
|
+
if (patched.has(this)) throw firstErr;
|
|
392
|
+
patched.add(this);
|
|
393
|
+
console.log(`[Gitee] init failed with branch="${this.api.branch}", resolving to SHA...`);
|
|
394
|
+
const baseUrl = this.api.baseUrl || "https://gitee.com/api/v5";
|
|
395
|
+
const auth = `access_token=${this.api.token}`;
|
|
396
|
+
const branchUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${this.api.branch}?${auth}`;
|
|
393
397
|
const branchRes = await fetch(branchUrl);
|
|
394
|
-
if (!branchRes.ok) throw new Error(`Gitee: branch "${this.branch}" not found (${branchRes.status})`);
|
|
398
|
+
if (!branchRes.ok) throw new Error(`Gitee: branch "${this.api.branch}" not found (${branchRes.status})`);
|
|
395
399
|
const branchData = await branchRes.json();
|
|
396
400
|
const commitSha = branchData.commit?.sha;
|
|
397
|
-
if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.branch}"`);
|
|
398
|
-
const commitUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/git/commits/${commitSha}
|
|
401
|
+
if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.api.branch}"`);
|
|
402
|
+
const commitUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/git/commits/${commitSha}?${auth}`;
|
|
399
403
|
const commitRes = await fetch(commitUrl);
|
|
400
404
|
if (!commitRes.ok) throw new Error(`Gitee: commit ${commitSha} not found (${commitRes.status})`);
|
|
401
405
|
const commitData = await commitRes.json();
|
|
402
406
|
const treeSha = commitData.tree?.sha;
|
|
403
407
|
if (!treeSha) throw new Error(`Gitee: could not get tree SHA from commit ${commitSha}`);
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
408
|
+
const realBranch = this.api.branch;
|
|
409
|
+
this.api.branch = treeSha;
|
|
410
|
+
console.log(`[Gitee] Resolved branch="${realBranch}" \u2192 commit=${commitSha.slice(0, 8)} \u2192 tree=${treeSha.slice(0, 8)}`);
|
|
411
|
+
try {
|
|
412
|
+
return await origInit.call(this);
|
|
413
|
+
} finally {
|
|
414
|
+
this.api.branch = realBranch;
|
|
415
|
+
}
|
|
410
416
|
};
|
|
411
417
|
return wrapZenFSFileSystem({
|
|
412
418
|
backend: zenGitee.Gitee,
|