zen-fs-config 0.3.14 → 0.3.16
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 +37 -4
- package/dist/index.mjs +37 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -441,9 +441,42 @@ registerBackend("Gitee", async (options) => {
|
|
|
441
441
|
const baseUrl = this.api.baseUrl || "https://gitee.com/api/v5";
|
|
442
442
|
const auth = `access_token=${this.api.token}`;
|
|
443
443
|
const branchUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${this.api.branch}?${auth}`;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
444
|
+
let branchRes = await fetch(branchUrl);
|
|
445
|
+
let branchData;
|
|
446
|
+
if (branchRes.ok) {
|
|
447
|
+
branchData = await branchRes.json();
|
|
448
|
+
} else {
|
|
449
|
+
console.log(`[Gitee] Branch "${this.api.branch}" not found, creating...`);
|
|
450
|
+
const defaultBranch = this.api.branch === "master" ? "main" : "master";
|
|
451
|
+
let defaultSha;
|
|
452
|
+
for (const name of [defaultBranch, "main", "master"]) {
|
|
453
|
+
const dr = await fetch(`${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${name}?${auth}`);
|
|
454
|
+
if (dr.ok) {
|
|
455
|
+
const dd = await dr.json();
|
|
456
|
+
defaultSha = dd.commit?.sha;
|
|
457
|
+
if (defaultSha) break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (!defaultSha) {
|
|
461
|
+
console.log(`[Gitee] No branches found in repo, skipping tree init`);
|
|
462
|
+
this.initialized = true;
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const createRes = await fetch(`${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches?${auth}`, {
|
|
466
|
+
method: "POST",
|
|
467
|
+
headers: { "Content-Type": "application/json" },
|
|
468
|
+
body: JSON.stringify({
|
|
469
|
+
refs: defaultSha,
|
|
470
|
+
branch_name: this.api.branch
|
|
471
|
+
})
|
|
472
|
+
});
|
|
473
|
+
if (!createRes.ok) {
|
|
474
|
+
const errText = await createRes.text().catch(() => "");
|
|
475
|
+
throw new Error(`Gitee: failed to create branch "${this.api.branch}": ${createRes.status} ${errText}`);
|
|
476
|
+
}
|
|
477
|
+
branchData = await createRes.json();
|
|
478
|
+
console.log(`[Gitee] Branch "${this.api.branch}" created from ${defaultSha.slice(0, 8)}`);
|
|
479
|
+
}
|
|
447
480
|
const commitSha = branchData.commit?.sha;
|
|
448
481
|
if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.api.branch}"`);
|
|
449
482
|
const commitUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/git/commits/${commitSha}?${auth}`;
|
|
@@ -941,7 +974,7 @@ var ConfigRepo = class {
|
|
|
941
974
|
this.fullFS,
|
|
942
975
|
replica.syncable,
|
|
943
976
|
{
|
|
944
|
-
direction: import_zen_fs_sync.SyncDirection.
|
|
977
|
+
direction: import_zen_fs_sync.SyncDirection.BiDirectional,
|
|
945
978
|
conflictStrategy: "source-wins"
|
|
946
979
|
// No filter = sync everything under root
|
|
947
980
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -394,9 +394,42 @@ registerBackend("Gitee", async (options) => {
|
|
|
394
394
|
const baseUrl = this.api.baseUrl || "https://gitee.com/api/v5";
|
|
395
395
|
const auth = `access_token=${this.api.token}`;
|
|
396
396
|
const branchUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${this.api.branch}?${auth}`;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
397
|
+
let branchRes = await fetch(branchUrl);
|
|
398
|
+
let branchData;
|
|
399
|
+
if (branchRes.ok) {
|
|
400
|
+
branchData = await branchRes.json();
|
|
401
|
+
} else {
|
|
402
|
+
console.log(`[Gitee] Branch "${this.api.branch}" not found, creating...`);
|
|
403
|
+
const defaultBranch = this.api.branch === "master" ? "main" : "master";
|
|
404
|
+
let defaultSha;
|
|
405
|
+
for (const name of [defaultBranch, "main", "master"]) {
|
|
406
|
+
const dr = await fetch(`${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${name}?${auth}`);
|
|
407
|
+
if (dr.ok) {
|
|
408
|
+
const dd = await dr.json();
|
|
409
|
+
defaultSha = dd.commit?.sha;
|
|
410
|
+
if (defaultSha) break;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (!defaultSha) {
|
|
414
|
+
console.log(`[Gitee] No branches found in repo, skipping tree init`);
|
|
415
|
+
this.initialized = true;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const createRes = await fetch(`${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches?${auth}`, {
|
|
419
|
+
method: "POST",
|
|
420
|
+
headers: { "Content-Type": "application/json" },
|
|
421
|
+
body: JSON.stringify({
|
|
422
|
+
refs: defaultSha,
|
|
423
|
+
branch_name: this.api.branch
|
|
424
|
+
})
|
|
425
|
+
});
|
|
426
|
+
if (!createRes.ok) {
|
|
427
|
+
const errText = await createRes.text().catch(() => "");
|
|
428
|
+
throw new Error(`Gitee: failed to create branch "${this.api.branch}": ${createRes.status} ${errText}`);
|
|
429
|
+
}
|
|
430
|
+
branchData = await createRes.json();
|
|
431
|
+
console.log(`[Gitee] Branch "${this.api.branch}" created from ${defaultSha.slice(0, 8)}`);
|
|
432
|
+
}
|
|
400
433
|
const commitSha = branchData.commit?.sha;
|
|
401
434
|
if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.api.branch}"`);
|
|
402
435
|
const commitUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/git/commits/${commitSha}?${auth}`;
|
|
@@ -894,7 +927,7 @@ var ConfigRepo = class {
|
|
|
894
927
|
this.fullFS,
|
|
895
928
|
replica.syncable,
|
|
896
929
|
{
|
|
897
|
-
direction: SyncDirection.
|
|
930
|
+
direction: SyncDirection.BiDirectional,
|
|
898
931
|
conflictStrategy: "source-wins"
|
|
899
932
|
// No filter = sync everything under root
|
|
900
933
|
},
|