archiver-ts 0.3.0 → 0.3.1
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 +600 -579
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import h, { join as
|
|
4
|
-
import
|
|
5
|
-
import { parse as
|
|
6
|
-
import
|
|
7
|
-
import { Command as
|
|
2
|
+
import We from "node:fs";
|
|
3
|
+
import h, { join as D } from "node:path";
|
|
4
|
+
import p from "node:fs/promises";
|
|
5
|
+
import { parse as ut, printParseErrorCode as mt, modify as vt, applyEdits as ht } from "jsonc-parser";
|
|
6
|
+
import Je, { homedir as ft } from "node:os";
|
|
7
|
+
import { Command as gt } from "commander";
|
|
8
8
|
import v from "chalk";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { stdout as
|
|
12
|
-
import { execFile as
|
|
13
|
-
import { promisify as
|
|
14
|
-
function
|
|
9
|
+
import ge from "node:readline";
|
|
10
|
+
import pt from "node:readline/promises";
|
|
11
|
+
import { stdout as _t, stdin as wt } from "node:process";
|
|
12
|
+
import { execFile as It } from "node:child_process";
|
|
13
|
+
import { promisify as yt } from "node:util";
|
|
14
|
+
function bt(e) {
|
|
15
15
|
const t = h.join(import.meta.dirname, e);
|
|
16
|
-
return
|
|
16
|
+
return We.existsSync(t) ? t : h.resolve(import.meta.dirname, "..", "..", "public", e);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
18
|
+
function Ge(e) {
|
|
19
|
+
return We.readFileSync(bt(e), "utf8");
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const de = Ge("config.default.jsonc"), ue = Ge("auto-incr.default.jsonc"), kt = {
|
|
22
22
|
"app.description": "Archive files and folders into ~/.archiver with audit logs",
|
|
23
23
|
"defaults.vault.remark": "Default vault",
|
|
24
24
|
"common.action.list": "list",
|
|
@@ -27,6 +27,9 @@ const oe = Ue("config.default.jsonc"), ce = Ue("auto-incr.default.jsonc"), gt =
|
|
|
27
27
|
"common.state.off": "off",
|
|
28
28
|
"index.no_command_action.unknown": "No-command action is unknown.",
|
|
29
29
|
"index.no_command_action.question": "When you run `arv` with no subcommand, what should it do?",
|
|
30
|
+
"index.no_command_action.note": "You can change this later with the config command.",
|
|
31
|
+
"index.no_command_action.option.list": "Interactive Archiver list",
|
|
32
|
+
"index.no_command_action.option.help": "Show help text",
|
|
30
33
|
"index.no_command_action.option_list": " 1) list",
|
|
31
34
|
"index.no_command_action.option_help": " 2) help",
|
|
32
35
|
"index.no_command_action.choose": "Choose [1/2] (default 1): ",
|
|
@@ -331,7 +334,7 @@ const oe = Ue("config.default.jsonc"), ce = Ue("auto-incr.default.jsonc"), gt =
|
|
|
331
334
|
"terminal.status.log.warn": "WARN",
|
|
332
335
|
"terminal.status.log.error": "ERROR",
|
|
333
336
|
"terminal.status.log.fatal": "FATAL"
|
|
334
|
-
},
|
|
337
|
+
}, Ct = {
|
|
335
338
|
"app.description": "将文件和文件夹归档到 ~/.archiver,并记录审计日志",
|
|
336
339
|
"defaults.vault.remark": "默认 vault",
|
|
337
340
|
"common.action.list": "list",
|
|
@@ -340,6 +343,9 @@ const oe = Ue("config.default.jsonc"), ce = Ue("auto-incr.default.jsonc"), gt =
|
|
|
340
343
|
"common.state.off": "off",
|
|
341
344
|
"index.no_command_action.unknown": "未配置无子命令行为。",
|
|
342
345
|
"index.no_command_action.question": "当你输入 `arv` 且不带子命令时,希望执行什么?",
|
|
346
|
+
"index.no_command_action.note": "此行为可通过 config 命令随时更改。",
|
|
347
|
+
"index.no_command_action.option.list": "可互动的Archiver列表",
|
|
348
|
+
"index.no_command_action.option.help": "显示帮助文本",
|
|
343
349
|
"index.no_command_action.option_list": " 1) list",
|
|
344
350
|
"index.no_command_action.option_help": " 2) help",
|
|
345
351
|
"index.no_command_action.choose": "请选择 [1/2](默认 1):",
|
|
@@ -644,18 +650,18 @@ const oe = Ue("config.default.jsonc"), ce = Ue("auto-incr.default.jsonc"), gt =
|
|
|
644
650
|
"terminal.status.log.warn": "警告",
|
|
645
651
|
"terminal.status.log.error": "错误",
|
|
646
652
|
"terminal.status.log.fatal": "致命"
|
|
647
|
-
},
|
|
648
|
-
zh:
|
|
649
|
-
en:
|
|
653
|
+
}, Ae = {
|
|
654
|
+
zh: Ct,
|
|
655
|
+
en: kt
|
|
650
656
|
};
|
|
651
|
-
let
|
|
652
|
-
function
|
|
657
|
+
let me = "zh";
|
|
658
|
+
function Et(e) {
|
|
653
659
|
return e === "en" ? "en" : "zh";
|
|
654
660
|
}
|
|
655
|
-
function
|
|
656
|
-
return
|
|
661
|
+
function Z(e) {
|
|
662
|
+
return me = Et(e), me;
|
|
657
663
|
}
|
|
658
|
-
function
|
|
664
|
+
function At(e, t) {
|
|
659
665
|
return t ? e.replace(/\{([a-zA-Z0-9_]+)\}/g, (a, i) => {
|
|
660
666
|
if (!(i in t))
|
|
661
667
|
return `{${i}}`;
|
|
@@ -664,27 +670,27 @@ function wt(e, t) {
|
|
|
664
670
|
}) : e;
|
|
665
671
|
}
|
|
666
672
|
function r(e, t) {
|
|
667
|
-
const a =
|
|
668
|
-
return
|
|
673
|
+
const a = Ae[me][e] ?? Ae.zh[e] ?? e;
|
|
674
|
+
return At(a, t);
|
|
669
675
|
}
|
|
670
|
-
function
|
|
676
|
+
function Ke(e) {
|
|
671
677
|
return e.endsWith(`
|
|
672
678
|
`) ? e : `${e}
|
|
673
679
|
`;
|
|
674
680
|
}
|
|
675
|
-
async function
|
|
681
|
+
async function pe(e) {
|
|
676
682
|
try {
|
|
677
|
-
return await
|
|
683
|
+
return await p.readFile(e, "utf8");
|
|
678
684
|
} catch (t) {
|
|
679
685
|
if (t.code === "ENOENT")
|
|
680
686
|
return;
|
|
681
687
|
throw t;
|
|
682
688
|
}
|
|
683
689
|
}
|
|
684
|
-
function
|
|
685
|
-
const a = [], i =
|
|
690
|
+
function Q(e, t) {
|
|
691
|
+
const a = [], i = ut(e, a, { allowTrailingComma: !0 });
|
|
686
692
|
if (a.length > 0) {
|
|
687
|
-
const n = a.map((o) => `${
|
|
693
|
+
const n = a.map((o) => `${mt(o.error)}@${o.offset}`).join(", ");
|
|
688
694
|
throw new Error(
|
|
689
695
|
r("util.jsonc.error.parse_file", {
|
|
690
696
|
filePath: t,
|
|
@@ -694,10 +700,10 @@ function K(e, t) {
|
|
|
694
700
|
}
|
|
695
701
|
return i;
|
|
696
702
|
}
|
|
697
|
-
function
|
|
703
|
+
function St(e, t) {
|
|
698
704
|
let a = e;
|
|
699
705
|
for (const [i, n] of Object.entries(t)) {
|
|
700
|
-
const o =
|
|
706
|
+
const o = vt(a, [i], n, {
|
|
701
707
|
isArrayInsertion: !1,
|
|
702
708
|
formattingOptions: {
|
|
703
709
|
insertSpaces: !0,
|
|
@@ -706,27 +712,27 @@ function It(e, t) {
|
|
|
706
712
|
`
|
|
707
713
|
}
|
|
708
714
|
});
|
|
709
|
-
a =
|
|
715
|
+
a = ht(a, o);
|
|
710
716
|
}
|
|
711
|
-
return
|
|
717
|
+
return Ke(a);
|
|
712
718
|
}
|
|
713
|
-
async function
|
|
714
|
-
const a = await
|
|
715
|
-
return !a || !a.trim() ? t :
|
|
719
|
+
async function ve(e, t) {
|
|
720
|
+
const a = await pe(e);
|
|
721
|
+
return !a || !a.trim() ? t : Q(a, e);
|
|
716
722
|
}
|
|
717
|
-
async function
|
|
718
|
-
await
|
|
723
|
+
async function Se(e, t) {
|
|
724
|
+
await pe(e) === void 0 && await p.writeFile(e, Ke(t), "utf8");
|
|
719
725
|
}
|
|
720
|
-
async function
|
|
721
|
-
const i = await
|
|
722
|
-
|
|
723
|
-
const o =
|
|
724
|
-
await
|
|
726
|
+
async function xe(e, t, a) {
|
|
727
|
+
const i = await pe(e), n = i && i.trim().length > 0 ? i : a;
|
|
728
|
+
Q(n, e);
|
|
729
|
+
const o = St(n, t);
|
|
730
|
+
await p.writeFile(e, o, "utf8");
|
|
725
731
|
}
|
|
726
|
-
var S = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Protected = "Protected", e))(S || {}),
|
|
732
|
+
var S = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Protected = "Protected", e))(S || {}), y = /* @__PURE__ */ ((e) => (e.Archived = "Archived", e.Restored = "Restored", e))(y || {}), w = /* @__PURE__ */ ((e) => (e.Info = "Info", e.Warn = "Warn", e.Error = "Error", e))(w || {}), g;
|
|
727
733
|
((e) => {
|
|
728
|
-
e.VaultId = 0, e.VaultName = "@", e.Config =
|
|
729
|
-
|
|
734
|
+
e.VaultId = 0, e.VaultName = "@", e.Config = Q(de, "default-files/config.default.jsonc"), e.AutoIncr = Q(
|
|
735
|
+
ue,
|
|
730
736
|
"default-files/auto-incr.default.jsonc"
|
|
731
737
|
), e.Vault = {
|
|
732
738
|
id: e.VaultId,
|
|
@@ -735,38 +741,38 @@ var S = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Pro
|
|
|
735
741
|
createdAt: "system",
|
|
736
742
|
status: S.Protected
|
|
737
743
|
}, e.LogTail = 15;
|
|
738
|
-
})(
|
|
739
|
-
const
|
|
740
|
-
var
|
|
744
|
+
})(g || (g = {}));
|
|
745
|
+
const xt = () => process.env.ARCHIVER_PATH ?? D(ft(), ".archiver"), $ = xt();
|
|
746
|
+
var f;
|
|
741
747
|
((e) => {
|
|
742
748
|
e.Dir = {
|
|
743
749
|
root: $,
|
|
744
|
-
vaults:
|
|
750
|
+
vaults: D($, "vaults")
|
|
745
751
|
}, e.File = {
|
|
746
|
-
config:
|
|
747
|
-
autoIncr:
|
|
748
|
-
list:
|
|
749
|
-
vaults:
|
|
750
|
-
log:
|
|
752
|
+
config: D($, "config.jsonc"),
|
|
753
|
+
autoIncr: D($, "auto-incr.jsonc"),
|
|
754
|
+
list: D($, "list.jsonl"),
|
|
755
|
+
vaults: D($, "vaults.jsonl"),
|
|
756
|
+
log: D($, "log.jsonl")
|
|
751
757
|
};
|
|
752
|
-
})(
|
|
753
|
-
var
|
|
758
|
+
})(f || (f = {}));
|
|
759
|
+
var M;
|
|
754
760
|
((e) => {
|
|
755
761
|
e.CheckInterval = 1440 * 60 * 1e3, e.Repo = process.env.ARCHIVER_GITHUB_REPO ?? "aldia/archiver", e.Timeout = 1e4;
|
|
756
|
-
})(
|
|
757
|
-
const
|
|
758
|
-
function
|
|
759
|
-
const t = e.getFullYear(), a =
|
|
762
|
+
})(M || (M = {}));
|
|
763
|
+
const Vt = "archiver", z = (e) => e.toString().padStart(2, "0"), Rt = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
764
|
+
function _e(e = /* @__PURE__ */ new Date()) {
|
|
765
|
+
const t = e.getFullYear(), a = z(e.getMonth() + 1), i = z(e.getDate()), n = z(e.getHours()), o = z(e.getMinutes()), c = z(e.getSeconds());
|
|
760
766
|
return `${t}-${a}-${i} ${n}:${o}:${c}`;
|
|
761
767
|
}
|
|
762
|
-
function
|
|
768
|
+
function ce(e) {
|
|
763
769
|
if (!/^\d{6}$/.test(e))
|
|
764
770
|
return;
|
|
765
771
|
const t = Number(e.slice(0, 4)), a = Number(e.slice(4, 6));
|
|
766
772
|
if (!(a < 1 || a > 12))
|
|
767
773
|
return { year: t, month: a };
|
|
768
774
|
}
|
|
769
|
-
function
|
|
775
|
+
function Ve(e) {
|
|
770
776
|
if (e.length === 0)
|
|
771
777
|
throw new Error(r("util.parse.error.at_least_one_id"));
|
|
772
778
|
const t = e.map((i) => {
|
|
@@ -778,19 +784,19 @@ function ke(e) {
|
|
|
778
784
|
throw new Error(r("util.parse.error.duplicate_ids"));
|
|
779
785
|
return t;
|
|
780
786
|
}
|
|
781
|
-
function
|
|
787
|
+
function Lt(e) {
|
|
782
788
|
if (!e)
|
|
783
789
|
return { mode: "all" };
|
|
784
790
|
if (["all", "*", "a"].includes(e.toLowerCase()))
|
|
785
791
|
return { mode: "all" };
|
|
786
792
|
if (/^\d{6}$/.test(e)) {
|
|
787
|
-
if (!
|
|
793
|
+
if (!ce(e))
|
|
788
794
|
throw new Error(r("util.parse.error.invalid_month_range", { range: e }));
|
|
789
795
|
return { mode: "month", from: e, to: e };
|
|
790
796
|
}
|
|
791
797
|
const t = e.split("-");
|
|
792
798
|
if (t.length === 2 && /^\d{6}$/.test(t[0]) && /^\d{6}$/.test(t[1])) {
|
|
793
|
-
const a =
|
|
799
|
+
const a = ce(t[0]), i = ce(t[1]);
|
|
794
800
|
if (!a || !i)
|
|
795
801
|
throw new Error(r("util.parse.error.invalid_range", { range: e }));
|
|
796
802
|
if (t[0] > t[1])
|
|
@@ -799,51 +805,51 @@ function Ct(e) {
|
|
|
799
805
|
}
|
|
800
806
|
throw new Error(r("util.parse.error.invalid_range_format", { range: e }));
|
|
801
807
|
}
|
|
802
|
-
function
|
|
808
|
+
function ne(e, t) {
|
|
803
809
|
return t === "green" ? v.black.bgGreen(` ${e} `) : t === "cyan" ? v.black.bgCyan(` ${e} `) : t === "yellow" ? v.black.bgYellow(` ${e} `) : v.white.bgRed(` ${e} `);
|
|
804
810
|
}
|
|
805
811
|
function C(e) {
|
|
806
|
-
console.log(`${
|
|
812
|
+
console.log(`${ne(r("terminal.badge.ok"), "green")} ${v.green(e)}`);
|
|
807
813
|
}
|
|
808
814
|
function A(e) {
|
|
809
|
-
console.log(`${
|
|
815
|
+
console.log(`${ne(r("terminal.badge.info"), "cyan")} ${v.cyan(e)}`);
|
|
810
816
|
}
|
|
811
|
-
function
|
|
812
|
-
console.log(`${
|
|
817
|
+
function se(e) {
|
|
818
|
+
console.log(`${ne(r("terminal.badge.warn"), "yellow")} ${v.yellow(e)}`);
|
|
813
819
|
}
|
|
814
|
-
function
|
|
815
|
-
console.error(`${
|
|
820
|
+
function j(e) {
|
|
821
|
+
console.error(`${ne(r("terminal.badge.error"), "red")} ${v.red(e)}`);
|
|
816
822
|
}
|
|
817
|
-
function
|
|
823
|
+
function Tt(e, t) {
|
|
818
824
|
return Array.from({ length: t }, (a, i) => e[i] ?? "");
|
|
819
825
|
}
|
|
820
|
-
function
|
|
826
|
+
function B(e, t) {
|
|
821
827
|
if (e.length === 0)
|
|
822
828
|
return "";
|
|
823
829
|
const a = e.length, i = [];
|
|
824
830
|
i.push(v.bold(e.join(" "))), i.push(v.dim(e.map((n) => "-".repeat(Math.max(n.length, 3))).join(" ")));
|
|
825
831
|
for (const n of t)
|
|
826
|
-
i.push(
|
|
832
|
+
i.push(Tt(n, a).join(" "));
|
|
827
833
|
return i.join(`
|
|
828
834
|
`);
|
|
829
835
|
}
|
|
830
|
-
function
|
|
836
|
+
function Xe(e) {
|
|
831
837
|
const t = e.toLowerCase();
|
|
832
838
|
return e === "A" || t === "archived" ? e === "A" ? v.green(e) : v.green(r("terminal.status.archive.archived")) : e === "R" || t === "restored" ? e === "R" ? v.gray(e) : v.gray(r("terminal.status.archive.restored")) : e;
|
|
833
839
|
}
|
|
834
|
-
function
|
|
840
|
+
function $t(e) {
|
|
835
841
|
return e === "Valid" ? v.green(r("terminal.status.vault.valid")) : e === "Removed" ? v.yellow(r("terminal.status.vault.removed")) : e === "Protected" ? v.cyan(r("terminal.status.vault.protected")) : e;
|
|
836
842
|
}
|
|
837
|
-
function
|
|
843
|
+
function Re(e) {
|
|
838
844
|
return e === "ERROR" || e === "FATAL" ? v.red(r(e === "ERROR" ? "terminal.status.log.error" : "terminal.status.log.fatal")) : e === "WARN" ? v.yellow(r("terminal.status.log.warn")) : e === "INFO" ? v.cyan(r("terminal.status.log.info")) : e;
|
|
839
845
|
}
|
|
840
|
-
function
|
|
846
|
+
function Nt(e) {
|
|
841
847
|
return e === "put" ? r("command.batch.operation.put") : e === "restore" ? r("command.batch.operation.restore") : e === "move" ? r("command.batch.operation.move") : e;
|
|
842
848
|
}
|
|
843
|
-
function
|
|
849
|
+
function K(e, t) {
|
|
844
850
|
A(
|
|
845
851
|
r("command.batch.summary", {
|
|
846
|
-
operation:
|
|
852
|
+
operation: Nt(e),
|
|
847
853
|
ok: t.ok.length,
|
|
848
854
|
failed: t.failed.length
|
|
849
855
|
})
|
|
@@ -854,12 +860,12 @@ async function V(e) {
|
|
|
854
860
|
if (t.updateCheck === "on") {
|
|
855
861
|
if (t.lastUpdateCheck) {
|
|
856
862
|
const a = new Date(t.lastUpdateCheck);
|
|
857
|
-
if (!Number.isNaN(a.getTime()) && Date.now() - a.getTime() <
|
|
863
|
+
if (!Number.isNaN(a.getTime()) && Date.now() - a.getTime() < M.CheckInterval)
|
|
858
864
|
return;
|
|
859
865
|
}
|
|
860
866
|
try {
|
|
861
867
|
const a = await e.updateService.checkLatest();
|
|
862
|
-
await e.configService.updateLastCheck(
|
|
868
|
+
await e.configService.updateLastCheck(Rt()), a.hasUpdate && A(
|
|
863
869
|
r("command.auto_update.new_available", {
|
|
864
870
|
latestVersion: a.latestVersion,
|
|
865
871
|
currentVersion: a.currentVersion
|
|
@@ -869,16 +875,16 @@ async function V(e) {
|
|
|
869
875
|
}
|
|
870
876
|
}
|
|
871
877
|
}
|
|
872
|
-
async function
|
|
878
|
+
async function b(e) {
|
|
873
879
|
try {
|
|
874
880
|
await e();
|
|
875
881
|
} catch (t) {
|
|
876
|
-
|
|
882
|
+
j(t.message), process.exitCode = 1;
|
|
877
883
|
}
|
|
878
884
|
}
|
|
879
|
-
function
|
|
885
|
+
function Dt(e, t) {
|
|
880
886
|
e.command("put").description(r("command.archive.put.description")).argument("<items...>", r("command.archive.put.argument.items")).option("-v, --vault <vault>", r("command.archive.put.option.vault")).option("-m, --message <message>", r("command.archive.put.option.message")).option("-r, --remark <remark>", r("command.archive.put.option.remark")).action(
|
|
881
|
-
(a, i) =>
|
|
887
|
+
(a, i) => b(async () => {
|
|
882
888
|
const n = await t.archiveService.put(a, i);
|
|
883
889
|
for (const o of n.ok)
|
|
884
890
|
C(
|
|
@@ -889,18 +895,18 @@ function Vt(e, t) {
|
|
|
889
895
|
})
|
|
890
896
|
);
|
|
891
897
|
for (const o of n.failed)
|
|
892
|
-
|
|
898
|
+
j(
|
|
893
899
|
r("command.archive.result.put.failed", {
|
|
894
900
|
id: o.id ?? "-",
|
|
895
901
|
input: o.input,
|
|
896
902
|
message: o.message
|
|
897
903
|
})
|
|
898
904
|
);
|
|
899
|
-
|
|
905
|
+
K("put", n), await V(t);
|
|
900
906
|
})
|
|
901
907
|
), e.command("restore").description(r("command.archive.restore.description")).argument("<ids...>", r("command.archive.restore.argument.ids")).action(
|
|
902
|
-
(a) =>
|
|
903
|
-
const i =
|
|
908
|
+
(a) => b(async () => {
|
|
909
|
+
const i = Ve(a), n = await t.archiveService.restore(i);
|
|
904
910
|
for (const o of n.ok)
|
|
905
911
|
C(
|
|
906
912
|
r("command.archive.result.restore.ok", {
|
|
@@ -909,17 +915,17 @@ function Vt(e, t) {
|
|
|
909
915
|
})
|
|
910
916
|
);
|
|
911
917
|
for (const o of n.failed)
|
|
912
|
-
|
|
918
|
+
j(
|
|
913
919
|
r("command.archive.result.restore.failed", {
|
|
914
920
|
id: o.id ?? "-",
|
|
915
921
|
message: o.message
|
|
916
922
|
})
|
|
917
923
|
);
|
|
918
|
-
|
|
924
|
+
K("restore", n), await V(t);
|
|
919
925
|
})
|
|
920
926
|
), e.command("move").description(r("command.archive.move.description")).argument("<ids...>", r("command.archive.move.argument.ids")).requiredOption("--to <vault>", r("command.archive.move.option.to")).action(
|
|
921
|
-
(a, i) =>
|
|
922
|
-
const n =
|
|
927
|
+
(a, i) => b(async () => {
|
|
928
|
+
const n = Ve(a), o = await t.archiveService.move(n, i.to);
|
|
923
929
|
for (const c of o.ok)
|
|
924
930
|
C(
|
|
925
931
|
r("command.archive.result.move.ok", {
|
|
@@ -928,45 +934,45 @@ function Vt(e, t) {
|
|
|
928
934
|
})
|
|
929
935
|
);
|
|
930
936
|
for (const c of o.failed)
|
|
931
|
-
|
|
937
|
+
j(
|
|
932
938
|
r("command.archive.result.move.failed", {
|
|
933
939
|
id: c.id ?? "-",
|
|
934
940
|
message: c.message
|
|
935
941
|
})
|
|
936
942
|
);
|
|
937
|
-
|
|
943
|
+
K("move", o), await V(t);
|
|
938
944
|
})
|
|
939
945
|
);
|
|
940
946
|
}
|
|
941
|
-
const
|
|
942
|
-
function
|
|
947
|
+
const Pt = v.level;
|
|
948
|
+
function Mt(e) {
|
|
943
949
|
if (typeof e != "string")
|
|
944
950
|
return;
|
|
945
951
|
const t = e.trim().toLowerCase();
|
|
946
952
|
if (t === "on" || t === "off")
|
|
947
953
|
return t;
|
|
948
954
|
}
|
|
949
|
-
function
|
|
950
|
-
return
|
|
955
|
+
function Ot(e, t = process.env) {
|
|
956
|
+
return Mt(t.ARCHIVER_STYLE) ?? e;
|
|
951
957
|
}
|
|
952
|
-
function
|
|
958
|
+
function Ft(e) {
|
|
953
959
|
if (e === "off") {
|
|
954
960
|
v.level = 0;
|
|
955
961
|
return;
|
|
956
962
|
}
|
|
957
|
-
v.level = Math.max(
|
|
963
|
+
v.level = Math.max(Pt, 1);
|
|
958
964
|
}
|
|
959
|
-
function
|
|
960
|
-
const a =
|
|
961
|
-
return
|
|
965
|
+
function ee(e, t = process.env) {
|
|
966
|
+
const a = Ot(e.style, t);
|
|
967
|
+
return Ft(a), a;
|
|
962
968
|
}
|
|
963
|
-
function
|
|
969
|
+
function Ze(e, t) {
|
|
964
970
|
return e < 0 ? 0 : e > t.length ? t.length : e;
|
|
965
971
|
}
|
|
966
|
-
function
|
|
967
|
-
return { value: e, cursor:
|
|
972
|
+
function P(e, t) {
|
|
973
|
+
return { value: e, cursor: Ze(t, e) };
|
|
968
974
|
}
|
|
969
|
-
function
|
|
975
|
+
function jt(e) {
|
|
970
976
|
if (!e)
|
|
971
977
|
return !1;
|
|
972
978
|
for (const t of e) {
|
|
@@ -976,13 +982,13 @@ function Lt(e) {
|
|
|
976
982
|
}
|
|
977
983
|
return !0;
|
|
978
984
|
}
|
|
979
|
-
function
|
|
985
|
+
function Yt(e = "") {
|
|
980
986
|
return { value: e, cursor: e.length };
|
|
981
987
|
}
|
|
982
|
-
function
|
|
983
|
-
return t === "left" ?
|
|
988
|
+
function Le(e, t) {
|
|
989
|
+
return t === "left" ? P(e.value, e.cursor - 1) : P(e.value, e.cursor + 1);
|
|
984
990
|
}
|
|
985
|
-
function
|
|
991
|
+
function Te(e, t, a) {
|
|
986
992
|
if (a.ctrl && a.name === "c")
|
|
987
993
|
return { state: e, action: "cancel" };
|
|
988
994
|
if (a.name === "escape")
|
|
@@ -990,48 +996,55 @@ function Ae(e, t, a) {
|
|
|
990
996
|
if (a.name === "return" || a.name === "enter")
|
|
991
997
|
return { state: e, action: "submit" };
|
|
992
998
|
if (a.name === "left")
|
|
993
|
-
return { state:
|
|
999
|
+
return { state: Le(e, "left"), action: "continue" };
|
|
994
1000
|
if (a.name === "right")
|
|
995
|
-
return { state:
|
|
1001
|
+
return { state: Le(e, "right"), action: "continue" };
|
|
996
1002
|
if (a.name === "home")
|
|
997
|
-
return { state:
|
|
1003
|
+
return { state: P(e.value, 0), action: "continue" };
|
|
998
1004
|
if (a.name === "end")
|
|
999
|
-
return { state:
|
|
1005
|
+
return { state: P(e.value, e.value.length), action: "continue" };
|
|
1000
1006
|
if (a.name === "backspace") {
|
|
1001
1007
|
if (e.cursor === 0)
|
|
1002
1008
|
return { state: e, action: "continue" };
|
|
1003
1009
|
const n = `${e.value.slice(0, e.cursor - 1)}${e.value.slice(e.cursor)}`;
|
|
1004
|
-
return { state:
|
|
1010
|
+
return { state: P(n, e.cursor - 1), action: "continue" };
|
|
1005
1011
|
}
|
|
1006
1012
|
if (a.name === "delete") {
|
|
1007
1013
|
if (e.cursor >= e.value.length)
|
|
1008
1014
|
return { state: e, action: "continue" };
|
|
1009
1015
|
const n = `${e.value.slice(0, e.cursor)}${e.value.slice(e.cursor + 1)}`;
|
|
1010
|
-
return { state:
|
|
1016
|
+
return { state: P(n, e.cursor), action: "continue" };
|
|
1011
1017
|
}
|
|
1012
|
-
if (!
|
|
1018
|
+
if (!jt(t))
|
|
1013
1019
|
return { state: e, action: "continue" };
|
|
1014
1020
|
const i = `${e.value.slice(0, e.cursor)}${t}${e.value.slice(e.cursor)}`;
|
|
1015
|
-
return { state:
|
|
1021
|
+
return { state: P(i, e.cursor + t.length), action: "continue" };
|
|
1016
1022
|
}
|
|
1017
|
-
function
|
|
1023
|
+
function Ht(e, t = !0, a = "") {
|
|
1018
1024
|
if (!t) {
|
|
1019
1025
|
const s = e.value || a;
|
|
1020
1026
|
return v.dim(`[${s}]`);
|
|
1021
1027
|
}
|
|
1022
1028
|
if (!e.value)
|
|
1023
1029
|
return a ? `[${v.dim(a)}]` : `[${v.inverse(" ")}]`;
|
|
1024
|
-
const i =
|
|
1030
|
+
const i = Ze(e.cursor, e.value);
|
|
1025
1031
|
if (i >= e.value.length)
|
|
1026
1032
|
return `[${e.value}${v.inverse(" ")}]`;
|
|
1027
1033
|
const n = e.value.slice(0, i), o = e.value.slice(i, i + 1), c = e.value.slice(i + 1);
|
|
1028
1034
|
return `[${n}${v.inverse(o)}${c}]`;
|
|
1029
1035
|
}
|
|
1030
|
-
function
|
|
1036
|
+
function Ut(e) {
|
|
1037
|
+
return typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : 24;
|
|
1038
|
+
}
|
|
1039
|
+
function we(e) {
|
|
1040
|
+
const t = e.contentLines.length > 0 ? e.contentLines : [""], a = e.footerLines ?? [], i = Ut(e.rows), n = Math.max(i - t.length - a.length, 0);
|
|
1041
|
+
return [...t, ...Array.from({ length: n }, () => ""), ...a];
|
|
1042
|
+
}
|
|
1043
|
+
function Ie(e = {}) {
|
|
1031
1044
|
const t = e.stdinIsTTY ?? !!process.stdin.isTTY, a = e.stdoutIsTTY ?? !!process.stdout.isTTY, i = e.forceInteractive ?? process.env.ARCHIVER_FORCE_INTERACTIVE === "1", n = e.hasRawMode ?? typeof process.stdin.setRawMode == "function";
|
|
1032
1045
|
return t && n && (a || i);
|
|
1033
1046
|
}
|
|
1034
|
-
function
|
|
1047
|
+
function Qe(e, t, a) {
|
|
1035
1048
|
if (e.length === 0)
|
|
1036
1049
|
return;
|
|
1037
1050
|
const i = a === "left" ? -1 : 1;
|
|
@@ -1046,44 +1059,46 @@ function O(e, t) {
|
|
|
1046
1059
|
return { options: e, selectedIndex: 0 };
|
|
1047
1060
|
let a = t === void 0 ? 0 : e.findIndex((i) => Object.is(i.value, t));
|
|
1048
1061
|
if (a < 0 && (a = 0), e[a]?.disabled) {
|
|
1049
|
-
const i =
|
|
1062
|
+
const i = Qe(e, a, "right");
|
|
1050
1063
|
i !== void 0 && (a = i);
|
|
1051
1064
|
}
|
|
1052
1065
|
return { options: e, selectedIndex: a };
|
|
1053
1066
|
}
|
|
1054
|
-
function
|
|
1055
|
-
const a =
|
|
1067
|
+
function q(e, t) {
|
|
1068
|
+
const a = Qe(e.options, e.selectedIndex, t);
|
|
1056
1069
|
return a === void 0 ? e : { ...e, selectedIndex: a };
|
|
1057
1070
|
}
|
|
1058
|
-
function
|
|
1071
|
+
function H(e) {
|
|
1059
1072
|
return e.options[e.selectedIndex];
|
|
1060
1073
|
}
|
|
1061
|
-
function
|
|
1074
|
+
function zt(e) {
|
|
1062
1075
|
return Math.max(...e.map((t) => t.label.length), 1);
|
|
1063
1076
|
}
|
|
1064
|
-
function
|
|
1077
|
+
function Bt(e, t, a, i) {
|
|
1065
1078
|
const o = `${e.disabled ? "x" : t ? ">" : " "} ${e.label.padEnd(i, " ")}`;
|
|
1066
1079
|
return e.disabled ? v.dim(`[${o}]`) : t && a ? v.black.bgGreen(`[${o}]`) : t ? v.green(`[${o}]`) : a ? v.green(`[${o}]`) : v.dim(`[${o}]`);
|
|
1067
1080
|
}
|
|
1068
|
-
function
|
|
1069
|
-
const a =
|
|
1070
|
-
return e.options.map((i, n) =>
|
|
1081
|
+
function te(e, t = !0) {
|
|
1082
|
+
const a = zt(e.options);
|
|
1083
|
+
return e.options.map((i, n) => Bt(i, n === e.selectedIndex, t, a)).join(" ");
|
|
1071
1084
|
}
|
|
1072
1085
|
function R(e) {
|
|
1073
1086
|
return v.black.bgWhite(` ${e} `);
|
|
1074
1087
|
}
|
|
1075
|
-
async function
|
|
1088
|
+
async function qt(e) {
|
|
1076
1089
|
const t = O(e.options, e.initialValue);
|
|
1077
1090
|
if (e.options.length === 0)
|
|
1078
1091
|
return null;
|
|
1079
|
-
if (!
|
|
1080
|
-
return
|
|
1092
|
+
if (!Ie())
|
|
1093
|
+
return H(t)?.value ?? null;
|
|
1081
1094
|
const a = process.stdin;
|
|
1082
1095
|
let i = t;
|
|
1083
|
-
return
|
|
1096
|
+
return ge.emitKeypressEvents(a), a.setRawMode(!0), a.resume(), new Promise((n) => {
|
|
1084
1097
|
const o = () => {
|
|
1085
|
-
const l = [e.title
|
|
1086
|
-
e.
|
|
1098
|
+
const l = [e.title];
|
|
1099
|
+
e.description && l.push(v.dim(e.description)), l.push("", te(i));
|
|
1100
|
+
const d = e.hint ? [e.hint] : [], m = we({ contentLines: l, footerLines: d, rows: process.stdout.rows });
|
|
1101
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(`${m.join(`
|
|
1087
1102
|
`)}
|
|
1088
1103
|
`);
|
|
1089
1104
|
}, c = (l) => {
|
|
@@ -1095,25 +1110,25 @@ async function Mt(e) {
|
|
|
1095
1110
|
return;
|
|
1096
1111
|
}
|
|
1097
1112
|
if (d.name === "left") {
|
|
1098
|
-
i =
|
|
1113
|
+
i = q(i, "left"), o();
|
|
1099
1114
|
return;
|
|
1100
1115
|
}
|
|
1101
1116
|
if (d.name === "right") {
|
|
1102
|
-
i =
|
|
1117
|
+
i = q(i, "right"), o();
|
|
1103
1118
|
return;
|
|
1104
1119
|
}
|
|
1105
1120
|
if (d.name === "return" || d.name === "enter") {
|
|
1106
|
-
const
|
|
1107
|
-
if (!
|
|
1121
|
+
const m = H(i);
|
|
1122
|
+
if (!m || m.disabled)
|
|
1108
1123
|
return;
|
|
1109
|
-
c(
|
|
1124
|
+
c(m.value);
|
|
1110
1125
|
}
|
|
1111
1126
|
};
|
|
1112
1127
|
a.on("keypress", s), o();
|
|
1113
1128
|
});
|
|
1114
1129
|
}
|
|
1115
|
-
const
|
|
1116
|
-
function
|
|
1130
|
+
const Wt = ["updateCheck", "vaultItemSeparator", "style", "language", "noCommandAction"];
|
|
1131
|
+
function Jt(e) {
|
|
1117
1132
|
return {
|
|
1118
1133
|
updateCheck: e.updateCheck,
|
|
1119
1134
|
vaultItemSeparator: e.vaultItemSeparator,
|
|
@@ -1122,7 +1137,7 @@ function jt(e) {
|
|
|
1122
1137
|
noCommandAction: e.noCommandAction
|
|
1123
1138
|
};
|
|
1124
1139
|
}
|
|
1125
|
-
function
|
|
1140
|
+
function Gt(e, t) {
|
|
1126
1141
|
return {
|
|
1127
1142
|
...e,
|
|
1128
1143
|
updateCheck: t.updateCheck,
|
|
@@ -1132,17 +1147,17 @@ function Yt(e, t) {
|
|
|
1132
1147
|
noCommandAction: t.noCommandAction
|
|
1133
1148
|
};
|
|
1134
1149
|
}
|
|
1135
|
-
function
|
|
1136
|
-
return
|
|
1150
|
+
function et(e, t) {
|
|
1151
|
+
return Wt.every((a) => e[a] === t[a]);
|
|
1137
1152
|
}
|
|
1138
|
-
function
|
|
1153
|
+
function Kt(e) {
|
|
1139
1154
|
if (!e.vaultItemSeparator.trim())
|
|
1140
1155
|
return "command.config.vault_item_sep.error.empty";
|
|
1141
1156
|
}
|
|
1142
|
-
function
|
|
1157
|
+
function Xt() {
|
|
1143
1158
|
return !!(process.stdin.isTTY && process.stdout.isTTY && typeof process.stdin.setRawMode == "function");
|
|
1144
1159
|
}
|
|
1145
|
-
function
|
|
1160
|
+
function Zt(e) {
|
|
1146
1161
|
return [
|
|
1147
1162
|
{
|
|
1148
1163
|
kind: "select",
|
|
@@ -1160,7 +1175,7 @@ function zt(e) {
|
|
|
1160
1175
|
kind: "input",
|
|
1161
1176
|
key: "vaultItemSeparator",
|
|
1162
1177
|
label: r("command.config.edit.field.vault_item_sep"),
|
|
1163
|
-
state:
|
|
1178
|
+
state: Yt(e.vaultItemSeparator)
|
|
1164
1179
|
},
|
|
1165
1180
|
{
|
|
1166
1181
|
kind: "select",
|
|
@@ -1201,17 +1216,17 @@ function zt(e) {
|
|
|
1201
1216
|
}
|
|
1202
1217
|
];
|
|
1203
1218
|
}
|
|
1204
|
-
function
|
|
1219
|
+
function $e(e, t, a) {
|
|
1205
1220
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1206
1221
|
}
|
|
1207
|
-
function
|
|
1222
|
+
function tt(e, t) {
|
|
1208
1223
|
const a = { ...t };
|
|
1209
1224
|
for (const i of e) {
|
|
1210
1225
|
if (i.kind === "input") {
|
|
1211
1226
|
a.vaultItemSeparator = i.state.value;
|
|
1212
1227
|
continue;
|
|
1213
1228
|
}
|
|
1214
|
-
const n =
|
|
1229
|
+
const n = H(i.state)?.value;
|
|
1215
1230
|
if (n) {
|
|
1216
1231
|
if (i.key === "updateCheck") {
|
|
1217
1232
|
a.updateCheck = n;
|
|
@@ -1230,78 +1245,82 @@ function Ge(e, t) {
|
|
|
1230
1245
|
}
|
|
1231
1246
|
return a;
|
|
1232
1247
|
}
|
|
1233
|
-
function
|
|
1248
|
+
function Qt(e) {
|
|
1234
1249
|
return Math.max(...e.map((t) => t.label.length), 1);
|
|
1235
1250
|
}
|
|
1236
|
-
function
|
|
1237
|
-
const o =
|
|
1238
|
-
|
|
1239
|
-
r("command.config.edit.
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
const f = e[m];
|
|
1249
|
-
if (!f)
|
|
1251
|
+
function N(e, t, a, i, n) {
|
|
1252
|
+
const o = tt(e, a), c = !et(o, a), s = Qt(e), l = e.length, d = t === l, m = r("command.config.edit.hint", {
|
|
1253
|
+
upDown: R(r("command.config.edit.key.up_down")),
|
|
1254
|
+
leftRight: R(r("command.config.edit.key.left_right")),
|
|
1255
|
+
type: R(r("command.config.edit.key.type")),
|
|
1256
|
+
enter: R(r("command.config.edit.key.enter")),
|
|
1257
|
+
cancel: R(r("command.config.edit.key.cancel"))
|
|
1258
|
+
}), u = [];
|
|
1259
|
+
u.push(v.bold(r("command.config.edit.title"))), u.push("");
|
|
1260
|
+
for (let k = 0; k < e.length; k += 1) {
|
|
1261
|
+
const x = e[k];
|
|
1262
|
+
if (!x)
|
|
1250
1263
|
continue;
|
|
1251
|
-
const
|
|
1252
|
-
u.push(`${
|
|
1253
|
-
}
|
|
1254
|
-
u.push(""), u.push(`${r("command.config.edit.action_prefix")} ${
|
|
1264
|
+
const L = k === t, T = L ? v.cyan(">") : " ", re = L ? v.bold(x.label.padEnd(s, " ")) : x.label.padEnd(s, " "), oe = x.kind === "select" ? te(x.state, L) : Ht(x.state, L, r("command.config.edit.input.placeholder"));
|
|
1265
|
+
u.push(`${T} ${re} ${oe}`);
|
|
1266
|
+
}
|
|
1267
|
+
u.push(""), u.push(`${r("command.config.edit.action_prefix")} ${te(i, d)}`), u.push(""), u.push(v.dim(r(c ? "command.config.edit.state.dirty" : "command.config.edit.state.clean"))), n && u.push(v.yellow(n));
|
|
1268
|
+
const _ = we({
|
|
1269
|
+
contentLines: u,
|
|
1270
|
+
footerLines: [m],
|
|
1271
|
+
rows: process.stdout.rows
|
|
1272
|
+
});
|
|
1273
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(`${_.join(`
|
|
1255
1274
|
`)}
|
|
1256
1275
|
`);
|
|
1257
1276
|
}
|
|
1258
|
-
async function
|
|
1259
|
-
if (!
|
|
1277
|
+
async function ea(e) {
|
|
1278
|
+
if (!Xt())
|
|
1260
1279
|
throw new Error(r("command.config.edit.error.no_tty"));
|
|
1261
|
-
const t = process.stdin, a =
|
|
1280
|
+
const t = process.stdin, a = Zt(e);
|
|
1262
1281
|
let i = O([
|
|
1263
1282
|
{ value: "save", label: r("command.config.edit.action.save") },
|
|
1264
1283
|
{ value: "cancel", label: r("command.config.edit.action.cancel") }
|
|
1265
1284
|
]), n = 0, o = "";
|
|
1266
|
-
return
|
|
1267
|
-
const s = (
|
|
1285
|
+
return ge.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((c) => {
|
|
1286
|
+
const s = (m) => {
|
|
1268
1287
|
t.off("keypress", d), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1269
|
-
`), c(
|
|
1288
|
+
`), c(m);
|
|
1270
1289
|
}, l = () => {
|
|
1271
|
-
const
|
|
1272
|
-
if (
|
|
1273
|
-
o = r(
|
|
1290
|
+
const m = tt(a, e), u = Kt(m);
|
|
1291
|
+
if (u) {
|
|
1292
|
+
o = r(u), N(a, n, e, i, o);
|
|
1274
1293
|
return;
|
|
1275
1294
|
}
|
|
1276
|
-
s(
|
|
1277
|
-
}, d = (
|
|
1278
|
-
if (
|
|
1295
|
+
s(m);
|
|
1296
|
+
}, d = (m, u) => {
|
|
1297
|
+
if (u.ctrl && u.name === "c") {
|
|
1279
1298
|
s(null);
|
|
1280
1299
|
return;
|
|
1281
1300
|
}
|
|
1282
|
-
if (
|
|
1301
|
+
if (u.name === "escape") {
|
|
1283
1302
|
s(null);
|
|
1284
1303
|
return;
|
|
1285
1304
|
}
|
|
1286
|
-
if (
|
|
1287
|
-
n =
|
|
1305
|
+
if (u.name === "up") {
|
|
1306
|
+
n = $e(n, "up", a.length + 1), o = "", N(a, n, e, i, o);
|
|
1288
1307
|
return;
|
|
1289
1308
|
}
|
|
1290
|
-
if (
|
|
1291
|
-
n =
|
|
1309
|
+
if (u.name === "down") {
|
|
1310
|
+
n = $e(n, "down", a.length + 1), o = "", N(a, n, e, i, o);
|
|
1292
1311
|
return;
|
|
1293
1312
|
}
|
|
1294
1313
|
if (n === a.length) {
|
|
1295
|
-
if (
|
|
1314
|
+
if (u.name === "q") {
|
|
1296
1315
|
s(null);
|
|
1297
1316
|
return;
|
|
1298
1317
|
}
|
|
1299
|
-
if (
|
|
1300
|
-
i =
|
|
1318
|
+
if (u.name === "left" || u.name === "right") {
|
|
1319
|
+
i = q(i, u.name), o = "", N(a, n, e, i, o);
|
|
1301
1320
|
return;
|
|
1302
1321
|
}
|
|
1303
|
-
if (
|
|
1304
|
-
if ((
|
|
1322
|
+
if (u.name === "return" || u.name === "enter") {
|
|
1323
|
+
if ((H(i)?.value ?? "save") === "cancel") {
|
|
1305
1324
|
s(null);
|
|
1306
1325
|
return;
|
|
1307
1326
|
}
|
|
@@ -1309,41 +1328,41 @@ async function qt(e) {
|
|
|
1309
1328
|
}
|
|
1310
1329
|
return;
|
|
1311
1330
|
}
|
|
1312
|
-
const
|
|
1313
|
-
if (!
|
|
1331
|
+
const _ = a[n];
|
|
1332
|
+
if (!_) {
|
|
1314
1333
|
s(null);
|
|
1315
1334
|
return;
|
|
1316
1335
|
}
|
|
1317
|
-
if (
|
|
1336
|
+
if (u.name === "q" && _.kind !== "input") {
|
|
1318
1337
|
s(null);
|
|
1319
1338
|
return;
|
|
1320
1339
|
}
|
|
1321
|
-
if (
|
|
1322
|
-
|
|
1340
|
+
if (u.name === "left" || u.name === "right") {
|
|
1341
|
+
_.kind === "select" ? _.state = q(_.state, u.name) : _.state = Te(_.state, m, u).state, o = "", N(a, n, e, i, o);
|
|
1323
1342
|
return;
|
|
1324
1343
|
}
|
|
1325
|
-
if (
|
|
1326
|
-
const
|
|
1327
|
-
if (
|
|
1344
|
+
if (_.kind === "input") {
|
|
1345
|
+
const k = Te(_.state, m, u);
|
|
1346
|
+
if (_.state = k.state, k.action === "cancel") {
|
|
1328
1347
|
s(null);
|
|
1329
1348
|
return;
|
|
1330
1349
|
}
|
|
1331
|
-
if (
|
|
1350
|
+
if (k.action === "submit") {
|
|
1332
1351
|
l();
|
|
1333
1352
|
return;
|
|
1334
1353
|
}
|
|
1335
|
-
o = "",
|
|
1354
|
+
o = "", N(a, n, e, i, o);
|
|
1336
1355
|
return;
|
|
1337
1356
|
}
|
|
1338
|
-
(
|
|
1357
|
+
(u.name === "return" || u.name === "enter") && l();
|
|
1339
1358
|
};
|
|
1340
|
-
t.on("keypress", d),
|
|
1359
|
+
t.on("keypress", d), N(a, n, e, i, o);
|
|
1341
1360
|
});
|
|
1342
1361
|
}
|
|
1343
|
-
function
|
|
1362
|
+
function ta(e, t) {
|
|
1344
1363
|
const a = e.command("config").description(r("command.config.description"));
|
|
1345
1364
|
a.command("list").description(r("command.config.list.description")).option("-c, --comment", r("command.config.list.option.comment")).action(
|
|
1346
|
-
(i) =>
|
|
1365
|
+
(i) => b(async () => {
|
|
1347
1366
|
const n = await t.configService.getConfig();
|
|
1348
1367
|
if (i.comment) {
|
|
1349
1368
|
const o = [
|
|
@@ -1356,7 +1375,7 @@ function Wt(e, t) {
|
|
|
1356
1375
|
["no_command_action", n.noCommandAction, r("command.config.list.comment.no_command_action")]
|
|
1357
1376
|
];
|
|
1358
1377
|
console.log(
|
|
1359
|
-
|
|
1378
|
+
B(
|
|
1360
1379
|
[
|
|
1361
1380
|
r("command.config.list.table.key"),
|
|
1362
1381
|
r("command.config.list.table.value"),
|
|
@@ -1369,25 +1388,25 @@ function Wt(e, t) {
|
|
|
1369
1388
|
console.log(JSON.stringify(n, null, 2));
|
|
1370
1389
|
})
|
|
1371
1390
|
), a.command("edit").alias("e").description(r("command.config.edit.description")).action(
|
|
1372
|
-
() =>
|
|
1373
|
-
const i = await t.configService.getConfig(), n =
|
|
1391
|
+
() => b(async () => {
|
|
1392
|
+
const i = await t.configService.getConfig(), n = Jt(i), o = await ea(n);
|
|
1374
1393
|
if (!o) {
|
|
1375
1394
|
A(r("command.config.edit.cancelled"));
|
|
1376
1395
|
return;
|
|
1377
1396
|
}
|
|
1378
|
-
if (
|
|
1397
|
+
if (et(n, o)) {
|
|
1379
1398
|
A(r("command.config.edit.no_changes"));
|
|
1380
1399
|
return;
|
|
1381
1400
|
}
|
|
1382
|
-
const c =
|
|
1383
|
-
await t.context.saveConfig(c),
|
|
1401
|
+
const c = Gt(i, o);
|
|
1402
|
+
await t.context.saveConfig(c), ee(c), C(r("command.config.edit.saved")), await t.auditLogger.log(
|
|
1384
1403
|
"INFO",
|
|
1385
1404
|
{ main: "config", sub: "edit", source: "u" },
|
|
1386
1405
|
r("command.config.edit.audit.saved")
|
|
1387
1406
|
), await V(t);
|
|
1388
1407
|
})
|
|
1389
1408
|
), a.command("update-check").description(r("command.config.update_check.description")).argument("<state>", r("command.config.update_check.argument")).action(
|
|
1390
|
-
(i) =>
|
|
1409
|
+
(i) => b(async () => {
|
|
1391
1410
|
const n = i.toLowerCase();
|
|
1392
1411
|
if (n !== "on" && n !== "off")
|
|
1393
1412
|
throw new Error(r("command.config.state.error"));
|
|
@@ -1398,19 +1417,19 @@ function Wt(e, t) {
|
|
|
1398
1417
|
), await V(t);
|
|
1399
1418
|
})
|
|
1400
1419
|
), a.command("style").description(r("command.config.style.description")).argument("<state>", r("command.config.style.argument")).action(
|
|
1401
|
-
(i) =>
|
|
1420
|
+
(i) => b(async () => {
|
|
1402
1421
|
const n = i.toLowerCase();
|
|
1403
1422
|
if (n !== "on" && n !== "off")
|
|
1404
1423
|
throw new Error(r("command.config.state.error"));
|
|
1405
1424
|
const o = await t.configService.setStyle(n);
|
|
1406
|
-
|
|
1425
|
+
ee(o), C(r("command.config.style.updated", { state: n })), await t.auditLogger.log(
|
|
1407
1426
|
"INFO",
|
|
1408
1427
|
{ main: "config", sub: "style", args: [n], source: "u" },
|
|
1409
1428
|
r("command.config.style.updated", { state: n })
|
|
1410
1429
|
);
|
|
1411
1430
|
})
|
|
1412
1431
|
), a.command("vault-item-sep").description(r("command.config.vault_item_sep.description")).argument("<sep>", r("command.config.vault_item_sep.argument")).action(
|
|
1413
|
-
(i) =>
|
|
1432
|
+
(i) => b(async () => {
|
|
1414
1433
|
if (!i.trim())
|
|
1415
1434
|
throw new Error(r("command.config.vault_item_sep.error.empty"));
|
|
1416
1435
|
await t.configService.setVaultItemSeparator(i), C(
|
|
@@ -1426,7 +1445,7 @@ function Wt(e, t) {
|
|
|
1426
1445
|
), await V(t);
|
|
1427
1446
|
})
|
|
1428
1447
|
), a.command("no-command-action").description(r("command.config.no_command_action.description")).argument("<action>", r("command.config.no_command_action.argument")).action(
|
|
1429
|
-
(i) =>
|
|
1448
|
+
(i) => b(async () => {
|
|
1430
1449
|
const n = i.toLowerCase();
|
|
1431
1450
|
if (n !== "help" && n !== "list" && n !== "unknown")
|
|
1432
1451
|
throw new Error(r("command.config.no_command_action.error.invalid"));
|
|
@@ -1437,7 +1456,7 @@ function Wt(e, t) {
|
|
|
1437
1456
|
);
|
|
1438
1457
|
})
|
|
1439
1458
|
), a.command("language").description(r("command.config.language.description")).argument("<language>", r("command.config.language.argument")).action(
|
|
1440
|
-
(i) =>
|
|
1459
|
+
(i) => b(async () => {
|
|
1441
1460
|
const n = i.toLowerCase();
|
|
1442
1461
|
if (n !== "zh" && n !== "en")
|
|
1443
1462
|
throw new Error(r("command.config.language.error.invalid"));
|
|
@@ -1449,8 +1468,8 @@ function Wt(e, t) {
|
|
|
1449
1468
|
})
|
|
1450
1469
|
);
|
|
1451
1470
|
}
|
|
1452
|
-
const
|
|
1453
|
-
function
|
|
1471
|
+
const aa = "__ARCHIVER_CD__:";
|
|
1472
|
+
function ia(e, t) {
|
|
1454
1473
|
if (e.includes(`
|
|
1455
1474
|
`) || e.includes("\r"))
|
|
1456
1475
|
throw new Error(
|
|
@@ -1459,80 +1478,81 @@ function Gt(e, t) {
|
|
|
1459
1478
|
})
|
|
1460
1479
|
);
|
|
1461
1480
|
}
|
|
1462
|
-
function
|
|
1463
|
-
return
|
|
1481
|
+
function na(e) {
|
|
1482
|
+
return ia(e, r("util.cd.label.archive_slot_path")), `${aa}${e}`;
|
|
1464
1483
|
}
|
|
1465
|
-
async function
|
|
1466
|
-
console.log(
|
|
1484
|
+
async function ra(e) {
|
|
1485
|
+
console.log(na(e));
|
|
1467
1486
|
}
|
|
1468
|
-
function
|
|
1487
|
+
function Ne(e) {
|
|
1469
1488
|
return r(e === "enter" ? "command.list.interactive.action.enter" : "command.list.interactive.action.restore");
|
|
1470
1489
|
}
|
|
1471
|
-
function
|
|
1472
|
-
return
|
|
1490
|
+
function at() {
|
|
1491
|
+
return Ie();
|
|
1473
1492
|
}
|
|
1474
|
-
function
|
|
1475
|
-
return t === "enter" || t === "restore" ? e.status ===
|
|
1493
|
+
function he(e, t) {
|
|
1494
|
+
return t === "enter" || t === "restore" ? e.status === y.Archived : !1;
|
|
1476
1495
|
}
|
|
1477
|
-
function
|
|
1496
|
+
function ye(e, t) {
|
|
1478
1497
|
return O(
|
|
1479
1498
|
[
|
|
1480
|
-
{ value: "enter", label:
|
|
1481
|
-
{ value: "restore", label:
|
|
1499
|
+
{ value: "enter", label: Ne("enter"), disabled: !he(e, "enter") },
|
|
1500
|
+
{ value: "restore", label: Ne("restore"), disabled: !he(e, "restore") }
|
|
1482
1501
|
],
|
|
1483
1502
|
t
|
|
1484
1503
|
);
|
|
1485
1504
|
}
|
|
1486
|
-
function
|
|
1487
|
-
return
|
|
1505
|
+
function oa(e, t) {
|
|
1506
|
+
return H(ye(e, t))?.value ?? t;
|
|
1488
1507
|
}
|
|
1489
|
-
function
|
|
1490
|
-
const i =
|
|
1491
|
-
return
|
|
1508
|
+
function De(e, t, a) {
|
|
1509
|
+
const i = ye(e, t), n = q(i, a);
|
|
1510
|
+
return H(n)?.value ?? t;
|
|
1492
1511
|
}
|
|
1493
|
-
function
|
|
1512
|
+
function Pe(e, t, a) {
|
|
1494
1513
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1495
1514
|
}
|
|
1496
|
-
function
|
|
1515
|
+
function F(e, t, a, i) {
|
|
1497
1516
|
const n = e[t];
|
|
1498
1517
|
if (!n)
|
|
1499
1518
|
return;
|
|
1500
|
-
const o = process.stdout.rows ?? 24, c =
|
|
1501
|
-
m.push(r("command.list.interactive.hint", {
|
|
1519
|
+
const o = process.stdout.rows ?? 24, c = r("command.list.interactive.hint", {
|
|
1502
1520
|
upDown: R(r("command.list.interactive.key.up_down")),
|
|
1503
1521
|
leftRight: R(r("command.list.interactive.key.left_right")),
|
|
1504
1522
|
enter: R(r("command.list.interactive.key.enter")),
|
|
1505
1523
|
cancel: R(r("command.list.interactive.key.cancel"))
|
|
1506
|
-
}))
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
), m.
|
|
1511
|
-
for (let
|
|
1512
|
-
const
|
|
1513
|
-
if (!
|
|
1524
|
+
}), s = ye(n, a), l = [
|
|
1525
|
+
`${r("command.list.interactive.action_prefix")} ${te(s)}`,
|
|
1526
|
+
i ? v.yellow(i) : "",
|
|
1527
|
+
""
|
|
1528
|
+
], m = Math.max(o - l.length - 2, 2), u = Math.max(Math.floor(m / 2), 1), _ = Math.floor(u / 2), k = Math.max(e.length - u, 0), x = Math.min(Math.max(t - _, 0), k), L = Math.min(x + u, e.length), T = [...l];
|
|
1529
|
+
for (let W = x; W < L; W += 1) {
|
|
1530
|
+
const U = e[W];
|
|
1531
|
+
if (!U)
|
|
1514
1532
|
continue;
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1533
|
+
const ke = W === t, lt = ke ? v.cyan(">") : " ", dt = U.status === y.Archived ? v.green("A") : v.gray("R"), Ce = `${lt} [${String(U.id).padStart(4, " ")}] ${dt} ${U.title}`, Ee = ` ${v.dim(U.path)}`;
|
|
1534
|
+
ke ? (T.push(v.bold(Ce)), T.push(v.cyan(Ee))) : (T.push(Ce), T.push(Ee));
|
|
1517
1535
|
}
|
|
1518
|
-
|
|
1536
|
+
const re = [
|
|
1519
1537
|
v.dim(
|
|
1520
1538
|
r("command.list.interactive.showing", {
|
|
1521
|
-
start:
|
|
1522
|
-
end:
|
|
1539
|
+
start: x + 1,
|
|
1540
|
+
end: L,
|
|
1523
1541
|
total: e.length
|
|
1524
1542
|
})
|
|
1525
|
-
)
|
|
1526
|
-
|
|
1543
|
+
),
|
|
1544
|
+
c
|
|
1545
|
+
], oe = we({ contentLines: T, footerLines: re, rows: o });
|
|
1546
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(`${oe.join(`
|
|
1527
1547
|
`)}
|
|
1528
1548
|
`);
|
|
1529
1549
|
}
|
|
1530
|
-
async function
|
|
1531
|
-
if (e.length === 0 || !
|
|
1550
|
+
async function ca(e) {
|
|
1551
|
+
if (e.length === 0 || !at())
|
|
1532
1552
|
return null;
|
|
1533
1553
|
const t = process.stdin;
|
|
1534
1554
|
let a = 0, i = "enter", n = "";
|
|
1535
|
-
return
|
|
1555
|
+
return ge.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((o) => {
|
|
1536
1556
|
const c = (l) => {
|
|
1537
1557
|
t.off("keypress", s), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1538
1558
|
`), o(l);
|
|
@@ -1542,80 +1562,80 @@ async function Qt(e) {
|
|
|
1542
1562
|
return;
|
|
1543
1563
|
}
|
|
1544
1564
|
if (d.name === "up") {
|
|
1545
|
-
a =
|
|
1565
|
+
a = Pe(a, "up", e.length), n = "", F(e, a, i, n);
|
|
1546
1566
|
return;
|
|
1547
1567
|
}
|
|
1548
1568
|
if (d.name === "down") {
|
|
1549
|
-
a =
|
|
1569
|
+
a = Pe(a, "down", e.length), n = "", F(e, a, i, n);
|
|
1550
1570
|
return;
|
|
1551
1571
|
}
|
|
1552
1572
|
if (d.name === "left") {
|
|
1553
|
-
const
|
|
1554
|
-
if (!
|
|
1573
|
+
const m = e[a];
|
|
1574
|
+
if (!m) {
|
|
1555
1575
|
c(null);
|
|
1556
1576
|
return;
|
|
1557
1577
|
}
|
|
1558
|
-
i =
|
|
1578
|
+
i = De(m, i, "left"), n = "", F(e, a, i, n);
|
|
1559
1579
|
return;
|
|
1560
1580
|
}
|
|
1561
1581
|
if (d.name === "right") {
|
|
1562
|
-
const
|
|
1563
|
-
if (!
|
|
1582
|
+
const m = e[a];
|
|
1583
|
+
if (!m) {
|
|
1564
1584
|
c(null);
|
|
1565
1585
|
return;
|
|
1566
1586
|
}
|
|
1567
|
-
i =
|
|
1587
|
+
i = De(m, i, "right"), n = "", F(e, a, i, n);
|
|
1568
1588
|
return;
|
|
1569
1589
|
}
|
|
1570
1590
|
if (d.name === "return" || d.name === "enter") {
|
|
1571
|
-
const
|
|
1572
|
-
if (!
|
|
1591
|
+
const m = e[a];
|
|
1592
|
+
if (!m) {
|
|
1573
1593
|
c(null);
|
|
1574
1594
|
return;
|
|
1575
1595
|
}
|
|
1576
|
-
const
|
|
1577
|
-
if (!
|
|
1578
|
-
n = r("command.list.interactive.note.restored_unavailable"),
|
|
1596
|
+
const u = oa(m, i);
|
|
1597
|
+
if (!he(m, u)) {
|
|
1598
|
+
n = r("command.list.interactive.note.restored_unavailable"), F(e, a, i, n);
|
|
1579
1599
|
return;
|
|
1580
1600
|
}
|
|
1581
|
-
c({ entry:
|
|
1601
|
+
c({ entry: m, action: u });
|
|
1582
1602
|
return;
|
|
1583
1603
|
}
|
|
1584
1604
|
(d.name === "q" || d.name === "escape") && c(null);
|
|
1585
1605
|
};
|
|
1586
|
-
t.on("keypress", s),
|
|
1606
|
+
t.on("keypress", s), F(e, a, i, n);
|
|
1587
1607
|
});
|
|
1588
1608
|
}
|
|
1589
|
-
function
|
|
1590
|
-
return e.vaultId ===
|
|
1609
|
+
function be(e, t) {
|
|
1610
|
+
return e.vaultId === g.Vault.id ? e.item : `${e.vaultName}${t}${e.item}`;
|
|
1591
1611
|
}
|
|
1592
|
-
function
|
|
1612
|
+
function sa(e) {
|
|
1593
1613
|
return String(e).padStart(4, "0");
|
|
1594
1614
|
}
|
|
1595
|
-
function
|
|
1596
|
-
return e.status ===
|
|
1615
|
+
function it(e) {
|
|
1616
|
+
return e.status === y.Archived ? "A" : "R";
|
|
1597
1617
|
}
|
|
1598
|
-
function
|
|
1599
|
-
const a =
|
|
1600
|
-
return `[${
|
|
1618
|
+
function la(e, t) {
|
|
1619
|
+
const a = Xe(it(e));
|
|
1620
|
+
return `[${sa(e.id)}] ${a} ${be(e, t)}`;
|
|
1601
1621
|
}
|
|
1602
|
-
function
|
|
1603
|
-
return e.map((a) =>
|
|
1622
|
+
function da(e, t) {
|
|
1623
|
+
return e.map((a) => la(a, t)).join(`
|
|
1604
1624
|
`);
|
|
1605
1625
|
}
|
|
1606
|
-
function
|
|
1607
|
-
return e.map((a) => `${a.id} ${
|
|
1626
|
+
function ua(e, t) {
|
|
1627
|
+
return e.map((a) => `${a.id} ${it(a)} ${be(a, t)}`).join(`
|
|
1608
1628
|
`);
|
|
1609
1629
|
}
|
|
1610
|
-
function
|
|
1630
|
+
function ma(e, t) {
|
|
1611
1631
|
return e.map((a) => ({
|
|
1612
1632
|
id: a.id,
|
|
1613
1633
|
status: a.status,
|
|
1614
|
-
title:
|
|
1634
|
+
title: be(a, t),
|
|
1615
1635
|
path: a.displayPath
|
|
1616
1636
|
}));
|
|
1617
1637
|
}
|
|
1618
|
-
async function
|
|
1638
|
+
async function va(e, t) {
|
|
1619
1639
|
const a = t.entry.id;
|
|
1620
1640
|
if (t.action === "restore") {
|
|
1621
1641
|
const n = await e.archiveService.restore([a]);
|
|
@@ -1627,13 +1647,13 @@ async function na(e, t) {
|
|
|
1627
1647
|
})
|
|
1628
1648
|
);
|
|
1629
1649
|
for (const o of n.failed)
|
|
1630
|
-
|
|
1650
|
+
j(
|
|
1631
1651
|
r("command.archive.result.restore.failed", {
|
|
1632
1652
|
id: o.id ?? "-",
|
|
1633
1653
|
message: o.message
|
|
1634
1654
|
})
|
|
1635
1655
|
);
|
|
1636
|
-
|
|
1656
|
+
K("restore", n), await V(e);
|
|
1637
1657
|
return;
|
|
1638
1658
|
}
|
|
1639
1659
|
const i = await e.archiveService.resolveCdTarget(String(a));
|
|
@@ -1650,11 +1670,11 @@ async function na(e, t) {
|
|
|
1650
1670
|
archiveId: i.archiveId
|
|
1651
1671
|
}),
|
|
1652
1672
|
{ aid: i.archiveId, vid: i.vault.id }
|
|
1653
|
-
), await
|
|
1673
|
+
), await ra(i.slotPath);
|
|
1654
1674
|
}
|
|
1655
|
-
function
|
|
1675
|
+
function ha(e, t) {
|
|
1656
1676
|
e.command("list").description(r("command.list.description")).option("-r, --restored", r("command.list.option.restored")).option("-a, --all", r("command.list.option.all")).option("-v, --vault <vault>", r("command.list.option.vault")).option("--no-interactive", r("command.list.option.no_interactive")).option("-p, --plain", r("command.list.option.plain")).action(
|
|
1657
|
-
(a) =>
|
|
1677
|
+
(a) => b(async () => {
|
|
1658
1678
|
const i = await t.archiveService.listEntries(a), n = await t.archiveService.decorateEntries(i), o = await t.configService.getConfig();
|
|
1659
1679
|
if (n.length === 0) {
|
|
1660
1680
|
if (a.plain)
|
|
@@ -1663,26 +1683,26 @@ function oa(e, t) {
|
|
|
1663
1683
|
return;
|
|
1664
1684
|
}
|
|
1665
1685
|
if (a.plain) {
|
|
1666
|
-
console.log(
|
|
1686
|
+
console.log(ua(n, o.vaultItemSeparator));
|
|
1667
1687
|
return;
|
|
1668
1688
|
}
|
|
1669
|
-
const c = a.interactive !== !1 &&
|
|
1689
|
+
const c = a.interactive !== !1 && at(), s = n.some((d) => d.status === y.Archived);
|
|
1670
1690
|
if (!c || !s) {
|
|
1671
|
-
console.log(
|
|
1691
|
+
console.log(da(n, o.vaultItemSeparator)), c && !s && A(r("command.list.restored_only_notice"));
|
|
1672
1692
|
return;
|
|
1673
1693
|
}
|
|
1674
|
-
const l = await
|
|
1694
|
+
const l = await ca(ma(n, o.vaultItemSeparator));
|
|
1675
1695
|
if (!l) {
|
|
1676
1696
|
A(r("command.list.cancelled"));
|
|
1677
1697
|
return;
|
|
1678
1698
|
}
|
|
1679
|
-
await
|
|
1699
|
+
await va(t, l);
|
|
1680
1700
|
})
|
|
1681
1701
|
);
|
|
1682
1702
|
}
|
|
1683
|
-
function
|
|
1703
|
+
function fa(e, t) {
|
|
1684
1704
|
e.command("log").description(r("command.log.description")).argument("[range]", r("command.log.argument.range")).option("--id <id>", r("command.log.option.id")).action(
|
|
1685
|
-
(a, i) =>
|
|
1705
|
+
(a, i) => b(async () => {
|
|
1686
1706
|
if (i.id !== void 0) {
|
|
1687
1707
|
if (!/^\d+$/.test(i.id))
|
|
1688
1708
|
throw new Error(r("command.log.error.invalid_id", { id: i.id }));
|
|
@@ -1694,12 +1714,12 @@ function ca(e, t) {
|
|
|
1694
1714
|
id: l.log.id
|
|
1695
1715
|
})
|
|
1696
1716
|
), console.log(
|
|
1697
|
-
|
|
1717
|
+
B(
|
|
1698
1718
|
[r("command.log.detail.table.field"), r("command.log.detail.table.value")],
|
|
1699
1719
|
[
|
|
1700
1720
|
[r("command.log.detail.field.id"), String(l.log.id)],
|
|
1701
1721
|
[r("command.log.detail.field.time"), l.log.operedAt],
|
|
1702
|
-
[r("command.log.detail.field.level"),
|
|
1722
|
+
[r("command.log.detail.field.level"), Re(l.log.level)],
|
|
1703
1723
|
[
|
|
1704
1724
|
r("command.log.detail.field.operation"),
|
|
1705
1725
|
`${l.log.oper.main}${l.log.oper.sub ? `/${l.log.oper.sub}` : ""}`
|
|
@@ -1716,7 +1736,7 @@ function ca(e, t) {
|
|
|
1716
1736
|
]
|
|
1717
1737
|
)
|
|
1718
1738
|
), l.archive && (A(r("command.log.detail.linked_archive")), console.log(
|
|
1719
|
-
|
|
1739
|
+
B(
|
|
1720
1740
|
[
|
|
1721
1741
|
r("command.log.detail.archive.table.id"),
|
|
1722
1742
|
r("command.log.detail.archive.table.status"),
|
|
@@ -1727,7 +1747,7 @@ function ca(e, t) {
|
|
|
1727
1747
|
[
|
|
1728
1748
|
[
|
|
1729
1749
|
String(l.archive.id),
|
|
1730
|
-
|
|
1750
|
+
Xe(l.archive.status),
|
|
1731
1751
|
String(l.archive.vaultId),
|
|
1732
1752
|
l.archive.item,
|
|
1733
1753
|
l.archive.directory
|
|
@@ -1735,7 +1755,7 @@ function ca(e, t) {
|
|
|
1735
1755
|
]
|
|
1736
1756
|
)
|
|
1737
1757
|
)), l.vault && (A(r("command.log.detail.linked_vault")), console.log(
|
|
1738
|
-
|
|
1758
|
+
B(
|
|
1739
1759
|
[
|
|
1740
1760
|
r("command.log.detail.vault.table.id"),
|
|
1741
1761
|
r("command.log.detail.vault.table.name"),
|
|
@@ -1746,7 +1766,7 @@ function ca(e, t) {
|
|
|
1746
1766
|
[
|
|
1747
1767
|
String(l.vault.id),
|
|
1748
1768
|
l.vault.name,
|
|
1749
|
-
|
|
1769
|
+
$t(l.vault.status),
|
|
1750
1770
|
l.vault.remark
|
|
1751
1771
|
]
|
|
1752
1772
|
]
|
|
@@ -1754,7 +1774,7 @@ function ca(e, t) {
|
|
|
1754
1774
|
));
|
|
1755
1775
|
return;
|
|
1756
1776
|
}
|
|
1757
|
-
const n =
|
|
1777
|
+
const n = Lt(a), o = await t.logService.getLogs(n);
|
|
1758
1778
|
if (o.length === 0) {
|
|
1759
1779
|
A(r("command.log.empty"));
|
|
1760
1780
|
return;
|
|
@@ -1762,14 +1782,14 @@ function ca(e, t) {
|
|
|
1762
1782
|
const c = o.map((s) => [
|
|
1763
1783
|
String(s.id),
|
|
1764
1784
|
s.operedAt,
|
|
1765
|
-
|
|
1785
|
+
Re(s.level),
|
|
1766
1786
|
`${s.oper.main}${s.oper.sub ? `/${s.oper.sub}` : ""}`,
|
|
1767
1787
|
s.message,
|
|
1768
1788
|
s.archiveIds !== void 0 ? String(s.archiveIds) : "",
|
|
1769
1789
|
s.vaultIds !== void 0 ? String(s.vaultIds) : ""
|
|
1770
1790
|
]);
|
|
1771
1791
|
console.log(
|
|
1772
|
-
|
|
1792
|
+
B(
|
|
1773
1793
|
[
|
|
1774
1794
|
r("command.log.table.id"),
|
|
1775
1795
|
r("command.log.table.time"),
|
|
@@ -1785,40 +1805,40 @@ function ca(e, t) {
|
|
|
1785
1805
|
})
|
|
1786
1806
|
);
|
|
1787
1807
|
}
|
|
1788
|
-
async function
|
|
1789
|
-
await
|
|
1808
|
+
async function Y(e) {
|
|
1809
|
+
await p.mkdir(e, { recursive: !0 });
|
|
1790
1810
|
}
|
|
1791
|
-
const E = (e) =>
|
|
1792
|
-
function
|
|
1811
|
+
const E = (e) => p.access(e).then(() => !0).catch(() => !1), Me = (e) => p.realpath(e).catch(() => h.resolve(e)), ga = (e, t) => h.normalize(e) === h.normalize(t);
|
|
1812
|
+
function nt(e, t) {
|
|
1793
1813
|
const a = h.relative(h.resolve(e), h.resolve(t));
|
|
1794
1814
|
return a.length > 0 && !a.startsWith("..") && !h.isAbsolute(a);
|
|
1795
1815
|
}
|
|
1796
|
-
function
|
|
1797
|
-
return
|
|
1816
|
+
function pa(e, t) {
|
|
1817
|
+
return ga(e, t) || nt(e, t);
|
|
1798
1818
|
}
|
|
1799
|
-
async function
|
|
1819
|
+
async function X(e) {
|
|
1800
1820
|
const t = h.dirname(e);
|
|
1801
|
-
await
|
|
1821
|
+
await Y(t), await E(e) || await p.writeFile(e, "", "utf8");
|
|
1802
1822
|
}
|
|
1803
|
-
async function
|
|
1823
|
+
async function ae(e) {
|
|
1804
1824
|
try {
|
|
1805
|
-
return await
|
|
1825
|
+
return await p.lstat(e);
|
|
1806
1826
|
} catch (t) {
|
|
1807
1827
|
if (t.code === "ENOENT")
|
|
1808
1828
|
return;
|
|
1809
1829
|
throw t;
|
|
1810
1830
|
}
|
|
1811
1831
|
}
|
|
1812
|
-
async function
|
|
1832
|
+
async function _a(e) {
|
|
1813
1833
|
try {
|
|
1814
|
-
return (await
|
|
1834
|
+
return (await p.readdir(e, { withFileTypes: !0 })).filter((a) => a.isDirectory()).map((a) => a.name);
|
|
1815
1835
|
} catch (t) {
|
|
1816
1836
|
if (t.code === "ENOENT")
|
|
1817
1837
|
return [];
|
|
1818
1838
|
throw t;
|
|
1819
1839
|
}
|
|
1820
1840
|
}
|
|
1821
|
-
class
|
|
1841
|
+
class rt extends Error {
|
|
1822
1842
|
constructor(t) {
|
|
1823
1843
|
super(
|
|
1824
1844
|
r("service.vault.error.removed_exists", {
|
|
@@ -1827,7 +1847,7 @@ class Qe extends Error {
|
|
|
1827
1847
|
), this.name = "VaultRemovedExistsError";
|
|
1828
1848
|
}
|
|
1829
1849
|
}
|
|
1830
|
-
class
|
|
1850
|
+
class wa {
|
|
1831
1851
|
constructor(t, a) {
|
|
1832
1852
|
this.context = t, this.configService = a;
|
|
1833
1853
|
}
|
|
@@ -1838,10 +1858,10 @@ class ua {
|
|
|
1838
1858
|
const a = t.name.trim();
|
|
1839
1859
|
if (!a)
|
|
1840
1860
|
throw new Error(r("service.vault.error.name_empty"));
|
|
1841
|
-
if (a ===
|
|
1861
|
+
if (a === g.Vault.name)
|
|
1842
1862
|
throw new Error(
|
|
1843
1863
|
r("service.vault.error.name_reserved", {
|
|
1844
|
-
name:
|
|
1864
|
+
name: g.Vault.name
|
|
1845
1865
|
})
|
|
1846
1866
|
);
|
|
1847
1867
|
const i = await this.context.loadVaults(), n = i.find((s) => s.name === a);
|
|
@@ -1853,14 +1873,14 @@ class ua {
|
|
|
1853
1873
|
);
|
|
1854
1874
|
if (n?.status === "Removed") {
|
|
1855
1875
|
if (!t.recoverRemoved)
|
|
1856
|
-
throw new
|
|
1876
|
+
throw new rt(a);
|
|
1857
1877
|
return n.status = S.Valid, await this.context.ensureVaultDir(n.id), await this.context.saveVaults(i), t.activate && await this.configService.setCurrentVault(n.id), { vault: n, recovered: !0 };
|
|
1858
1878
|
}
|
|
1859
1879
|
const c = {
|
|
1860
1880
|
id: await this.context.nextAutoIncrement("vaultId"),
|
|
1861
1881
|
name: a,
|
|
1862
1882
|
remark: t.remark ?? "",
|
|
1863
|
-
createdAt:
|
|
1883
|
+
createdAt: _e(),
|
|
1864
1884
|
status: S.Valid
|
|
1865
1885
|
};
|
|
1866
1886
|
return i.push(c), await this.context.saveVaults(i), await this.context.ensureVaultDir(c.id), t.activate && await this.configService.setCurrentVault(c.id), { vault: c, recovered: !1 };
|
|
@@ -1901,10 +1921,10 @@ class ua {
|
|
|
1901
1921
|
const i = a.trim();
|
|
1902
1922
|
if (!i)
|
|
1903
1923
|
throw new Error(r("service.vault.error.new_name_empty"));
|
|
1904
|
-
if (i ===
|
|
1924
|
+
if (i === g.Vault.name)
|
|
1905
1925
|
throw new Error(
|
|
1906
1926
|
r("service.vault.error.name_reserved", {
|
|
1907
|
-
name:
|
|
1927
|
+
name: g.Vault.name
|
|
1908
1928
|
})
|
|
1909
1929
|
);
|
|
1910
1930
|
const n = await this.context.loadVaults(), o = n.find((s) => s.name === t || String(s.id) === t);
|
|
@@ -1939,7 +1959,7 @@ class ua {
|
|
|
1939
1959
|
reference: t
|
|
1940
1960
|
})
|
|
1941
1961
|
);
|
|
1942
|
-
if (a.id ===
|
|
1962
|
+
if (a.id === g.Vault.id || a.status === S.Protected)
|
|
1943
1963
|
throw new Error(r("service.vault.error.default_cannot_remove"));
|
|
1944
1964
|
if (a.status === S.Removed)
|
|
1945
1965
|
throw new Error(
|
|
@@ -1947,12 +1967,12 @@ class ua {
|
|
|
1947
1967
|
name: a.name
|
|
1948
1968
|
})
|
|
1949
1969
|
);
|
|
1950
|
-
const i = await this.context.loadListEntries(), n = i.filter((d) => d.vaultId === a.id && d.status ===
|
|
1951
|
-
await this.context.ensureVaultDir(
|
|
1970
|
+
const i = await this.context.loadListEntries(), n = i.filter((d) => d.vaultId === a.id && d.status === y.Archived);
|
|
1971
|
+
await this.context.ensureVaultDir(g.Vault.id), await this.validateMoveToDefault(n);
|
|
1952
1972
|
const o = [];
|
|
1953
1973
|
for (const d of n) {
|
|
1954
|
-
const
|
|
1955
|
-
await
|
|
1974
|
+
const m = this.context.archivePath(a.id, d.id), u = this.context.archivePath(g.Vault.id, d.id);
|
|
1975
|
+
await p.rename(m, u), d.vaultId = g.Vault.id, o.push(d.id);
|
|
1956
1976
|
}
|
|
1957
1977
|
const c = await this.context.loadVaults(), s = c.find((d) => d.id === a.id);
|
|
1958
1978
|
if (!s)
|
|
@@ -1963,11 +1983,11 @@ class ua {
|
|
|
1963
1983
|
);
|
|
1964
1984
|
s.status = S.Removed, await this.context.saveListEntries(i), await this.context.saveVaults(c);
|
|
1965
1985
|
const l = await this.context.loadConfig();
|
|
1966
|
-
return l.currentVaultId === a.id && (l.currentVaultId =
|
|
1986
|
+
return l.currentVaultId === a.id && (l.currentVaultId = g.Vault.id, await this.context.saveConfig(l)), { vault: s, movedArchiveIds: o };
|
|
1967
1987
|
}
|
|
1968
1988
|
async validateMoveToDefault(t) {
|
|
1969
1989
|
for (const a of t) {
|
|
1970
|
-
const i = this.context.archivePath(a.vaultId, a.id), n = this.context.archivePath(
|
|
1990
|
+
const i = this.context.archivePath(a.vaultId, a.id), n = this.context.archivePath(g.Vault.id, a.id);
|
|
1971
1991
|
if (!await E(i))
|
|
1972
1992
|
throw new Error(
|
|
1973
1993
|
r("service.vault.error.archived_object_missing", {
|
|
@@ -1991,31 +2011,31 @@ class ua {
|
|
|
1991
2011
|
}
|
|
1992
2012
|
async listArchivedIdsInVault(t) {
|
|
1993
2013
|
const a = this.context.vaultDir(t);
|
|
1994
|
-
return await E(a) ? (await
|
|
2014
|
+
return await E(a) ? (await p.readdir(a, { withFileTypes: !0 })).filter((o) => o.isFile() || o.isDirectory() || o.isSymbolicLink()).map((o) => o.name).filter((o) => /^\d+$/.test(o)).map((o) => Number(o)).sort((o, c) => o - c) : [];
|
|
1995
2015
|
}
|
|
1996
2016
|
getVaultDisplay(t) {
|
|
1997
|
-
return t.id ===
|
|
2017
|
+
return t.id === g.Vault.id ? `${t.name}(${t.id})` : `${t.name}(${t.id})`;
|
|
1998
2018
|
}
|
|
1999
2019
|
vaultRoot(t) {
|
|
2000
|
-
return h.join(
|
|
2020
|
+
return h.join(f.Dir.vaults, String(t.id));
|
|
2001
2021
|
}
|
|
2002
2022
|
}
|
|
2003
|
-
async function
|
|
2004
|
-
const t =
|
|
2023
|
+
async function ot(e) {
|
|
2024
|
+
const t = pt.createInterface({ input: wt, output: _t });
|
|
2005
2025
|
try {
|
|
2006
2026
|
return (await t.question(e)).trim();
|
|
2007
2027
|
} finally {
|
|
2008
2028
|
t.close();
|
|
2009
2029
|
}
|
|
2010
2030
|
}
|
|
2011
|
-
async function
|
|
2012
|
-
const a = (await
|
|
2031
|
+
async function Oe(e, t = !0) {
|
|
2032
|
+
const a = (await ot(e)).toLowerCase();
|
|
2013
2033
|
return a ? ["y", "yes"].includes(a) : !t;
|
|
2014
2034
|
}
|
|
2015
|
-
function
|
|
2035
|
+
function Ia(e, t) {
|
|
2016
2036
|
const a = e.command("vault").description(r("command.vault.description"));
|
|
2017
2037
|
a.command("use").description(r("command.vault.use.description")).argument("<name-or-id>", r("command.vault.use.argument")).action(
|
|
2018
|
-
(i) =>
|
|
2038
|
+
(i) => b(async () => {
|
|
2019
2039
|
const n = await t.vaultService.useVault(i);
|
|
2020
2040
|
C(
|
|
2021
2041
|
r("command.vault.use.updated", {
|
|
@@ -2033,7 +2053,7 @@ function ma(e, t) {
|
|
|
2033
2053
|
), await V(t);
|
|
2034
2054
|
})
|
|
2035
2055
|
), a.command("create").description(r("command.vault.create.description")).argument("<name>", r("command.vault.create.argument")).option("-r, --remark <remark>", r("command.vault.create.option.remark")).option("-a, --activate", r("command.vault.create.option.activate")).action(
|
|
2036
|
-
(i, n) =>
|
|
2056
|
+
(i, n) => b(async () => {
|
|
2037
2057
|
let o = !1;
|
|
2038
2058
|
const c = async (s) => {
|
|
2039
2059
|
const l = await t.vaultService.createVault({
|
|
@@ -2073,13 +2093,13 @@ function ma(e, t) {
|
|
|
2073
2093
|
try {
|
|
2074
2094
|
await c(!1);
|
|
2075
2095
|
} catch (s) {
|
|
2076
|
-
if (s instanceof
|
|
2077
|
-
if (!await
|
|
2096
|
+
if (s instanceof rt) {
|
|
2097
|
+
if (!await Oe(
|
|
2078
2098
|
r("command.vault.create.confirm_recover", {
|
|
2079
2099
|
name: i
|
|
2080
2100
|
})
|
|
2081
2101
|
)) {
|
|
2082
|
-
|
|
2102
|
+
se(r("command.vault.operation.cancelled"));
|
|
2083
2103
|
return;
|
|
2084
2104
|
}
|
|
2085
2105
|
await c(!0);
|
|
@@ -2089,22 +2109,22 @@ function ma(e, t) {
|
|
|
2089
2109
|
await V(t);
|
|
2090
2110
|
})
|
|
2091
2111
|
), a.command("remove").description(r("command.vault.remove.description")).argument("<name-or-id>", r("command.vault.remove.argument")).action(
|
|
2092
|
-
(i) =>
|
|
2093
|
-
if (!await
|
|
2112
|
+
(i) => b(async () => {
|
|
2113
|
+
if (!await Oe(
|
|
2094
2114
|
r("command.vault.remove.confirm", {
|
|
2095
2115
|
nameOrId: i
|
|
2096
2116
|
})
|
|
2097
2117
|
)) {
|
|
2098
|
-
|
|
2118
|
+
se(r("command.vault.operation.cancelled"));
|
|
2099
2119
|
return;
|
|
2100
2120
|
}
|
|
2101
2121
|
const o = Math.random().toString(36).slice(2, 8).toUpperCase();
|
|
2102
|
-
if (await
|
|
2122
|
+
if (await ot(
|
|
2103
2123
|
r("command.vault.remove.verify_prompt", {
|
|
2104
2124
|
verifyCode: o
|
|
2105
2125
|
})
|
|
2106
2126
|
) !== o) {
|
|
2107
|
-
|
|
2127
|
+
se(r("command.vault.remove.verify_mismatch"));
|
|
2108
2128
|
return;
|
|
2109
2129
|
}
|
|
2110
2130
|
const s = await t.vaultService.removeVault(i);
|
|
@@ -2116,7 +2136,7 @@ function ma(e, t) {
|
|
|
2116
2136
|
), s.movedArchiveIds.length > 0 && A(
|
|
2117
2137
|
r("command.vault.remove.moved_to_default", {
|
|
2118
2138
|
count: s.movedArchiveIds.length,
|
|
2119
|
-
name:
|
|
2139
|
+
name: g.Vault.name
|
|
2120
2140
|
})
|
|
2121
2141
|
), await t.auditLogger.log(
|
|
2122
2142
|
"WARN",
|
|
@@ -2134,7 +2154,7 @@ function ma(e, t) {
|
|
|
2134
2154
|
), await V(t);
|
|
2135
2155
|
})
|
|
2136
2156
|
), a.command("recover").description(r("command.vault.recover.description")).argument("<name-or-id>", r("command.vault.recover.argument")).action(
|
|
2137
|
-
(i) =>
|
|
2157
|
+
(i) => b(async () => {
|
|
2138
2158
|
const n = await t.vaultService.recoverVault(i);
|
|
2139
2159
|
C(
|
|
2140
2160
|
r("command.vault.recover.done", {
|
|
@@ -2157,7 +2177,7 @@ function ma(e, t) {
|
|
|
2157
2177
|
), await V(t);
|
|
2158
2178
|
})
|
|
2159
2179
|
), a.command("rename").description(r("command.vault.rename.description")).argument("<old>", r("command.vault.rename.argument.old")).argument("<new>", r("command.vault.rename.argument.new")).action(
|
|
2160
|
-
(i, n) =>
|
|
2180
|
+
(i, n) => b(async () => {
|
|
2161
2181
|
const o = await t.vaultService.renameVault(i, n);
|
|
2162
2182
|
C(
|
|
2163
2183
|
r("command.vault.rename.done", {
|
|
@@ -2180,7 +2200,7 @@ function ma(e, t) {
|
|
|
2180
2200
|
), await V(t);
|
|
2181
2201
|
})
|
|
2182
2202
|
), a.command("list").description(r("command.vault.list.description")).option("-a, --all", r("command.vault.list.option.all")).action(
|
|
2183
|
-
(i) =>
|
|
2203
|
+
(i) => b(async () => {
|
|
2184
2204
|
const n = await t.vaultService.listVaults(!!i.all);
|
|
2185
2205
|
if (n.length === 0) {
|
|
2186
2206
|
A(r("command.vault.list.empty"));
|
|
@@ -2192,11 +2212,11 @@ function ma(e, t) {
|
|
|
2192
2212
|
})
|
|
2193
2213
|
);
|
|
2194
2214
|
}
|
|
2195
|
-
function
|
|
2196
|
-
const t = new
|
|
2197
|
-
return t.name(
|
|
2215
|
+
function ya(e) {
|
|
2216
|
+
const t = new gt();
|
|
2217
|
+
return t.name(Vt).description(r("app.description")).version(e.version), Dt(t, e), Ia(t, e), ha(t, e), fa(t, e), ta(t, e), t;
|
|
2198
2218
|
}
|
|
2199
|
-
const
|
|
2219
|
+
const Fe = {
|
|
2200
2220
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2201
2221
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2202
2222
|
functionPattern: /(^|\n)\s*(function\s+)?arv\s*(\(\))?\s*\{/m,
|
|
@@ -2221,7 +2241,7 @@ const Le = {
|
|
|
2221
2241
|
fi
|
|
2222
2242
|
return $status
|
|
2223
2243
|
}`
|
|
2224
|
-
},
|
|
2244
|
+
}, ba = {
|
|
2225
2245
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2226
2246
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2227
2247
|
functionPattern: /(^|\n)\s*function\s+arv\b/m,
|
|
@@ -2247,7 +2267,7 @@ const Le = {
|
|
|
2247
2267
|
rm -f $target_tmp
|
|
2248
2268
|
return $status
|
|
2249
2269
|
end`
|
|
2250
|
-
},
|
|
2270
|
+
}, ka = {
|
|
2251
2271
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2252
2272
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2253
2273
|
functionPattern: /(^|\r?\n)\s*function\s+arv\b/im,
|
|
@@ -2287,7 +2307,7 @@ end`
|
|
|
2287
2307
|
$global:LASTEXITCODE = $status
|
|
2288
2308
|
}`
|
|
2289
2309
|
};
|
|
2290
|
-
function
|
|
2310
|
+
function Ca(e) {
|
|
2291
2311
|
const t = h.basename(e).toLowerCase();
|
|
2292
2312
|
if (t.includes("bash"))
|
|
2293
2313
|
return "bash";
|
|
@@ -2298,17 +2318,17 @@ function ga(e) {
|
|
|
2298
2318
|
if (t.includes("pwsh") || t.includes("powershell"))
|
|
2299
2319
|
return "powershell";
|
|
2300
2320
|
}
|
|
2301
|
-
function
|
|
2321
|
+
function je(e) {
|
|
2302
2322
|
return e.endsWith(`
|
|
2303
2323
|
`) ? e : `${e}
|
|
2304
2324
|
`;
|
|
2305
2325
|
}
|
|
2306
|
-
function
|
|
2326
|
+
function ct(e) {
|
|
2307
2327
|
return `${e.startMarker}
|
|
2308
2328
|
${e.body}
|
|
2309
2329
|
${e.endMarker}`;
|
|
2310
2330
|
}
|
|
2311
|
-
function
|
|
2331
|
+
function Ea(e, t) {
|
|
2312
2332
|
const a = e.indexOf(t.startMarker);
|
|
2313
2333
|
if (a === -1)
|
|
2314
2334
|
return;
|
|
@@ -2319,8 +2339,8 @@ function pa(e, t) {
|
|
|
2319
2339
|
end: i + t.endMarker.length
|
|
2320
2340
|
};
|
|
2321
2341
|
}
|
|
2322
|
-
function
|
|
2323
|
-
const a =
|
|
2342
|
+
function Aa(e, t) {
|
|
2343
|
+
const a = ct(t);
|
|
2324
2344
|
if (e.trim().length === 0)
|
|
2325
2345
|
return `${a}
|
|
2326
2346
|
`;
|
|
@@ -2332,7 +2352,7 @@ function _a(e, t) {
|
|
|
2332
2352
|
return `${e}${i}${a}
|
|
2333
2353
|
`;
|
|
2334
2354
|
}
|
|
2335
|
-
async function
|
|
2355
|
+
async function Sa(e, t) {
|
|
2336
2356
|
for (const a of t) {
|
|
2337
2357
|
const i = h.join(e, a);
|
|
2338
2358
|
if (await E(i))
|
|
@@ -2340,35 +2360,35 @@ async function wa(e, t) {
|
|
|
2340
2360
|
}
|
|
2341
2361
|
return h.join(e, t[0] ?? ".bashrc");
|
|
2342
2362
|
}
|
|
2343
|
-
async function
|
|
2344
|
-
await
|
|
2345
|
-
const a = await
|
|
2363
|
+
async function J(e, t) {
|
|
2364
|
+
await X(e);
|
|
2365
|
+
const a = await p.readFile(e, "utf8"), i = Ea(a, t);
|
|
2346
2366
|
if (i) {
|
|
2347
|
-
const o = a.slice(i.start, i.end), c =
|
|
2367
|
+
const o = a.slice(i.start, i.end), c = ct(t);
|
|
2348
2368
|
if (o === c)
|
|
2349
2369
|
return !1;
|
|
2350
2370
|
const s = `${a.slice(0, i.start)}${c}${a.slice(i.end)}`;
|
|
2351
|
-
return await
|
|
2371
|
+
return await p.writeFile(e, je(s), "utf8"), !0;
|
|
2352
2372
|
}
|
|
2353
2373
|
if (t.functionPattern.test(a))
|
|
2354
2374
|
return !1;
|
|
2355
|
-
const n =
|
|
2356
|
-
return await
|
|
2375
|
+
const n = je(Aa(a, t));
|
|
2376
|
+
return await p.writeFile(e, n, "utf8"), !0;
|
|
2357
2377
|
}
|
|
2358
|
-
function
|
|
2378
|
+
function xa(e, t) {
|
|
2359
2379
|
const a = h.resolve(t), i = h.resolve(e);
|
|
2360
2380
|
if (i === a)
|
|
2361
2381
|
return "~";
|
|
2362
2382
|
const n = `${a}${h.sep}`;
|
|
2363
2383
|
return i.startsWith(n) ? `~${i.slice(a.length)}` : e;
|
|
2364
2384
|
}
|
|
2365
|
-
function
|
|
2385
|
+
function Va(e) {
|
|
2366
2386
|
return `'${e.replaceAll("'", "'\\''")}'`;
|
|
2367
2387
|
}
|
|
2368
|
-
function
|
|
2388
|
+
function Ra(e) {
|
|
2369
2389
|
return `'${e.replaceAll("'", "''")}'`;
|
|
2370
2390
|
}
|
|
2371
|
-
async function
|
|
2391
|
+
async function La(e) {
|
|
2372
2392
|
if (process.platform === "win32") {
|
|
2373
2393
|
const t = [
|
|
2374
2394
|
h.join(e, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1"),
|
|
@@ -2381,58 +2401,58 @@ async function ka(e) {
|
|
|
2381
2401
|
}
|
|
2382
2402
|
return h.join(e, ".config", "powershell", "Microsoft.PowerShell_profile.ps1");
|
|
2383
2403
|
}
|
|
2384
|
-
function
|
|
2385
|
-
const n =
|
|
2404
|
+
function G(e, t, a, i) {
|
|
2405
|
+
const n = xa(t, a);
|
|
2386
2406
|
return e === "powershell" ? {
|
|
2387
2407
|
installed: i,
|
|
2388
2408
|
shell: e,
|
|
2389
2409
|
profilePath: n,
|
|
2390
|
-
reloadCommand: `. ${
|
|
2410
|
+
reloadCommand: `. ${Ra(t)}`
|
|
2391
2411
|
} : {
|
|
2392
2412
|
installed: i,
|
|
2393
2413
|
shell: e,
|
|
2394
2414
|
profilePath: n,
|
|
2395
|
-
reloadCommand: `source ${
|
|
2415
|
+
reloadCommand: `source ${Va(t)}`
|
|
2396
2416
|
};
|
|
2397
2417
|
}
|
|
2398
|
-
async function
|
|
2418
|
+
async function Ta(e = {}) {
|
|
2399
2419
|
const t = e.env ?? process.env;
|
|
2400
2420
|
if (t.ARCHIVER_DISABLE_SHELL_INIT === "1")
|
|
2401
2421
|
return { installed: !1 };
|
|
2402
2422
|
if (!(e.stdinIsTTY ?? !!process.stdin.isTTY))
|
|
2403
2423
|
return { installed: !1 };
|
|
2404
|
-
const i = e.homeDir ?? t.HOME ?? t.USERPROFILE ??
|
|
2424
|
+
const i = e.homeDir ?? t.HOME ?? t.USERPROFILE ?? Je.homedir();
|
|
2405
2425
|
if (!i)
|
|
2406
2426
|
return { installed: !1 };
|
|
2407
|
-
const n = e.shellPath ?? t.SHELL ?? "", o =
|
|
2427
|
+
const n = e.shellPath ?? t.SHELL ?? "", o = Ca(n);
|
|
2408
2428
|
if (!o)
|
|
2409
2429
|
return { installed: !1 };
|
|
2410
2430
|
try {
|
|
2411
2431
|
if (o === "bash") {
|
|
2412
|
-
const l = await
|
|
2413
|
-
return
|
|
2432
|
+
const l = await Sa(i, [".bashrc", ".bash_profile", ".profile"]), d = await J(l, Fe);
|
|
2433
|
+
return G(o, l, i, d);
|
|
2414
2434
|
}
|
|
2415
2435
|
if (o === "zsh") {
|
|
2416
|
-
const l = h.join(i, ".zshrc"), d = await
|
|
2417
|
-
return
|
|
2436
|
+
const l = h.join(i, ".zshrc"), d = await J(l, Fe);
|
|
2437
|
+
return G(o, l, i, d);
|
|
2418
2438
|
}
|
|
2419
2439
|
if (o === "fish") {
|
|
2420
2440
|
const l = h.join(i, ".config", "fish", "functions", "arv.fish");
|
|
2421
|
-
await
|
|
2422
|
-
const d = await
|
|
2423
|
-
return
|
|
2441
|
+
await Y(h.dirname(l));
|
|
2442
|
+
const d = await J(l, ba);
|
|
2443
|
+
return G(o, l, i, d);
|
|
2424
2444
|
}
|
|
2425
|
-
const c = await
|
|
2426
|
-
await
|
|
2427
|
-
const s = await
|
|
2428
|
-
return
|
|
2445
|
+
const c = await La(i);
|
|
2446
|
+
await Y(h.dirname(c));
|
|
2447
|
+
const s = await J(c, ka);
|
|
2448
|
+
return G(o, c, i, s);
|
|
2429
2449
|
} catch {
|
|
2430
2450
|
return { installed: !1 };
|
|
2431
2451
|
}
|
|
2432
2452
|
}
|
|
2433
|
-
async function
|
|
2453
|
+
async function ie(e) {
|
|
2434
2454
|
try {
|
|
2435
|
-
const t = await
|
|
2455
|
+
const t = await p.readFile(e, "utf8");
|
|
2436
2456
|
return t.trim() ? t.split(/\r?\n/).map((i) => i.trim()).filter((i) => i.length > 0).map((i, n) => {
|
|
2437
2457
|
try {
|
|
2438
2458
|
return JSON.parse(i);
|
|
@@ -2451,36 +2471,36 @@ async function ee(e) {
|
|
|
2451
2471
|
throw t;
|
|
2452
2472
|
}
|
|
2453
2473
|
}
|
|
2454
|
-
async function
|
|
2474
|
+
async function Ye(e, t) {
|
|
2455
2475
|
const a = t.map((i) => JSON.stringify(i)).join(`
|
|
2456
2476
|
`);
|
|
2457
|
-
await
|
|
2477
|
+
await p.writeFile(e, a.length > 0 ? `${a}
|
|
2458
2478
|
` : "", "utf8");
|
|
2459
2479
|
}
|
|
2460
|
-
async function
|
|
2461
|
-
await
|
|
2480
|
+
async function st(e, t) {
|
|
2481
|
+
await p.appendFile(e, `${JSON.stringify(t)}
|
|
2462
2482
|
`, "utf8");
|
|
2463
2483
|
}
|
|
2464
|
-
function
|
|
2484
|
+
function He(e) {
|
|
2465
2485
|
return {
|
|
2466
|
-
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId :
|
|
2486
|
+
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId : g.Config.currentVaultId,
|
|
2467
2487
|
updateCheck: e.updateCheck === "off" ? "off" : "on",
|
|
2468
2488
|
lastUpdateCheck: typeof e.lastUpdateCheck == "string" ? e.lastUpdateCheck : "",
|
|
2469
|
-
vaultItemSeparator: typeof e.vaultItemSeparator == "string" && e.vaultItemSeparator.length > 0 ? e.vaultItemSeparator :
|
|
2489
|
+
vaultItemSeparator: typeof e.vaultItemSeparator == "string" && e.vaultItemSeparator.length > 0 ? e.vaultItemSeparator : g.Config.vaultItemSeparator,
|
|
2470
2490
|
style: e.style === "off" ? "off" : "on",
|
|
2471
2491
|
language: e.language === "en" ? "en" : "zh",
|
|
2472
2492
|
noCommandAction: e.noCommandAction === "help" || e.noCommandAction === "list" ? e.noCommandAction : "unknown"
|
|
2473
2493
|
};
|
|
2474
2494
|
}
|
|
2475
|
-
function
|
|
2495
|
+
function Ue(e) {
|
|
2476
2496
|
return {
|
|
2477
2497
|
logId: Number.isInteger(e.logId) && e.logId >= 0 ? e.logId : 0,
|
|
2478
2498
|
vaultId: Number.isInteger(e.vaultId) && e.vaultId >= 0 ? e.vaultId : 0,
|
|
2479
2499
|
archiveId: Number.isInteger(e.archiveId) && e.archiveId >= 0 ? e.archiveId : 0
|
|
2480
2500
|
};
|
|
2481
2501
|
}
|
|
2482
|
-
function
|
|
2483
|
-
const t = e.isDirectory === 1 ? 1 : 0, a = e.status ===
|
|
2502
|
+
function ze(e) {
|
|
2503
|
+
const t = e.isDirectory === 1 ? 1 : 0, a = e.status === y.Restored ? y.Restored : y.Archived;
|
|
2484
2504
|
return {
|
|
2485
2505
|
archivedAt: String(e.archivedAt ?? ""),
|
|
2486
2506
|
status: a,
|
|
@@ -2493,7 +2513,7 @@ function Me(e) {
|
|
|
2493
2513
|
remark: String(e.remark ?? "")
|
|
2494
2514
|
};
|
|
2495
2515
|
}
|
|
2496
|
-
function
|
|
2516
|
+
function Be(e) {
|
|
2497
2517
|
const t = S[e.status] ?? S.Valid;
|
|
2498
2518
|
return {
|
|
2499
2519
|
id: e.id,
|
|
@@ -2503,35 +2523,35 @@ function Fe(e) {
|
|
|
2503
2523
|
status: t
|
|
2504
2524
|
};
|
|
2505
2525
|
}
|
|
2506
|
-
class
|
|
2526
|
+
class $a {
|
|
2507
2527
|
configCache;
|
|
2508
2528
|
autoIncrCache;
|
|
2509
2529
|
listCache;
|
|
2510
2530
|
vaultCache;
|
|
2511
2531
|
async init() {
|
|
2512
|
-
for (const a of Object.values(
|
|
2513
|
-
await
|
|
2514
|
-
await
|
|
2532
|
+
for (const a of Object.values(f.Dir))
|
|
2533
|
+
await Y(a);
|
|
2534
|
+
await Y(this.vaultDir(g.Vault.id)), await Se(f.File.config, de), await Se(f.File.autoIncr, ue), await X(f.File.list), await X(f.File.vaults), await X(f.File.log);
|
|
2515
2535
|
const t = await this.loadConfig();
|
|
2516
|
-
t.currentVaultId === 0 || await E(this.vaultDir(t.currentVaultId)) || (t.currentVaultId =
|
|
2536
|
+
t.currentVaultId === 0 || await E(this.vaultDir(t.currentVaultId)) || (t.currentVaultId = g.Vault.id, await this.saveConfig(t));
|
|
2517
2537
|
}
|
|
2518
2538
|
async loadConfig(t = !1) {
|
|
2519
2539
|
if (this.configCache && !t)
|
|
2520
2540
|
return this.configCache;
|
|
2521
|
-
const a = await
|
|
2522
|
-
return
|
|
2541
|
+
const a = await ve(f.File.config, g.Config), i = He({ ...g.Config, ...a });
|
|
2542
|
+
return Z(i.language), this.configCache = i, i;
|
|
2523
2543
|
}
|
|
2524
2544
|
async saveConfig(t) {
|
|
2525
|
-
this.configCache =
|
|
2545
|
+
this.configCache = He(t), Z(this.configCache.language), await xe(f.File.config, this.configCache, de);
|
|
2526
2546
|
}
|
|
2527
2547
|
async loadAutoIncr(t = !1) {
|
|
2528
2548
|
if (this.autoIncrCache && !t)
|
|
2529
2549
|
return this.autoIncrCache;
|
|
2530
|
-
const a = await
|
|
2550
|
+
const a = await ve(f.File.autoIncr, g.AutoIncr), i = Ue({ ...g.AutoIncr, ...a });
|
|
2531
2551
|
return this.autoIncrCache = i, i;
|
|
2532
2552
|
}
|
|
2533
2553
|
async saveAutoIncr(t) {
|
|
2534
|
-
this.autoIncrCache =
|
|
2554
|
+
this.autoIncrCache = Ue(t), await xe(f.File.autoIncr, this.autoIncrCache, ue);
|
|
2535
2555
|
}
|
|
2536
2556
|
async nextAutoIncrement(t) {
|
|
2537
2557
|
const a = await this.loadAutoIncr();
|
|
@@ -2540,31 +2560,31 @@ class Ea {
|
|
|
2540
2560
|
async loadListEntries(t = !1) {
|
|
2541
2561
|
if (this.listCache && !t)
|
|
2542
2562
|
return this.listCache;
|
|
2543
|
-
const a = await
|
|
2544
|
-
return this.listCache = a.map((i) =>
|
|
2563
|
+
const a = await ie(f.File.list);
|
|
2564
|
+
return this.listCache = a.map((i) => ze(i)).filter((i) => Number.isInteger(i.id) && i.id > 0), this.listCache.sort((i, n) => i.id - n.id), this.listCache;
|
|
2545
2565
|
}
|
|
2546
2566
|
async saveListEntries(t) {
|
|
2547
|
-
this.listCache = [...t].sort((a, i) => a.id - i.id), await
|
|
2567
|
+
this.listCache = [...t].sort((a, i) => a.id - i.id), await Ye(f.File.list, this.listCache);
|
|
2548
2568
|
}
|
|
2549
2569
|
async appendListEntry(t) {
|
|
2550
|
-
const a =
|
|
2551
|
-
this.listCache || (this.listCache = await this.loadListEntries()), this.listCache.push(a), this.listCache.sort((i, n) => i.id - n.id), await
|
|
2570
|
+
const a = ze(t);
|
|
2571
|
+
this.listCache || (this.listCache = await this.loadListEntries()), this.listCache.push(a), this.listCache.sort((i, n) => i.id - n.id), await st(f.File.list, a);
|
|
2552
2572
|
}
|
|
2553
2573
|
async loadVaults(t = !1) {
|
|
2554
2574
|
if (this.vaultCache && !t)
|
|
2555
2575
|
return this.vaultCache;
|
|
2556
|
-
const a = await
|
|
2557
|
-
return this.vaultCache = a.map((i) =>
|
|
2576
|
+
const a = await ie(f.File.vaults);
|
|
2577
|
+
return this.vaultCache = a.map((i) => Be(i)).filter((i) => Number.isInteger(i.id) && i.id > 0).sort((i, n) => i.id - n.id), this.vaultCache;
|
|
2558
2578
|
}
|
|
2559
2579
|
async saveVaults(t) {
|
|
2560
|
-
const a = t.map((i) =>
|
|
2561
|
-
this.vaultCache = a, await
|
|
2580
|
+
const a = t.map((i) => Be(i)).filter((i) => i.id > 0).sort((i, n) => i.id - n.id);
|
|
2581
|
+
this.vaultCache = a, await Ye(f.File.vaults, a);
|
|
2562
2582
|
}
|
|
2563
2583
|
async getVaults(t) {
|
|
2564
2584
|
const a = t?.includeRemoved ?? !1, i = t?.withDefault ?? !0, n = await this.loadVaults(), o = a ? n : n.filter((c) => c.status === "Valid");
|
|
2565
2585
|
return i ? [
|
|
2566
2586
|
{
|
|
2567
|
-
...
|
|
2587
|
+
...g.Vault,
|
|
2568
2588
|
remark: r("defaults.vault.remark")
|
|
2569
2589
|
},
|
|
2570
2590
|
...o
|
|
@@ -2587,7 +2607,7 @@ class Ea {
|
|
|
2587
2607
|
return s;
|
|
2588
2608
|
}
|
|
2589
2609
|
vaultDir(t) {
|
|
2590
|
-
return h.join(
|
|
2610
|
+
return h.join(f.Dir.vaults, String(t));
|
|
2591
2611
|
}
|
|
2592
2612
|
archivePath(t, a) {
|
|
2593
2613
|
return h.join(this.vaultDir(t), String(a));
|
|
@@ -2596,7 +2616,7 @@ class Ea {
|
|
|
2596
2616
|
return h.join(this.archivePath(t, a), i);
|
|
2597
2617
|
}
|
|
2598
2618
|
async resolveArchiveStorageLocation(t) {
|
|
2599
|
-
const a = this.archivePath(t.vaultId, t.id), i = await
|
|
2619
|
+
const a = this.archivePath(t.vaultId, t.id), i = await ae(a);
|
|
2600
2620
|
if (!i || !i.isDirectory())
|
|
2601
2621
|
return;
|
|
2602
2622
|
const n = this.archiveObjectPath(t.vaultId, t.id, t.item);
|
|
@@ -2607,13 +2627,13 @@ class Ea {
|
|
|
2607
2627
|
};
|
|
2608
2628
|
}
|
|
2609
2629
|
async ensureVaultDir(t) {
|
|
2610
|
-
await
|
|
2630
|
+
await Y(this.vaultDir(t));
|
|
2611
2631
|
}
|
|
2612
2632
|
async removeVaultDir(t) {
|
|
2613
|
-
t !==
|
|
2633
|
+
t !== g.Vault.id && await p.rm(this.vaultDir(t), { recursive: !0, force: !0 });
|
|
2614
2634
|
}
|
|
2615
2635
|
}
|
|
2616
|
-
class
|
|
2636
|
+
class Na {
|
|
2617
2637
|
constructor(t, a) {
|
|
2618
2638
|
this.context = t, this.logger = a;
|
|
2619
2639
|
}
|
|
@@ -2627,8 +2647,8 @@ class Aa {
|
|
|
2627
2647
|
const o = { ok: [], failed: [] };
|
|
2628
2648
|
for (const c of n) {
|
|
2629
2649
|
const s = await this.context.nextAutoIncrement("archiveId"), l = this.context.archivePath(i.id, s), d = {
|
|
2630
|
-
archivedAt:
|
|
2631
|
-
status:
|
|
2650
|
+
archivedAt: _e(),
|
|
2651
|
+
status: y.Archived,
|
|
2632
2652
|
isDirectory: c.stats.isDirectory() ? 1 : 0,
|
|
2633
2653
|
vaultId: i.id,
|
|
2634
2654
|
id: s,
|
|
@@ -2644,13 +2664,13 @@ class Aa {
|
|
|
2644
2664
|
path: l
|
|
2645
2665
|
})
|
|
2646
2666
|
);
|
|
2647
|
-
await
|
|
2648
|
-
const
|
|
2667
|
+
await p.mkdir(l, { recursive: !1 });
|
|
2668
|
+
const m = this.context.archiveObjectPath(i.id, s, d.item);
|
|
2649
2669
|
try {
|
|
2650
|
-
await
|
|
2651
|
-
} catch (
|
|
2652
|
-
throw await
|
|
2653
|
-
}),
|
|
2670
|
+
await p.rename(c.resolvedPath, m);
|
|
2671
|
+
} catch (u) {
|
|
2672
|
+
throw await p.rmdir(l).catch(() => {
|
|
2673
|
+
}), u;
|
|
2654
2674
|
}
|
|
2655
2675
|
await this.context.appendListEntry(d), await this.logger.log(
|
|
2656
2676
|
"INFO",
|
|
@@ -2675,8 +2695,8 @@ class Aa {
|
|
|
2675
2695
|
id: i.id
|
|
2676
2696
|
})
|
|
2677
2697
|
});
|
|
2678
|
-
} catch (
|
|
2679
|
-
const
|
|
2698
|
+
} catch (m) {
|
|
2699
|
+
const u = m.message;
|
|
2680
2700
|
await this.logger.log(
|
|
2681
2701
|
"ERROR",
|
|
2682
2702
|
{
|
|
@@ -2689,13 +2709,13 @@ class Aa {
|
|
|
2689
2709
|
},
|
|
2690
2710
|
r("service.archive.log.archive_failed", {
|
|
2691
2711
|
input: c.input,
|
|
2692
|
-
message:
|
|
2712
|
+
message: u
|
|
2693
2713
|
})
|
|
2694
2714
|
), o.failed.push({
|
|
2695
2715
|
id: s,
|
|
2696
2716
|
input: c.input,
|
|
2697
2717
|
success: !1,
|
|
2698
|
-
message:
|
|
2718
|
+
message: u
|
|
2699
2719
|
});
|
|
2700
2720
|
}
|
|
2701
2721
|
}
|
|
@@ -2713,7 +2733,7 @@ class Aa {
|
|
|
2713
2733
|
id: c
|
|
2714
2734
|
})
|
|
2715
2735
|
);
|
|
2716
|
-
if (s.status !==
|
|
2736
|
+
if (s.status !== y.Archived)
|
|
2717
2737
|
throw new Error(
|
|
2718
2738
|
r("service.archive.error.id_already_restored", {
|
|
2719
2739
|
id: c
|
|
@@ -2746,10 +2766,10 @@ class Aa {
|
|
|
2746
2766
|
path: d
|
|
2747
2767
|
})
|
|
2748
2768
|
);
|
|
2749
|
-
await
|
|
2750
|
-
if (
|
|
2751
|
-
throw
|
|
2752
|
-
}), s.status =
|
|
2769
|
+
await p.mkdir(s.directory, { recursive: !0 }), await p.rename(l.objectPath, d), await p.rmdir(l.slotPath).catch((m) => {
|
|
2770
|
+
if (m.code !== "ENOENT")
|
|
2771
|
+
throw m;
|
|
2772
|
+
}), s.status = y.Restored, o = !0, await this.logger.log(
|
|
2753
2773
|
"INFO",
|
|
2754
2774
|
{
|
|
2755
2775
|
main: "restore",
|
|
@@ -2764,8 +2784,8 @@ class Aa {
|
|
|
2764
2784
|
success: !0,
|
|
2765
2785
|
message: r("service.archive.result.restored_to", { path: d })
|
|
2766
2786
|
});
|
|
2767
|
-
} catch (
|
|
2768
|
-
const
|
|
2787
|
+
} catch (m) {
|
|
2788
|
+
const u = m.message;
|
|
2769
2789
|
await this.logger.log(
|
|
2770
2790
|
"ERROR",
|
|
2771
2791
|
{
|
|
@@ -2773,13 +2793,13 @@ class Aa {
|
|
|
2773
2793
|
args: [String(c)],
|
|
2774
2794
|
source: "u"
|
|
2775
2795
|
},
|
|
2776
|
-
r("service.archive.log.restore_failed", { id: c, message:
|
|
2796
|
+
r("service.archive.log.restore_failed", { id: c, message: u }),
|
|
2777
2797
|
{ aid: c, vid: s.vaultId }
|
|
2778
2798
|
), n.failed.push({
|
|
2779
2799
|
id: c,
|
|
2780
2800
|
input: String(c),
|
|
2781
2801
|
success: !1,
|
|
2782
|
-
message:
|
|
2802
|
+
message: u
|
|
2783
2803
|
});
|
|
2784
2804
|
}
|
|
2785
2805
|
}
|
|
@@ -2801,49 +2821,49 @@ class Aa {
|
|
|
2801
2821
|
await this.context.ensureVaultDir(i.id);
|
|
2802
2822
|
const n = await this.context.loadListEntries(), o = new Map(n.map((d) => [d.id, d])), c = /* @__PURE__ */ new Map();
|
|
2803
2823
|
for (const d of t) {
|
|
2804
|
-
const
|
|
2805
|
-
if (!
|
|
2824
|
+
const m = o.get(d);
|
|
2825
|
+
if (!m)
|
|
2806
2826
|
throw new Error(
|
|
2807
2827
|
r("service.archive.error.id_not_exists", {
|
|
2808
2828
|
id: d
|
|
2809
2829
|
})
|
|
2810
2830
|
);
|
|
2811
|
-
if (
|
|
2831
|
+
if (m.status !== y.Archived)
|
|
2812
2832
|
throw new Error(
|
|
2813
2833
|
r("service.archive.error.id_restored_cannot_move", {
|
|
2814
2834
|
id: d
|
|
2815
2835
|
})
|
|
2816
2836
|
);
|
|
2817
|
-
if (
|
|
2837
|
+
if (m.vaultId === i.id)
|
|
2818
2838
|
throw new Error(
|
|
2819
2839
|
r("service.archive.error.id_already_in_vault", {
|
|
2820
2840
|
id: d,
|
|
2821
2841
|
vault: i.name
|
|
2822
2842
|
})
|
|
2823
2843
|
);
|
|
2824
|
-
const
|
|
2825
|
-
if (!
|
|
2844
|
+
const u = await this.context.resolveArchiveStorageLocation(m), _ = this.context.archivePath(m.vaultId, m.id), k = this.context.archivePath(i.id, m.id);
|
|
2845
|
+
if (!u)
|
|
2826
2846
|
throw new Error(
|
|
2827
2847
|
r("service.archive.error.object_missing", {
|
|
2828
|
-
path:
|
|
2848
|
+
path: _
|
|
2829
2849
|
})
|
|
2830
2850
|
);
|
|
2831
|
-
if (await E(
|
|
2851
|
+
if (await E(k))
|
|
2832
2852
|
throw new Error(
|
|
2833
2853
|
r("service.archive.error.target_slot_exists", {
|
|
2834
|
-
path:
|
|
2854
|
+
path: k
|
|
2835
2855
|
})
|
|
2836
2856
|
);
|
|
2837
|
-
c.set(d,
|
|
2857
|
+
c.set(d, u);
|
|
2838
2858
|
}
|
|
2839
2859
|
const s = { ok: [], failed: [] };
|
|
2840
2860
|
let l = !1;
|
|
2841
2861
|
for (const d of t) {
|
|
2842
|
-
const
|
|
2843
|
-
if (!
|
|
2862
|
+
const m = o.get(d);
|
|
2863
|
+
if (!m)
|
|
2844
2864
|
continue;
|
|
2845
|
-
const
|
|
2846
|
-
if (!
|
|
2865
|
+
const u = c.get(d);
|
|
2866
|
+
if (!u) {
|
|
2847
2867
|
s.failed.push({
|
|
2848
2868
|
id: d,
|
|
2849
2869
|
input: String(d),
|
|
@@ -2852,9 +2872,9 @@ class Aa {
|
|
|
2852
2872
|
});
|
|
2853
2873
|
continue;
|
|
2854
2874
|
}
|
|
2855
|
-
const
|
|
2875
|
+
const _ = this.context.archivePath(i.id, m.id), k = m.vaultId;
|
|
2856
2876
|
try {
|
|
2857
|
-
await
|
|
2877
|
+
await p.rename(u.slotPath, _), m.vaultId = i.id, l = !0, await this.logger.log(
|
|
2858
2878
|
"INFO",
|
|
2859
2879
|
{
|
|
2860
2880
|
main: "move",
|
|
@@ -2864,7 +2884,7 @@ class Aa {
|
|
|
2864
2884
|
},
|
|
2865
2885
|
r("service.archive.log.moved", {
|
|
2866
2886
|
id: d,
|
|
2867
|
-
fromVaultId:
|
|
2887
|
+
fromVaultId: k,
|
|
2868
2888
|
toVaultId: i.id
|
|
2869
2889
|
}),
|
|
2870
2890
|
{ aid: d, vid: i.id }
|
|
@@ -2878,7 +2898,7 @@ class Aa {
|
|
|
2878
2898
|
})
|
|
2879
2899
|
});
|
|
2880
2900
|
} catch (x) {
|
|
2881
|
-
const
|
|
2901
|
+
const L = x.message;
|
|
2882
2902
|
await this.logger.log(
|
|
2883
2903
|
"ERROR",
|
|
2884
2904
|
{
|
|
@@ -2889,14 +2909,14 @@ class Aa {
|
|
|
2889
2909
|
},
|
|
2890
2910
|
r("service.archive.log.move_failed", {
|
|
2891
2911
|
id: d,
|
|
2892
|
-
message:
|
|
2912
|
+
message: L
|
|
2893
2913
|
}),
|
|
2894
|
-
{ aid: d, vid:
|
|
2914
|
+
{ aid: d, vid: k }
|
|
2895
2915
|
), s.failed.push({
|
|
2896
2916
|
id: d,
|
|
2897
2917
|
input: String(d),
|
|
2898
2918
|
success: !1,
|
|
2899
|
-
message:
|
|
2919
|
+
message: L
|
|
2900
2920
|
});
|
|
2901
2921
|
}
|
|
2902
2922
|
}
|
|
@@ -2913,7 +2933,7 @@ class Aa {
|
|
|
2913
2933
|
id: n
|
|
2914
2934
|
})
|
|
2915
2935
|
);
|
|
2916
|
-
if (c.status !==
|
|
2936
|
+
if (c.status !== y.Archived)
|
|
2917
2937
|
throw new Error(
|
|
2918
2938
|
r("service.archive.error.id_restored_no_slot", {
|
|
2919
2939
|
id: n
|
|
@@ -2965,7 +2985,7 @@ class Aa {
|
|
|
2965
2985
|
}
|
|
2966
2986
|
async listEntries(t) {
|
|
2967
2987
|
let i = await this.context.loadListEntries();
|
|
2968
|
-
if (t.all || (t.restored ? i = i.filter((n) => n.status ===
|
|
2988
|
+
if (t.all || (t.restored ? i = i.filter((n) => n.status === y.Restored) : i = i.filter((n) => n.status === y.Archived)), t.vault !== void 0) {
|
|
2969
2989
|
const n = await this.context.resolveVault(t.vault, {
|
|
2970
2990
|
includeRemoved: !0,
|
|
2971
2991
|
fallbackCurrent: !1
|
|
@@ -3042,17 +3062,17 @@ class Aa {
|
|
|
3042
3062
|
};
|
|
3043
3063
|
}
|
|
3044
3064
|
async preValidatePutItems(t) {
|
|
3045
|
-
const a = [], i = /* @__PURE__ */ new Set(), n = await
|
|
3065
|
+
const a = [], i = /* @__PURE__ */ new Set(), n = await Me(f.Dir.root);
|
|
3046
3066
|
for (const o of t) {
|
|
3047
|
-
const c = h.resolve(o), s = await
|
|
3067
|
+
const c = h.resolve(o), s = await ae(c);
|
|
3048
3068
|
if (!s)
|
|
3049
3069
|
throw new Error(
|
|
3050
3070
|
r("service.archive.error.path_not_exists", {
|
|
3051
3071
|
path: o
|
|
3052
3072
|
})
|
|
3053
3073
|
);
|
|
3054
|
-
const l = await
|
|
3055
|
-
if (
|
|
3074
|
+
const l = await Me(c);
|
|
3075
|
+
if (pa(l, n) || nt(n, l))
|
|
3056
3076
|
throw new Error(
|
|
3057
3077
|
r("service.archive.error.path_forbidden_archiver_scope", {
|
|
3058
3078
|
path: o
|
|
@@ -3086,24 +3106,24 @@ class Aa {
|
|
|
3086
3106
|
}
|
|
3087
3107
|
}
|
|
3088
3108
|
}
|
|
3089
|
-
class
|
|
3109
|
+
class Da {
|
|
3090
3110
|
constructor(t) {
|
|
3091
3111
|
this.context = t;
|
|
3092
3112
|
}
|
|
3093
3113
|
async log(t, a, i, n) {
|
|
3094
3114
|
const s = {
|
|
3095
3115
|
id: await this.context.nextAutoIncrement("logId"),
|
|
3096
|
-
operedAt:
|
|
3116
|
+
operedAt: _e(/* @__PURE__ */ new Date()),
|
|
3097
3117
|
level: t,
|
|
3098
3118
|
oper: a,
|
|
3099
3119
|
message: i,
|
|
3100
3120
|
...n?.aid !== void 0 ? { archiveIds: n.aid } : {},
|
|
3101
3121
|
...n?.vid !== void 0 ? { vaultIds: n.vid } : {}
|
|
3102
3122
|
};
|
|
3103
|
-
return await
|
|
3123
|
+
return await st(f.File.log, s), s;
|
|
3104
3124
|
}
|
|
3105
3125
|
}
|
|
3106
|
-
function
|
|
3126
|
+
function le(e) {
|
|
3107
3127
|
const t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
3108
3128
|
for (const i of e)
|
|
3109
3129
|
t.has(i) ? a.add(i) : t.add(i);
|
|
@@ -3112,7 +3132,7 @@ function ne(e) {
|
|
|
3112
3132
|
function I(e, t, a, i) {
|
|
3113
3133
|
e.push({ level: t, code: a, message: i });
|
|
3114
3134
|
}
|
|
3115
|
-
class
|
|
3135
|
+
class Pa {
|
|
3116
3136
|
constructor(t) {
|
|
3117
3137
|
this.context = t;
|
|
3118
3138
|
}
|
|
@@ -3135,9 +3155,9 @@ class Va {
|
|
|
3135
3155
|
}
|
|
3136
3156
|
async checkRequiredPaths(t) {
|
|
3137
3157
|
const a = [
|
|
3138
|
-
...Object.values(
|
|
3139
|
-
...Object.values(
|
|
3140
|
-
this.context.vaultDir(
|
|
3158
|
+
...Object.values(f.Dir),
|
|
3159
|
+
...Object.values(f.File),
|
|
3160
|
+
this.context.vaultDir(g.Vault.id)
|
|
3141
3161
|
];
|
|
3142
3162
|
for (const i of a)
|
|
3143
3163
|
await E(i) || I(
|
|
@@ -3160,7 +3180,7 @@ class Va {
|
|
|
3160
3180
|
);
|
|
3161
3181
|
}
|
|
3162
3182
|
checkListIds(t, a, i) {
|
|
3163
|
-
const n = a.map((s) => s.id), o =
|
|
3183
|
+
const n = a.map((s) => s.id), o = le(n);
|
|
3164
3184
|
o.length > 0 && I(
|
|
3165
3185
|
t.issues,
|
|
3166
3186
|
w.Error,
|
|
@@ -3181,7 +3201,7 @@ class Va {
|
|
|
3181
3201
|
);
|
|
3182
3202
|
}
|
|
3183
3203
|
checkVaultIds(t, a, i) {
|
|
3184
|
-
const n = a.filter((
|
|
3204
|
+
const n = a.filter((m) => m.id !== g.Vault.id), o = n.map((m) => m.id), c = le(o);
|
|
3185
3205
|
c.length > 0 && I(
|
|
3186
3206
|
t.issues,
|
|
3187
3207
|
w.Error,
|
|
@@ -3190,7 +3210,7 @@ class Va {
|
|
|
3190
3210
|
ids: c.join(", ")
|
|
3191
3211
|
})
|
|
3192
3212
|
);
|
|
3193
|
-
const s = n.map((
|
|
3213
|
+
const s = n.map((m) => m.name), l = s.filter((m, u) => s.indexOf(m) !== u);
|
|
3194
3214
|
l.length > 0 && I(
|
|
3195
3215
|
t.issues,
|
|
3196
3216
|
w.Error,
|
|
@@ -3226,7 +3246,7 @@ class Va {
|
|
|
3226
3246
|
continue;
|
|
3227
3247
|
}
|
|
3228
3248
|
const s = this.context.archivePath(o.vaultId, o.id), l = h.join(o.directory, o.item);
|
|
3229
|
-
if (o.status ===
|
|
3249
|
+
if (o.status === y.Archived) {
|
|
3230
3250
|
const d = await this.context.resolveArchiveStorageLocation(o);
|
|
3231
3251
|
if (!d)
|
|
3232
3252
|
I(
|
|
@@ -3239,17 +3259,17 @@ class Va {
|
|
|
3239
3259
|
})
|
|
3240
3260
|
);
|
|
3241
3261
|
else {
|
|
3242
|
-
const
|
|
3243
|
-
if (
|
|
3244
|
-
const
|
|
3245
|
-
|
|
3262
|
+
const m = await ae(d.objectPath);
|
|
3263
|
+
if (m) {
|
|
3264
|
+
const u = m.isDirectory(), _ = o.isDirectory === 1;
|
|
3265
|
+
u !== _ && I(
|
|
3246
3266
|
t.issues,
|
|
3247
3267
|
w.Error,
|
|
3248
3268
|
"TYPE_MISMATCH_ARCHIVED",
|
|
3249
3269
|
r("service.check.issue.type_mismatch_archived", {
|
|
3250
3270
|
archiveId: o.id,
|
|
3251
|
-
expectedIsDir:
|
|
3252
|
-
actualIsDir:
|
|
3271
|
+
expectedIsDir: _,
|
|
3272
|
+
actualIsDir: u
|
|
3253
3273
|
})
|
|
3254
3274
|
);
|
|
3255
3275
|
}
|
|
@@ -3263,7 +3283,7 @@ class Va {
|
|
|
3263
3283
|
restorePath: l
|
|
3264
3284
|
})
|
|
3265
3285
|
);
|
|
3266
|
-
} else if (o.status ===
|
|
3286
|
+
} else if (o.status === y.Restored)
|
|
3267
3287
|
if (await E(s) && I(
|
|
3268
3288
|
t.issues,
|
|
3269
3289
|
w.Warn,
|
|
@@ -3273,17 +3293,17 @@ class Va {
|
|
|
3273
3293
|
archivePath: s
|
|
3274
3294
|
})
|
|
3275
3295
|
), await E(l)) {
|
|
3276
|
-
const d = await
|
|
3296
|
+
const d = await ae(l);
|
|
3277
3297
|
if (d) {
|
|
3278
|
-
const
|
|
3279
|
-
|
|
3298
|
+
const m = d.isDirectory(), u = o.isDirectory === 1;
|
|
3299
|
+
m !== u && I(
|
|
3280
3300
|
t.issues,
|
|
3281
3301
|
w.Warn,
|
|
3282
3302
|
"TYPE_MISMATCH_RESTORED",
|
|
3283
3303
|
r("service.check.issue.type_mismatch_restored", {
|
|
3284
3304
|
archiveId: o.id,
|
|
3285
|
-
expectedIsDir:
|
|
3286
|
-
actualIsDir:
|
|
3305
|
+
expectedIsDir: u,
|
|
3306
|
+
actualIsDir: m
|
|
3287
3307
|
})
|
|
3288
3308
|
);
|
|
3289
3309
|
}
|
|
@@ -3311,8 +3331,8 @@ class Va {
|
|
|
3311
3331
|
}
|
|
3312
3332
|
async checkVaultDirectoryConsistency(t, a, i) {
|
|
3313
3333
|
const n = new Set(i.map((s) => s.id)), o = new Set(
|
|
3314
|
-
a.filter((s) => s.status ===
|
|
3315
|
-
), c = await
|
|
3334
|
+
a.filter((s) => s.status === y.Archived).map((s) => `${s.vaultId}/${s.id}`)
|
|
3335
|
+
), c = await _a(f.Dir.vaults);
|
|
3316
3336
|
for (const s of c) {
|
|
3317
3337
|
if (!/^\d+$/.test(s)) {
|
|
3318
3338
|
I(
|
|
@@ -3320,7 +3340,7 @@ class Va {
|
|
|
3320
3340
|
w.Warn,
|
|
3321
3341
|
"NON_NUMERIC_VAULT_DIR",
|
|
3322
3342
|
r("service.check.issue.non_numeric_vault_dir", {
|
|
3323
|
-
path: h.join(
|
|
3343
|
+
path: h.join(f.Dir.vaults, s)
|
|
3324
3344
|
})
|
|
3325
3345
|
);
|
|
3326
3346
|
continue;
|
|
@@ -3331,42 +3351,42 @@ class Va {
|
|
|
3331
3351
|
w.Warn,
|
|
3332
3352
|
"ORPHAN_VAULT_DIR",
|
|
3333
3353
|
r("service.check.issue.orphan_vault_dir", {
|
|
3334
|
-
path: h.join(
|
|
3354
|
+
path: h.join(f.Dir.vaults, s)
|
|
3335
3355
|
})
|
|
3336
3356
|
);
|
|
3337
|
-
const d = this.context.vaultDir(l),
|
|
3338
|
-
for (const
|
|
3339
|
-
if (!/^[0-9]+$/.test(
|
|
3357
|
+
const d = this.context.vaultDir(l), m = await p.readdir(d, { withFileTypes: !0 });
|
|
3358
|
+
for (const u of m) {
|
|
3359
|
+
if (!/^[0-9]+$/.test(u.name)) {
|
|
3340
3360
|
I(
|
|
3341
3361
|
t.issues,
|
|
3342
3362
|
w.Warn,
|
|
3343
3363
|
"NON_NUMERIC_ARCHIVE_OBJECT",
|
|
3344
3364
|
r("service.check.issue.non_numeric_archive_object", {
|
|
3345
3365
|
vaultId: l,
|
|
3346
|
-
name:
|
|
3366
|
+
name: u.name
|
|
3347
3367
|
})
|
|
3348
3368
|
);
|
|
3349
3369
|
continue;
|
|
3350
3370
|
}
|
|
3351
|
-
if (!
|
|
3371
|
+
if (!u.isDirectory()) {
|
|
3352
3372
|
I(
|
|
3353
3373
|
t.issues,
|
|
3354
3374
|
w.Error,
|
|
3355
3375
|
"INVALID_ARCHIVE_SLOT",
|
|
3356
3376
|
r("service.check.issue.invalid_archive_slot", {
|
|
3357
3377
|
vaultId: l,
|
|
3358
|
-
slotName:
|
|
3378
|
+
slotName: u.name
|
|
3359
3379
|
})
|
|
3360
3380
|
);
|
|
3361
3381
|
continue;
|
|
3362
3382
|
}
|
|
3363
|
-
const
|
|
3364
|
-
o.has(
|
|
3383
|
+
const _ = `${l}/${Number(u.name)}`;
|
|
3384
|
+
o.has(_) || I(
|
|
3365
3385
|
t.issues,
|
|
3366
3386
|
w.Warn,
|
|
3367
3387
|
"ORPHAN_ARCHIVE_OBJECT",
|
|
3368
3388
|
r("service.check.issue.orphan_archive_object", {
|
|
3369
|
-
pairKey:
|
|
3389
|
+
pairKey: _
|
|
3370
3390
|
})
|
|
3371
3391
|
);
|
|
3372
3392
|
}
|
|
@@ -3388,7 +3408,7 @@ class Va {
|
|
|
3388
3408
|
}
|
|
3389
3409
|
}
|
|
3390
3410
|
async checkLogConsistency(t, a) {
|
|
3391
|
-
const n = (await
|
|
3411
|
+
const n = (await ie(f.File.log)).map((s) => Number(s.id)).filter((s) => Number.isInteger(s)), o = le(n);
|
|
3392
3412
|
o.length > 0 && I(
|
|
3393
3413
|
t.issues,
|
|
3394
3414
|
w.Error,
|
|
@@ -3409,7 +3429,7 @@ class Va {
|
|
|
3409
3429
|
);
|
|
3410
3430
|
}
|
|
3411
3431
|
}
|
|
3412
|
-
class
|
|
3432
|
+
class Ma {
|
|
3413
3433
|
constructor(t) {
|
|
3414
3434
|
this.context = t;
|
|
3415
3435
|
}
|
|
@@ -3445,7 +3465,7 @@ class Ra {
|
|
|
3445
3465
|
a.lastUpdateCheck = t, await this.context.saveConfig(a);
|
|
3446
3466
|
}
|
|
3447
3467
|
}
|
|
3448
|
-
function
|
|
3468
|
+
function Oa(e) {
|
|
3449
3469
|
return {
|
|
3450
3470
|
id: Number(e.id),
|
|
3451
3471
|
operedAt: String(e.operedAt ?? ""),
|
|
@@ -3456,17 +3476,17 @@ function xa(e) {
|
|
|
3456
3476
|
...e.vaultIds !== void 0 ? { vaultIds: Number(e.vaultIds) } : {}
|
|
3457
3477
|
};
|
|
3458
3478
|
}
|
|
3459
|
-
function
|
|
3479
|
+
function Fa(e) {
|
|
3460
3480
|
return e.operedAt.replace(/[-:\sT]/g, "").slice(0, 6);
|
|
3461
3481
|
}
|
|
3462
|
-
class
|
|
3482
|
+
class ja {
|
|
3463
3483
|
constructor(t) {
|
|
3464
3484
|
this.context = t;
|
|
3465
3485
|
}
|
|
3466
3486
|
async getLogs(t) {
|
|
3467
3487
|
const a = await this.loadAllLogs();
|
|
3468
3488
|
return t.mode === "all" ? a : a.filter((i) => {
|
|
3469
|
-
const n =
|
|
3489
|
+
const n = Fa(i);
|
|
3470
3490
|
return !n || n.length !== 6 ? !1 : n >= t.from && n <= t.to;
|
|
3471
3491
|
});
|
|
3472
3492
|
}
|
|
@@ -3486,19 +3506,19 @@ class $a {
|
|
|
3486
3506
|
return n;
|
|
3487
3507
|
}
|
|
3488
3508
|
async loadAllLogs() {
|
|
3489
|
-
const a = (await
|
|
3509
|
+
const a = (await ie(f.File.log)).map((i) => Oa(i));
|
|
3490
3510
|
return a.sort((i, n) => i.id - n.id), a;
|
|
3491
3511
|
}
|
|
3492
3512
|
}
|
|
3493
|
-
const
|
|
3494
|
-
function
|
|
3513
|
+
const Ya = yt(It);
|
|
3514
|
+
function fe(e) {
|
|
3495
3515
|
return e.trim().replace(/^v/i, "");
|
|
3496
3516
|
}
|
|
3497
|
-
function
|
|
3498
|
-
return
|
|
3517
|
+
function qe(e) {
|
|
3518
|
+
return fe(e).split(".").map((t) => Number(t.replace(/[^0-9].*$/, ""))).map((t) => Number.isFinite(t) ? t : 0);
|
|
3499
3519
|
}
|
|
3500
|
-
function
|
|
3501
|
-
const a =
|
|
3520
|
+
function Ha(e, t) {
|
|
3521
|
+
const a = qe(e), i = qe(t), n = Math.max(a.length, i.length);
|
|
3502
3522
|
for (let o = 0; o < n; o += 1) {
|
|
3503
3523
|
const c = a[o] ?? 0, s = i[o] ?? 0;
|
|
3504
3524
|
if (s > c)
|
|
@@ -3508,22 +3528,22 @@ function Na(e, t) {
|
|
|
3508
3528
|
}
|
|
3509
3529
|
return !1;
|
|
3510
3530
|
}
|
|
3511
|
-
class
|
|
3531
|
+
class Ua {
|
|
3512
3532
|
currentVersion;
|
|
3513
3533
|
constructor(t) {
|
|
3514
|
-
this.currentVersion =
|
|
3534
|
+
this.currentVersion = fe(t);
|
|
3515
3535
|
}
|
|
3516
|
-
async checkLatest(t =
|
|
3517
|
-
const a = await this.fetchLatestRelease(t), i =
|
|
3536
|
+
async checkLatest(t = M.Repo) {
|
|
3537
|
+
const a = await this.fetchLatestRelease(t), i = fe(a.tag_name);
|
|
3518
3538
|
return {
|
|
3519
3539
|
currentVersion: this.currentVersion,
|
|
3520
3540
|
latestVersion: i,
|
|
3521
|
-
hasUpdate:
|
|
3541
|
+
hasUpdate: Ha(this.currentVersion, i),
|
|
3522
3542
|
htmlUrl: a.html_url,
|
|
3523
3543
|
publishedAt: a.published_at
|
|
3524
3544
|
};
|
|
3525
3545
|
}
|
|
3526
|
-
async installLatest(t =
|
|
3546
|
+
async installLatest(t = M.Repo) {
|
|
3527
3547
|
const i = (await this.fetchLatestRelease(t)).assets?.find((s) => /install.*\.sh$/i.test(s.name));
|
|
3528
3548
|
if (!i)
|
|
3529
3549
|
throw new Error(r("service.update.error.no_install_asset"));
|
|
@@ -3531,7 +3551,7 @@ class Da {
|
|
|
3531
3551
|
headers: {
|
|
3532
3552
|
"user-agent": "archiver-ts"
|
|
3533
3553
|
},
|
|
3534
|
-
signal: AbortSignal.timeout(
|
|
3554
|
+
signal: AbortSignal.timeout(M.Timeout)
|
|
3535
3555
|
});
|
|
3536
3556
|
if (!n.ok)
|
|
3537
3557
|
throw new Error(
|
|
@@ -3539,14 +3559,14 @@ class Da {
|
|
|
3539
3559
|
status: n.status
|
|
3540
3560
|
})
|
|
3541
3561
|
);
|
|
3542
|
-
const o = await n.text(), c = h.join(
|
|
3543
|
-
await
|
|
3562
|
+
const o = await n.text(), c = h.join(Je.tmpdir(), `archiver-update-${Date.now()}.sh`);
|
|
3563
|
+
await p.writeFile(c, o, { encoding: "utf8", mode: 493 });
|
|
3544
3564
|
try {
|
|
3545
|
-
const s = await
|
|
3565
|
+
const s = await Ya("bash", [c], { maxBuffer: 4194304 });
|
|
3546
3566
|
return [s.stdout, s.stderr].filter(Boolean).join(`
|
|
3547
3567
|
`).trim();
|
|
3548
3568
|
} finally {
|
|
3549
|
-
await
|
|
3569
|
+
await p.rm(c, { force: !0 });
|
|
3550
3570
|
}
|
|
3551
3571
|
}
|
|
3552
3572
|
async fetchLatestRelease(t) {
|
|
@@ -3555,7 +3575,7 @@ class Da {
|
|
|
3555
3575
|
accept: "application/vnd.github+json",
|
|
3556
3576
|
"user-agent": "archiver-ts"
|
|
3557
3577
|
},
|
|
3558
|
-
signal: AbortSignal.timeout(
|
|
3578
|
+
signal: AbortSignal.timeout(M.Timeout)
|
|
3559
3579
|
});
|
|
3560
3580
|
if (!i.ok)
|
|
3561
3581
|
throw new Error(
|
|
@@ -3574,10 +3594,10 @@ class Da {
|
|
|
3574
3594
|
return n;
|
|
3575
3595
|
}
|
|
3576
3596
|
}
|
|
3577
|
-
async function
|
|
3578
|
-
const e = new
|
|
3597
|
+
async function za() {
|
|
3598
|
+
const e = new $a();
|
|
3579
3599
|
await e.init();
|
|
3580
|
-
const t = new
|
|
3600
|
+
const t = new Ma(e), a = new Da(e), i = new Na(e, a), n = new wa(e, t), o = new ja(e), c = new Pa(e), s = "0.3.1", l = new Ua(s);
|
|
3581
3601
|
return {
|
|
3582
3602
|
context: e,
|
|
3583
3603
|
archiveService: i,
|
|
@@ -3590,15 +3610,16 @@ async function Pa() {
|
|
|
3590
3610
|
version: s
|
|
3591
3611
|
};
|
|
3592
3612
|
}
|
|
3593
|
-
async function
|
|
3594
|
-
if (!
|
|
3613
|
+
async function Ba(e) {
|
|
3614
|
+
if (!Ie())
|
|
3595
3615
|
return "help";
|
|
3596
3616
|
A(r("index.no_command_action.unknown"));
|
|
3597
|
-
const t = await
|
|
3617
|
+
const t = await qt({
|
|
3598
3618
|
title: r("index.no_command_action.question"),
|
|
3619
|
+
description: r("index.no_command_action.note"),
|
|
3599
3620
|
options: [
|
|
3600
|
-
{ value: "list", label: r("
|
|
3601
|
-
{ value: "help", label: r("
|
|
3621
|
+
{ value: "list", label: r("index.no_command_action.option.list") },
|
|
3622
|
+
{ value: "help", label: r("index.no_command_action.option.help") }
|
|
3602
3623
|
],
|
|
3603
3624
|
initialValue: "list",
|
|
3604
3625
|
hint: r("index.no_command_action.hint", {
|
|
@@ -3608,12 +3629,12 @@ async function Oa(e) {
|
|
|
3608
3629
|
});
|
|
3609
3630
|
return t || process.exit(130), await e.configService.setNoCommandAction(t), C(r("index.no_command_action.updated", { action: t })), t;
|
|
3610
3631
|
}
|
|
3611
|
-
async function
|
|
3612
|
-
const e = await
|
|
3613
|
-
|
|
3632
|
+
async function qa() {
|
|
3633
|
+
const e = await ve(f.File.config, g.Config);
|
|
3634
|
+
Z(e.language), ee({
|
|
3614
3635
|
style: e.style === "off" ? "off" : "on"
|
|
3615
3636
|
});
|
|
3616
|
-
const t = await
|
|
3637
|
+
const t = await Ta();
|
|
3617
3638
|
if (t.installed) {
|
|
3618
3639
|
const o = t.profilePath ? ` ${t.profilePath}` : "";
|
|
3619
3640
|
A(r("index.shell_wrapper.installed", { where: o })), t.reloadCommand && A(
|
|
@@ -3623,11 +3644,11 @@ async function Ma() {
|
|
|
3623
3644
|
);
|
|
3624
3645
|
return;
|
|
3625
3646
|
}
|
|
3626
|
-
const a = await
|
|
3627
|
-
|
|
3628
|
-
const n =
|
|
3647
|
+
const a = await za(), i = await a.configService.getConfig();
|
|
3648
|
+
Z(i.language), ee(i);
|
|
3649
|
+
const n = ya(a);
|
|
3629
3650
|
if (process.argv.length <= 2) {
|
|
3630
|
-
if ((i.noCommandAction === "unknown" ? await
|
|
3651
|
+
if ((i.noCommandAction === "unknown" ? await Ba(a) : i.noCommandAction) === "list") {
|
|
3631
3652
|
await n.parseAsync([...process.argv, "list"]);
|
|
3632
3653
|
return;
|
|
3633
3654
|
}
|
|
@@ -3636,6 +3657,6 @@ async function Ma() {
|
|
|
3636
3657
|
}
|
|
3637
3658
|
await n.parseAsync(process.argv);
|
|
3638
3659
|
}
|
|
3639
|
-
|
|
3640
|
-
|
|
3660
|
+
qa().catch((e) => {
|
|
3661
|
+
j(e.message), process.exit(1);
|
|
3641
3662
|
});
|