archiver-ts 0.3.0 → 0.3.2
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 +604 -586
- 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,46 +1059,47 @@ 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.
|
|
1087
|
-
|
|
1088
|
-
`
|
|
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(`
|
|
1102
|
+
`));
|
|
1089
1103
|
}, c = (l) => {
|
|
1090
1104
|
a.off("keypress", s), a.setRawMode(!1), a.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1091
1105
|
`), n(l);
|
|
@@ -1095,25 +1109,25 @@ async function Mt(e) {
|
|
|
1095
1109
|
return;
|
|
1096
1110
|
}
|
|
1097
1111
|
if (d.name === "left") {
|
|
1098
|
-
i =
|
|
1112
|
+
i = q(i, "left"), o();
|
|
1099
1113
|
return;
|
|
1100
1114
|
}
|
|
1101
1115
|
if (d.name === "right") {
|
|
1102
|
-
i =
|
|
1116
|
+
i = q(i, "right"), o();
|
|
1103
1117
|
return;
|
|
1104
1118
|
}
|
|
1105
1119
|
if (d.name === "return" || d.name === "enter") {
|
|
1106
|
-
const
|
|
1107
|
-
if (!
|
|
1120
|
+
const m = H(i);
|
|
1121
|
+
if (!m || m.disabled)
|
|
1108
1122
|
return;
|
|
1109
|
-
c(
|
|
1123
|
+
c(m.value);
|
|
1110
1124
|
}
|
|
1111
1125
|
};
|
|
1112
1126
|
a.on("keypress", s), o();
|
|
1113
1127
|
});
|
|
1114
1128
|
}
|
|
1115
|
-
const
|
|
1116
|
-
function
|
|
1129
|
+
const Wt = ["updateCheck", "vaultItemSeparator", "style", "language", "noCommandAction"];
|
|
1130
|
+
function Jt(e) {
|
|
1117
1131
|
return {
|
|
1118
1132
|
updateCheck: e.updateCheck,
|
|
1119
1133
|
vaultItemSeparator: e.vaultItemSeparator,
|
|
@@ -1122,7 +1136,7 @@ function jt(e) {
|
|
|
1122
1136
|
noCommandAction: e.noCommandAction
|
|
1123
1137
|
};
|
|
1124
1138
|
}
|
|
1125
|
-
function
|
|
1139
|
+
function Gt(e, t) {
|
|
1126
1140
|
return {
|
|
1127
1141
|
...e,
|
|
1128
1142
|
updateCheck: t.updateCheck,
|
|
@@ -1132,17 +1146,17 @@ function Yt(e, t) {
|
|
|
1132
1146
|
noCommandAction: t.noCommandAction
|
|
1133
1147
|
};
|
|
1134
1148
|
}
|
|
1135
|
-
function
|
|
1136
|
-
return
|
|
1149
|
+
function et(e, t) {
|
|
1150
|
+
return Wt.every((a) => e[a] === t[a]);
|
|
1137
1151
|
}
|
|
1138
|
-
function
|
|
1152
|
+
function Kt(e) {
|
|
1139
1153
|
if (!e.vaultItemSeparator.trim())
|
|
1140
1154
|
return "command.config.vault_item_sep.error.empty";
|
|
1141
1155
|
}
|
|
1142
|
-
function
|
|
1156
|
+
function Xt() {
|
|
1143
1157
|
return !!(process.stdin.isTTY && process.stdout.isTTY && typeof process.stdin.setRawMode == "function");
|
|
1144
1158
|
}
|
|
1145
|
-
function
|
|
1159
|
+
function Zt(e) {
|
|
1146
1160
|
return [
|
|
1147
1161
|
{
|
|
1148
1162
|
kind: "select",
|
|
@@ -1160,7 +1174,7 @@ function zt(e) {
|
|
|
1160
1174
|
kind: "input",
|
|
1161
1175
|
key: "vaultItemSeparator",
|
|
1162
1176
|
label: r("command.config.edit.field.vault_item_sep"),
|
|
1163
|
-
state:
|
|
1177
|
+
state: Yt(e.vaultItemSeparator)
|
|
1164
1178
|
},
|
|
1165
1179
|
{
|
|
1166
1180
|
kind: "select",
|
|
@@ -1201,17 +1215,17 @@ function zt(e) {
|
|
|
1201
1215
|
}
|
|
1202
1216
|
];
|
|
1203
1217
|
}
|
|
1204
|
-
function
|
|
1218
|
+
function $e(e, t, a) {
|
|
1205
1219
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1206
1220
|
}
|
|
1207
|
-
function
|
|
1221
|
+
function tt(e, t) {
|
|
1208
1222
|
const a = { ...t };
|
|
1209
1223
|
for (const i of e) {
|
|
1210
1224
|
if (i.kind === "input") {
|
|
1211
1225
|
a.vaultItemSeparator = i.state.value;
|
|
1212
1226
|
continue;
|
|
1213
1227
|
}
|
|
1214
|
-
const n =
|
|
1228
|
+
const n = H(i.state)?.value;
|
|
1215
1229
|
if (n) {
|
|
1216
1230
|
if (i.key === "updateCheck") {
|
|
1217
1231
|
a.updateCheck = n;
|
|
@@ -1230,78 +1244,81 @@ function Ge(e, t) {
|
|
|
1230
1244
|
}
|
|
1231
1245
|
return a;
|
|
1232
1246
|
}
|
|
1233
|
-
function
|
|
1247
|
+
function Qt(e) {
|
|
1234
1248
|
return Math.max(...e.map((t) => t.label.length), 1);
|
|
1235
1249
|
}
|
|
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)
|
|
1250
|
+
function N(e, t, a, i, n) {
|
|
1251
|
+
const o = tt(e, a), c = !et(o, a), s = Qt(e), l = e.length, d = t === l, m = r("command.config.edit.hint", {
|
|
1252
|
+
upDown: R(r("command.config.edit.key.up_down")),
|
|
1253
|
+
leftRight: R(r("command.config.edit.key.left_right")),
|
|
1254
|
+
type: R(r("command.config.edit.key.type")),
|
|
1255
|
+
enter: R(r("command.config.edit.key.enter")),
|
|
1256
|
+
cancel: R(r("command.config.edit.key.cancel"))
|
|
1257
|
+
}), u = [];
|
|
1258
|
+
u.push(v.bold(r("command.config.edit.title"))), u.push("");
|
|
1259
|
+
for (let k = 0; k < e.length; k += 1) {
|
|
1260
|
+
const x = e[k];
|
|
1261
|
+
if (!x)
|
|
1250
1262
|
continue;
|
|
1251
|
-
const
|
|
1252
|
-
u.push(`${
|
|
1253
|
-
}
|
|
1254
|
-
u.push(""), u.push(`${r("command.config.edit.action_prefix")} ${
|
|
1255
|
-
|
|
1256
|
-
|
|
1263
|
+
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"));
|
|
1264
|
+
u.push(`${T} ${re} ${oe}`);
|
|
1265
|
+
}
|
|
1266
|
+
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));
|
|
1267
|
+
const _ = we({
|
|
1268
|
+
contentLines: u,
|
|
1269
|
+
footerLines: [m],
|
|
1270
|
+
rows: process.stdout.rows
|
|
1271
|
+
});
|
|
1272
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(_.join(`
|
|
1273
|
+
`));
|
|
1257
1274
|
}
|
|
1258
|
-
async function
|
|
1259
|
-
if (!
|
|
1275
|
+
async function ea(e) {
|
|
1276
|
+
if (!Xt())
|
|
1260
1277
|
throw new Error(r("command.config.edit.error.no_tty"));
|
|
1261
|
-
const t = process.stdin, a =
|
|
1278
|
+
const t = process.stdin, a = Zt(e);
|
|
1262
1279
|
let i = O([
|
|
1263
1280
|
{ value: "save", label: r("command.config.edit.action.save") },
|
|
1264
1281
|
{ value: "cancel", label: r("command.config.edit.action.cancel") }
|
|
1265
1282
|
]), n = 0, o = "";
|
|
1266
|
-
return
|
|
1267
|
-
const s = (
|
|
1283
|
+
return ge.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((c) => {
|
|
1284
|
+
const s = (m) => {
|
|
1268
1285
|
t.off("keypress", d), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1269
|
-
`), c(
|
|
1286
|
+
`), c(m);
|
|
1270
1287
|
}, l = () => {
|
|
1271
|
-
const
|
|
1272
|
-
if (
|
|
1273
|
-
o = r(
|
|
1288
|
+
const m = tt(a, e), u = Kt(m);
|
|
1289
|
+
if (u) {
|
|
1290
|
+
o = r(u), N(a, n, e, i, o);
|
|
1274
1291
|
return;
|
|
1275
1292
|
}
|
|
1276
|
-
s(
|
|
1277
|
-
}, d = (
|
|
1278
|
-
if (
|
|
1293
|
+
s(m);
|
|
1294
|
+
}, d = (m, u) => {
|
|
1295
|
+
if (u.ctrl && u.name === "c") {
|
|
1279
1296
|
s(null);
|
|
1280
1297
|
return;
|
|
1281
1298
|
}
|
|
1282
|
-
if (
|
|
1299
|
+
if (u.name === "escape") {
|
|
1283
1300
|
s(null);
|
|
1284
1301
|
return;
|
|
1285
1302
|
}
|
|
1286
|
-
if (
|
|
1287
|
-
n =
|
|
1303
|
+
if (u.name === "up") {
|
|
1304
|
+
n = $e(n, "up", a.length + 1), o = "", N(a, n, e, i, o);
|
|
1288
1305
|
return;
|
|
1289
1306
|
}
|
|
1290
|
-
if (
|
|
1291
|
-
n =
|
|
1307
|
+
if (u.name === "down") {
|
|
1308
|
+
n = $e(n, "down", a.length + 1), o = "", N(a, n, e, i, o);
|
|
1292
1309
|
return;
|
|
1293
1310
|
}
|
|
1294
1311
|
if (n === a.length) {
|
|
1295
|
-
if (
|
|
1312
|
+
if (u.name === "q") {
|
|
1296
1313
|
s(null);
|
|
1297
1314
|
return;
|
|
1298
1315
|
}
|
|
1299
|
-
if (
|
|
1300
|
-
i =
|
|
1316
|
+
if (u.name === "left" || u.name === "right") {
|
|
1317
|
+
i = q(i, u.name), o = "", N(a, n, e, i, o);
|
|
1301
1318
|
return;
|
|
1302
1319
|
}
|
|
1303
|
-
if (
|
|
1304
|
-
if ((
|
|
1320
|
+
if (u.name === "return" || u.name === "enter") {
|
|
1321
|
+
if ((H(i)?.value ?? "save") === "cancel") {
|
|
1305
1322
|
s(null);
|
|
1306
1323
|
return;
|
|
1307
1324
|
}
|
|
@@ -1309,41 +1326,41 @@ async function qt(e) {
|
|
|
1309
1326
|
}
|
|
1310
1327
|
return;
|
|
1311
1328
|
}
|
|
1312
|
-
const
|
|
1313
|
-
if (!
|
|
1329
|
+
const _ = a[n];
|
|
1330
|
+
if (!_) {
|
|
1314
1331
|
s(null);
|
|
1315
1332
|
return;
|
|
1316
1333
|
}
|
|
1317
|
-
if (
|
|
1334
|
+
if (u.name === "q" && _.kind !== "input") {
|
|
1318
1335
|
s(null);
|
|
1319
1336
|
return;
|
|
1320
1337
|
}
|
|
1321
|
-
if (
|
|
1322
|
-
|
|
1338
|
+
if (u.name === "left" || u.name === "right") {
|
|
1339
|
+
_.kind === "select" ? _.state = q(_.state, u.name) : _.state = Te(_.state, m, u).state, o = "", N(a, n, e, i, o);
|
|
1323
1340
|
return;
|
|
1324
1341
|
}
|
|
1325
|
-
if (
|
|
1326
|
-
const
|
|
1327
|
-
if (
|
|
1342
|
+
if (_.kind === "input") {
|
|
1343
|
+
const k = Te(_.state, m, u);
|
|
1344
|
+
if (_.state = k.state, k.action === "cancel") {
|
|
1328
1345
|
s(null);
|
|
1329
1346
|
return;
|
|
1330
1347
|
}
|
|
1331
|
-
if (
|
|
1348
|
+
if (k.action === "submit") {
|
|
1332
1349
|
l();
|
|
1333
1350
|
return;
|
|
1334
1351
|
}
|
|
1335
|
-
o = "",
|
|
1352
|
+
o = "", N(a, n, e, i, o);
|
|
1336
1353
|
return;
|
|
1337
1354
|
}
|
|
1338
|
-
(
|
|
1355
|
+
(u.name === "return" || u.name === "enter") && l();
|
|
1339
1356
|
};
|
|
1340
|
-
t.on("keypress", d),
|
|
1357
|
+
t.on("keypress", d), N(a, n, e, i, o);
|
|
1341
1358
|
});
|
|
1342
1359
|
}
|
|
1343
|
-
function
|
|
1360
|
+
function ta(e, t) {
|
|
1344
1361
|
const a = e.command("config").description(r("command.config.description"));
|
|
1345
1362
|
a.command("list").description(r("command.config.list.description")).option("-c, --comment", r("command.config.list.option.comment")).action(
|
|
1346
|
-
(i) =>
|
|
1363
|
+
(i) => b(async () => {
|
|
1347
1364
|
const n = await t.configService.getConfig();
|
|
1348
1365
|
if (i.comment) {
|
|
1349
1366
|
const o = [
|
|
@@ -1356,7 +1373,7 @@ function Wt(e, t) {
|
|
|
1356
1373
|
["no_command_action", n.noCommandAction, r("command.config.list.comment.no_command_action")]
|
|
1357
1374
|
];
|
|
1358
1375
|
console.log(
|
|
1359
|
-
|
|
1376
|
+
B(
|
|
1360
1377
|
[
|
|
1361
1378
|
r("command.config.list.table.key"),
|
|
1362
1379
|
r("command.config.list.table.value"),
|
|
@@ -1369,25 +1386,25 @@ function Wt(e, t) {
|
|
|
1369
1386
|
console.log(JSON.stringify(n, null, 2));
|
|
1370
1387
|
})
|
|
1371
1388
|
), a.command("edit").alias("e").description(r("command.config.edit.description")).action(
|
|
1372
|
-
() =>
|
|
1373
|
-
const i = await t.configService.getConfig(), n =
|
|
1389
|
+
() => b(async () => {
|
|
1390
|
+
const i = await t.configService.getConfig(), n = Jt(i), o = await ea(n);
|
|
1374
1391
|
if (!o) {
|
|
1375
1392
|
A(r("command.config.edit.cancelled"));
|
|
1376
1393
|
return;
|
|
1377
1394
|
}
|
|
1378
|
-
if (
|
|
1395
|
+
if (et(n, o)) {
|
|
1379
1396
|
A(r("command.config.edit.no_changes"));
|
|
1380
1397
|
return;
|
|
1381
1398
|
}
|
|
1382
|
-
const c =
|
|
1383
|
-
await t.context.saveConfig(c),
|
|
1399
|
+
const c = Gt(i, o);
|
|
1400
|
+
await t.context.saveConfig(c), ee(c), C(r("command.config.edit.saved")), await t.auditLogger.log(
|
|
1384
1401
|
"INFO",
|
|
1385
1402
|
{ main: "config", sub: "edit", source: "u" },
|
|
1386
1403
|
r("command.config.edit.audit.saved")
|
|
1387
1404
|
), await V(t);
|
|
1388
1405
|
})
|
|
1389
1406
|
), a.command("update-check").description(r("command.config.update_check.description")).argument("<state>", r("command.config.update_check.argument")).action(
|
|
1390
|
-
(i) =>
|
|
1407
|
+
(i) => b(async () => {
|
|
1391
1408
|
const n = i.toLowerCase();
|
|
1392
1409
|
if (n !== "on" && n !== "off")
|
|
1393
1410
|
throw new Error(r("command.config.state.error"));
|
|
@@ -1398,19 +1415,19 @@ function Wt(e, t) {
|
|
|
1398
1415
|
), await V(t);
|
|
1399
1416
|
})
|
|
1400
1417
|
), a.command("style").description(r("command.config.style.description")).argument("<state>", r("command.config.style.argument")).action(
|
|
1401
|
-
(i) =>
|
|
1418
|
+
(i) => b(async () => {
|
|
1402
1419
|
const n = i.toLowerCase();
|
|
1403
1420
|
if (n !== "on" && n !== "off")
|
|
1404
1421
|
throw new Error(r("command.config.state.error"));
|
|
1405
1422
|
const o = await t.configService.setStyle(n);
|
|
1406
|
-
|
|
1423
|
+
ee(o), C(r("command.config.style.updated", { state: n })), await t.auditLogger.log(
|
|
1407
1424
|
"INFO",
|
|
1408
1425
|
{ main: "config", sub: "style", args: [n], source: "u" },
|
|
1409
1426
|
r("command.config.style.updated", { state: n })
|
|
1410
1427
|
);
|
|
1411
1428
|
})
|
|
1412
1429
|
), 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) =>
|
|
1430
|
+
(i) => b(async () => {
|
|
1414
1431
|
if (!i.trim())
|
|
1415
1432
|
throw new Error(r("command.config.vault_item_sep.error.empty"));
|
|
1416
1433
|
await t.configService.setVaultItemSeparator(i), C(
|
|
@@ -1426,7 +1443,7 @@ function Wt(e, t) {
|
|
|
1426
1443
|
), await V(t);
|
|
1427
1444
|
})
|
|
1428
1445
|
), 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) =>
|
|
1446
|
+
(i) => b(async () => {
|
|
1430
1447
|
const n = i.toLowerCase();
|
|
1431
1448
|
if (n !== "help" && n !== "list" && n !== "unknown")
|
|
1432
1449
|
throw new Error(r("command.config.no_command_action.error.invalid"));
|
|
@@ -1437,7 +1454,7 @@ function Wt(e, t) {
|
|
|
1437
1454
|
);
|
|
1438
1455
|
})
|
|
1439
1456
|
), a.command("language").description(r("command.config.language.description")).argument("<language>", r("command.config.language.argument")).action(
|
|
1440
|
-
(i) =>
|
|
1457
|
+
(i) => b(async () => {
|
|
1441
1458
|
const n = i.toLowerCase();
|
|
1442
1459
|
if (n !== "zh" && n !== "en")
|
|
1443
1460
|
throw new Error(r("command.config.language.error.invalid"));
|
|
@@ -1449,8 +1466,8 @@ function Wt(e, t) {
|
|
|
1449
1466
|
})
|
|
1450
1467
|
);
|
|
1451
1468
|
}
|
|
1452
|
-
const
|
|
1453
|
-
function
|
|
1469
|
+
const aa = "__ARCHIVER_CD__:";
|
|
1470
|
+
function ia(e, t) {
|
|
1454
1471
|
if (e.includes(`
|
|
1455
1472
|
`) || e.includes("\r"))
|
|
1456
1473
|
throw new Error(
|
|
@@ -1459,80 +1476,80 @@ function Gt(e, t) {
|
|
|
1459
1476
|
})
|
|
1460
1477
|
);
|
|
1461
1478
|
}
|
|
1462
|
-
function
|
|
1463
|
-
return
|
|
1479
|
+
function na(e) {
|
|
1480
|
+
return ia(e, r("util.cd.label.archive_slot_path")), `${aa}${e}`;
|
|
1464
1481
|
}
|
|
1465
|
-
async function
|
|
1466
|
-
console.log(
|
|
1482
|
+
async function ra(e) {
|
|
1483
|
+
console.log(na(e));
|
|
1467
1484
|
}
|
|
1468
|
-
function
|
|
1485
|
+
function Ne(e) {
|
|
1469
1486
|
return r(e === "enter" ? "command.list.interactive.action.enter" : "command.list.interactive.action.restore");
|
|
1470
1487
|
}
|
|
1471
|
-
function
|
|
1472
|
-
return
|
|
1488
|
+
function at() {
|
|
1489
|
+
return Ie();
|
|
1473
1490
|
}
|
|
1474
|
-
function
|
|
1475
|
-
return t === "enter" || t === "restore" ? e.status ===
|
|
1491
|
+
function he(e, t) {
|
|
1492
|
+
return t === "enter" || t === "restore" ? e.status === y.Archived : !1;
|
|
1476
1493
|
}
|
|
1477
|
-
function
|
|
1494
|
+
function ye(e, t) {
|
|
1478
1495
|
return O(
|
|
1479
1496
|
[
|
|
1480
|
-
{ value: "enter", label:
|
|
1481
|
-
{ value: "restore", label:
|
|
1497
|
+
{ value: "enter", label: Ne("enter"), disabled: !he(e, "enter") },
|
|
1498
|
+
{ value: "restore", label: Ne("restore"), disabled: !he(e, "restore") }
|
|
1482
1499
|
],
|
|
1483
1500
|
t
|
|
1484
1501
|
);
|
|
1485
1502
|
}
|
|
1486
|
-
function
|
|
1487
|
-
return
|
|
1503
|
+
function oa(e, t) {
|
|
1504
|
+
return H(ye(e, t))?.value ?? t;
|
|
1488
1505
|
}
|
|
1489
|
-
function
|
|
1490
|
-
const i =
|
|
1491
|
-
return
|
|
1506
|
+
function De(e, t, a) {
|
|
1507
|
+
const i = ye(e, t), n = q(i, a);
|
|
1508
|
+
return H(n)?.value ?? t;
|
|
1492
1509
|
}
|
|
1493
|
-
function
|
|
1510
|
+
function Pe(e, t, a) {
|
|
1494
1511
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1495
1512
|
}
|
|
1496
|
-
function
|
|
1513
|
+
function F(e, t, a, i) {
|
|
1497
1514
|
const n = e[t];
|
|
1498
1515
|
if (!n)
|
|
1499
1516
|
return;
|
|
1500
|
-
const o = process.stdout.rows ?? 24, c =
|
|
1501
|
-
m.push(r("command.list.interactive.hint", {
|
|
1517
|
+
const o = process.stdout.rows ?? 24, c = r("command.list.interactive.hint", {
|
|
1502
1518
|
upDown: R(r("command.list.interactive.key.up_down")),
|
|
1503
1519
|
leftRight: R(r("command.list.interactive.key.left_right")),
|
|
1504
1520
|
enter: R(r("command.list.interactive.key.enter")),
|
|
1505
1521
|
cancel: R(r("command.list.interactive.key.cancel"))
|
|
1506
|
-
}))
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
), m.
|
|
1511
|
-
for (let
|
|
1512
|
-
const
|
|
1513
|
-
if (!
|
|
1522
|
+
}), s = ye(n, a), l = [
|
|
1523
|
+
`${r("command.list.interactive.action_prefix")} ${te(s)}`,
|
|
1524
|
+
i ? v.yellow(i) : "",
|
|
1525
|
+
""
|
|
1526
|
+
], 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];
|
|
1527
|
+
for (let W = x; W < L; W += 1) {
|
|
1528
|
+
const U = e[W];
|
|
1529
|
+
if (!U)
|
|
1514
1530
|
continue;
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1531
|
+
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)}`;
|
|
1532
|
+
ke ? (T.push(v.bold(Ce)), T.push(v.cyan(Ee))) : (T.push(Ce), T.push(Ee));
|
|
1517
1533
|
}
|
|
1518
|
-
|
|
1534
|
+
const re = [
|
|
1519
1535
|
v.dim(
|
|
1520
1536
|
r("command.list.interactive.showing", {
|
|
1521
|
-
start:
|
|
1522
|
-
end:
|
|
1537
|
+
start: x + 1,
|
|
1538
|
+
end: L,
|
|
1523
1539
|
total: e.length
|
|
1524
1540
|
})
|
|
1525
|
-
)
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
`
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1541
|
+
),
|
|
1542
|
+
c
|
|
1543
|
+
], oe = we({ contentLines: T, footerLines: re, rows: o });
|
|
1544
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(oe.join(`
|
|
1545
|
+
`));
|
|
1546
|
+
}
|
|
1547
|
+
async function ca(e) {
|
|
1548
|
+
if (e.length === 0 || !at())
|
|
1532
1549
|
return null;
|
|
1533
1550
|
const t = process.stdin;
|
|
1534
1551
|
let a = 0, i = "enter", n = "";
|
|
1535
|
-
return
|
|
1552
|
+
return ge.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((o) => {
|
|
1536
1553
|
const c = (l) => {
|
|
1537
1554
|
t.off("keypress", s), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1538
1555
|
`), o(l);
|
|
@@ -1542,80 +1559,80 @@ async function Qt(e) {
|
|
|
1542
1559
|
return;
|
|
1543
1560
|
}
|
|
1544
1561
|
if (d.name === "up") {
|
|
1545
|
-
a =
|
|
1562
|
+
a = Pe(a, "up", e.length), n = "", F(e, a, i, n);
|
|
1546
1563
|
return;
|
|
1547
1564
|
}
|
|
1548
1565
|
if (d.name === "down") {
|
|
1549
|
-
a =
|
|
1566
|
+
a = Pe(a, "down", e.length), n = "", F(e, a, i, n);
|
|
1550
1567
|
return;
|
|
1551
1568
|
}
|
|
1552
1569
|
if (d.name === "left") {
|
|
1553
|
-
const
|
|
1554
|
-
if (!
|
|
1570
|
+
const m = e[a];
|
|
1571
|
+
if (!m) {
|
|
1555
1572
|
c(null);
|
|
1556
1573
|
return;
|
|
1557
1574
|
}
|
|
1558
|
-
i =
|
|
1575
|
+
i = De(m, i, "left"), n = "", F(e, a, i, n);
|
|
1559
1576
|
return;
|
|
1560
1577
|
}
|
|
1561
1578
|
if (d.name === "right") {
|
|
1562
|
-
const
|
|
1563
|
-
if (!
|
|
1579
|
+
const m = e[a];
|
|
1580
|
+
if (!m) {
|
|
1564
1581
|
c(null);
|
|
1565
1582
|
return;
|
|
1566
1583
|
}
|
|
1567
|
-
i =
|
|
1584
|
+
i = De(m, i, "right"), n = "", F(e, a, i, n);
|
|
1568
1585
|
return;
|
|
1569
1586
|
}
|
|
1570
1587
|
if (d.name === "return" || d.name === "enter") {
|
|
1571
|
-
const
|
|
1572
|
-
if (!
|
|
1588
|
+
const m = e[a];
|
|
1589
|
+
if (!m) {
|
|
1573
1590
|
c(null);
|
|
1574
1591
|
return;
|
|
1575
1592
|
}
|
|
1576
|
-
const
|
|
1577
|
-
if (!
|
|
1578
|
-
n = r("command.list.interactive.note.restored_unavailable"),
|
|
1593
|
+
const u = oa(m, i);
|
|
1594
|
+
if (!he(m, u)) {
|
|
1595
|
+
n = r("command.list.interactive.note.restored_unavailable"), F(e, a, i, n);
|
|
1579
1596
|
return;
|
|
1580
1597
|
}
|
|
1581
|
-
c({ entry:
|
|
1598
|
+
c({ entry: m, action: u });
|
|
1582
1599
|
return;
|
|
1583
1600
|
}
|
|
1584
1601
|
(d.name === "q" || d.name === "escape") && c(null);
|
|
1585
1602
|
};
|
|
1586
|
-
t.on("keypress", s),
|
|
1603
|
+
t.on("keypress", s), F(e, a, i, n);
|
|
1587
1604
|
});
|
|
1588
1605
|
}
|
|
1589
|
-
function
|
|
1590
|
-
return e.vaultId ===
|
|
1606
|
+
function be(e, t) {
|
|
1607
|
+
return e.vaultId === g.Vault.id ? e.item : `${e.vaultName}${t}${e.item}`;
|
|
1591
1608
|
}
|
|
1592
|
-
function
|
|
1609
|
+
function sa(e) {
|
|
1593
1610
|
return String(e).padStart(4, "0");
|
|
1594
1611
|
}
|
|
1595
|
-
function
|
|
1596
|
-
return e.status ===
|
|
1612
|
+
function it(e) {
|
|
1613
|
+
return e.status === y.Archived ? "A" : "R";
|
|
1597
1614
|
}
|
|
1598
|
-
function
|
|
1599
|
-
const a =
|
|
1600
|
-
return `[${
|
|
1615
|
+
function la(e, t) {
|
|
1616
|
+
const a = Xe(it(e));
|
|
1617
|
+
return `[${sa(e.id)}] ${a} ${be(e, t)}`;
|
|
1601
1618
|
}
|
|
1602
|
-
function
|
|
1603
|
-
return e.map((a) =>
|
|
1619
|
+
function da(e, t) {
|
|
1620
|
+
return e.map((a) => la(a, t)).join(`
|
|
1604
1621
|
`);
|
|
1605
1622
|
}
|
|
1606
|
-
function
|
|
1607
|
-
return e.map((a) => `${a.id} ${
|
|
1623
|
+
function ua(e, t) {
|
|
1624
|
+
return e.map((a) => `${a.id} ${it(a)} ${be(a, t)}`).join(`
|
|
1608
1625
|
`);
|
|
1609
1626
|
}
|
|
1610
|
-
function
|
|
1627
|
+
function ma(e, t) {
|
|
1611
1628
|
return e.map((a) => ({
|
|
1612
1629
|
id: a.id,
|
|
1613
1630
|
status: a.status,
|
|
1614
|
-
title:
|
|
1631
|
+
title: be(a, t),
|
|
1615
1632
|
path: a.displayPath
|
|
1616
1633
|
}));
|
|
1617
1634
|
}
|
|
1618
|
-
async function
|
|
1635
|
+
async function va(e, t) {
|
|
1619
1636
|
const a = t.entry.id;
|
|
1620
1637
|
if (t.action === "restore") {
|
|
1621
1638
|
const n = await e.archiveService.restore([a]);
|
|
@@ -1627,13 +1644,13 @@ async function na(e, t) {
|
|
|
1627
1644
|
})
|
|
1628
1645
|
);
|
|
1629
1646
|
for (const o of n.failed)
|
|
1630
|
-
|
|
1647
|
+
j(
|
|
1631
1648
|
r("command.archive.result.restore.failed", {
|
|
1632
1649
|
id: o.id ?? "-",
|
|
1633
1650
|
message: o.message
|
|
1634
1651
|
})
|
|
1635
1652
|
);
|
|
1636
|
-
|
|
1653
|
+
K("restore", n), await V(e);
|
|
1637
1654
|
return;
|
|
1638
1655
|
}
|
|
1639
1656
|
const i = await e.archiveService.resolveCdTarget(String(a));
|
|
@@ -1650,11 +1667,11 @@ async function na(e, t) {
|
|
|
1650
1667
|
archiveId: i.archiveId
|
|
1651
1668
|
}),
|
|
1652
1669
|
{ aid: i.archiveId, vid: i.vault.id }
|
|
1653
|
-
), await
|
|
1670
|
+
), await ra(i.slotPath);
|
|
1654
1671
|
}
|
|
1655
|
-
function
|
|
1672
|
+
function ha(e, t) {
|
|
1656
1673
|
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) =>
|
|
1674
|
+
(a) => b(async () => {
|
|
1658
1675
|
const i = await t.archiveService.listEntries(a), n = await t.archiveService.decorateEntries(i), o = await t.configService.getConfig();
|
|
1659
1676
|
if (n.length === 0) {
|
|
1660
1677
|
if (a.plain)
|
|
@@ -1663,26 +1680,26 @@ function oa(e, t) {
|
|
|
1663
1680
|
return;
|
|
1664
1681
|
}
|
|
1665
1682
|
if (a.plain) {
|
|
1666
|
-
console.log(
|
|
1683
|
+
console.log(ua(n, o.vaultItemSeparator));
|
|
1667
1684
|
return;
|
|
1668
1685
|
}
|
|
1669
|
-
const c = a.interactive !== !1 &&
|
|
1686
|
+
const c = a.interactive !== !1 && at(), s = n.some((d) => d.status === y.Archived);
|
|
1670
1687
|
if (!c || !s) {
|
|
1671
|
-
console.log(
|
|
1688
|
+
console.log(da(n, o.vaultItemSeparator)), c && !s && A(r("command.list.restored_only_notice"));
|
|
1672
1689
|
return;
|
|
1673
1690
|
}
|
|
1674
|
-
const l = await
|
|
1691
|
+
const l = await ca(ma(n, o.vaultItemSeparator));
|
|
1675
1692
|
if (!l) {
|
|
1676
1693
|
A(r("command.list.cancelled"));
|
|
1677
1694
|
return;
|
|
1678
1695
|
}
|
|
1679
|
-
await
|
|
1696
|
+
await va(t, l);
|
|
1680
1697
|
})
|
|
1681
1698
|
);
|
|
1682
1699
|
}
|
|
1683
|
-
function
|
|
1700
|
+
function fa(e, t) {
|
|
1684
1701
|
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) =>
|
|
1702
|
+
(a, i) => b(async () => {
|
|
1686
1703
|
if (i.id !== void 0) {
|
|
1687
1704
|
if (!/^\d+$/.test(i.id))
|
|
1688
1705
|
throw new Error(r("command.log.error.invalid_id", { id: i.id }));
|
|
@@ -1694,12 +1711,12 @@ function ca(e, t) {
|
|
|
1694
1711
|
id: l.log.id
|
|
1695
1712
|
})
|
|
1696
1713
|
), console.log(
|
|
1697
|
-
|
|
1714
|
+
B(
|
|
1698
1715
|
[r("command.log.detail.table.field"), r("command.log.detail.table.value")],
|
|
1699
1716
|
[
|
|
1700
1717
|
[r("command.log.detail.field.id"), String(l.log.id)],
|
|
1701
1718
|
[r("command.log.detail.field.time"), l.log.operedAt],
|
|
1702
|
-
[r("command.log.detail.field.level"),
|
|
1719
|
+
[r("command.log.detail.field.level"), Re(l.log.level)],
|
|
1703
1720
|
[
|
|
1704
1721
|
r("command.log.detail.field.operation"),
|
|
1705
1722
|
`${l.log.oper.main}${l.log.oper.sub ? `/${l.log.oper.sub}` : ""}`
|
|
@@ -1716,7 +1733,7 @@ function ca(e, t) {
|
|
|
1716
1733
|
]
|
|
1717
1734
|
)
|
|
1718
1735
|
), l.archive && (A(r("command.log.detail.linked_archive")), console.log(
|
|
1719
|
-
|
|
1736
|
+
B(
|
|
1720
1737
|
[
|
|
1721
1738
|
r("command.log.detail.archive.table.id"),
|
|
1722
1739
|
r("command.log.detail.archive.table.status"),
|
|
@@ -1727,7 +1744,7 @@ function ca(e, t) {
|
|
|
1727
1744
|
[
|
|
1728
1745
|
[
|
|
1729
1746
|
String(l.archive.id),
|
|
1730
|
-
|
|
1747
|
+
Xe(l.archive.status),
|
|
1731
1748
|
String(l.archive.vaultId),
|
|
1732
1749
|
l.archive.item,
|
|
1733
1750
|
l.archive.directory
|
|
@@ -1735,7 +1752,7 @@ function ca(e, t) {
|
|
|
1735
1752
|
]
|
|
1736
1753
|
)
|
|
1737
1754
|
)), l.vault && (A(r("command.log.detail.linked_vault")), console.log(
|
|
1738
|
-
|
|
1755
|
+
B(
|
|
1739
1756
|
[
|
|
1740
1757
|
r("command.log.detail.vault.table.id"),
|
|
1741
1758
|
r("command.log.detail.vault.table.name"),
|
|
@@ -1746,7 +1763,7 @@ function ca(e, t) {
|
|
|
1746
1763
|
[
|
|
1747
1764
|
String(l.vault.id),
|
|
1748
1765
|
l.vault.name,
|
|
1749
|
-
|
|
1766
|
+
$t(l.vault.status),
|
|
1750
1767
|
l.vault.remark
|
|
1751
1768
|
]
|
|
1752
1769
|
]
|
|
@@ -1754,7 +1771,7 @@ function ca(e, t) {
|
|
|
1754
1771
|
));
|
|
1755
1772
|
return;
|
|
1756
1773
|
}
|
|
1757
|
-
const n =
|
|
1774
|
+
const n = Lt(a), o = await t.logService.getLogs(n);
|
|
1758
1775
|
if (o.length === 0) {
|
|
1759
1776
|
A(r("command.log.empty"));
|
|
1760
1777
|
return;
|
|
@@ -1762,14 +1779,14 @@ function ca(e, t) {
|
|
|
1762
1779
|
const c = o.map((s) => [
|
|
1763
1780
|
String(s.id),
|
|
1764
1781
|
s.operedAt,
|
|
1765
|
-
|
|
1782
|
+
Re(s.level),
|
|
1766
1783
|
`${s.oper.main}${s.oper.sub ? `/${s.oper.sub}` : ""}`,
|
|
1767
1784
|
s.message,
|
|
1768
1785
|
s.archiveIds !== void 0 ? String(s.archiveIds) : "",
|
|
1769
1786
|
s.vaultIds !== void 0 ? String(s.vaultIds) : ""
|
|
1770
1787
|
]);
|
|
1771
1788
|
console.log(
|
|
1772
|
-
|
|
1789
|
+
B(
|
|
1773
1790
|
[
|
|
1774
1791
|
r("command.log.table.id"),
|
|
1775
1792
|
r("command.log.table.time"),
|
|
@@ -1785,40 +1802,40 @@ function ca(e, t) {
|
|
|
1785
1802
|
})
|
|
1786
1803
|
);
|
|
1787
1804
|
}
|
|
1788
|
-
async function
|
|
1789
|
-
await
|
|
1805
|
+
async function Y(e) {
|
|
1806
|
+
await p.mkdir(e, { recursive: !0 });
|
|
1790
1807
|
}
|
|
1791
|
-
const E = (e) =>
|
|
1792
|
-
function
|
|
1808
|
+
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);
|
|
1809
|
+
function nt(e, t) {
|
|
1793
1810
|
const a = h.relative(h.resolve(e), h.resolve(t));
|
|
1794
1811
|
return a.length > 0 && !a.startsWith("..") && !h.isAbsolute(a);
|
|
1795
1812
|
}
|
|
1796
|
-
function
|
|
1797
|
-
return
|
|
1813
|
+
function pa(e, t) {
|
|
1814
|
+
return ga(e, t) || nt(e, t);
|
|
1798
1815
|
}
|
|
1799
|
-
async function
|
|
1816
|
+
async function X(e) {
|
|
1800
1817
|
const t = h.dirname(e);
|
|
1801
|
-
await
|
|
1818
|
+
await Y(t), await E(e) || await p.writeFile(e, "", "utf8");
|
|
1802
1819
|
}
|
|
1803
|
-
async function
|
|
1820
|
+
async function ae(e) {
|
|
1804
1821
|
try {
|
|
1805
|
-
return await
|
|
1822
|
+
return await p.lstat(e);
|
|
1806
1823
|
} catch (t) {
|
|
1807
1824
|
if (t.code === "ENOENT")
|
|
1808
1825
|
return;
|
|
1809
1826
|
throw t;
|
|
1810
1827
|
}
|
|
1811
1828
|
}
|
|
1812
|
-
async function
|
|
1829
|
+
async function _a(e) {
|
|
1813
1830
|
try {
|
|
1814
|
-
return (await
|
|
1831
|
+
return (await p.readdir(e, { withFileTypes: !0 })).filter((a) => a.isDirectory()).map((a) => a.name);
|
|
1815
1832
|
} catch (t) {
|
|
1816
1833
|
if (t.code === "ENOENT")
|
|
1817
1834
|
return [];
|
|
1818
1835
|
throw t;
|
|
1819
1836
|
}
|
|
1820
1837
|
}
|
|
1821
|
-
class
|
|
1838
|
+
class rt extends Error {
|
|
1822
1839
|
constructor(t) {
|
|
1823
1840
|
super(
|
|
1824
1841
|
r("service.vault.error.removed_exists", {
|
|
@@ -1827,7 +1844,7 @@ class Qe extends Error {
|
|
|
1827
1844
|
), this.name = "VaultRemovedExistsError";
|
|
1828
1845
|
}
|
|
1829
1846
|
}
|
|
1830
|
-
class
|
|
1847
|
+
class wa {
|
|
1831
1848
|
constructor(t, a) {
|
|
1832
1849
|
this.context = t, this.configService = a;
|
|
1833
1850
|
}
|
|
@@ -1838,10 +1855,10 @@ class ua {
|
|
|
1838
1855
|
const a = t.name.trim();
|
|
1839
1856
|
if (!a)
|
|
1840
1857
|
throw new Error(r("service.vault.error.name_empty"));
|
|
1841
|
-
if (a ===
|
|
1858
|
+
if (a === g.Vault.name)
|
|
1842
1859
|
throw new Error(
|
|
1843
1860
|
r("service.vault.error.name_reserved", {
|
|
1844
|
-
name:
|
|
1861
|
+
name: g.Vault.name
|
|
1845
1862
|
})
|
|
1846
1863
|
);
|
|
1847
1864
|
const i = await this.context.loadVaults(), n = i.find((s) => s.name === a);
|
|
@@ -1853,14 +1870,14 @@ class ua {
|
|
|
1853
1870
|
);
|
|
1854
1871
|
if (n?.status === "Removed") {
|
|
1855
1872
|
if (!t.recoverRemoved)
|
|
1856
|
-
throw new
|
|
1873
|
+
throw new rt(a);
|
|
1857
1874
|
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
1875
|
}
|
|
1859
1876
|
const c = {
|
|
1860
1877
|
id: await this.context.nextAutoIncrement("vaultId"),
|
|
1861
1878
|
name: a,
|
|
1862
1879
|
remark: t.remark ?? "",
|
|
1863
|
-
createdAt:
|
|
1880
|
+
createdAt: _e(),
|
|
1864
1881
|
status: S.Valid
|
|
1865
1882
|
};
|
|
1866
1883
|
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 +1918,10 @@ class ua {
|
|
|
1901
1918
|
const i = a.trim();
|
|
1902
1919
|
if (!i)
|
|
1903
1920
|
throw new Error(r("service.vault.error.new_name_empty"));
|
|
1904
|
-
if (i ===
|
|
1921
|
+
if (i === g.Vault.name)
|
|
1905
1922
|
throw new Error(
|
|
1906
1923
|
r("service.vault.error.name_reserved", {
|
|
1907
|
-
name:
|
|
1924
|
+
name: g.Vault.name
|
|
1908
1925
|
})
|
|
1909
1926
|
);
|
|
1910
1927
|
const n = await this.context.loadVaults(), o = n.find((s) => s.name === t || String(s.id) === t);
|
|
@@ -1939,7 +1956,7 @@ class ua {
|
|
|
1939
1956
|
reference: t
|
|
1940
1957
|
})
|
|
1941
1958
|
);
|
|
1942
|
-
if (a.id ===
|
|
1959
|
+
if (a.id === g.Vault.id || a.status === S.Protected)
|
|
1943
1960
|
throw new Error(r("service.vault.error.default_cannot_remove"));
|
|
1944
1961
|
if (a.status === S.Removed)
|
|
1945
1962
|
throw new Error(
|
|
@@ -1947,12 +1964,12 @@ class ua {
|
|
|
1947
1964
|
name: a.name
|
|
1948
1965
|
})
|
|
1949
1966
|
);
|
|
1950
|
-
const i = await this.context.loadListEntries(), n = i.filter((d) => d.vaultId === a.id && d.status ===
|
|
1951
|
-
await this.context.ensureVaultDir(
|
|
1967
|
+
const i = await this.context.loadListEntries(), n = i.filter((d) => d.vaultId === a.id && d.status === y.Archived);
|
|
1968
|
+
await this.context.ensureVaultDir(g.Vault.id), await this.validateMoveToDefault(n);
|
|
1952
1969
|
const o = [];
|
|
1953
1970
|
for (const d of n) {
|
|
1954
|
-
const
|
|
1955
|
-
await
|
|
1971
|
+
const m = this.context.archivePath(a.id, d.id), u = this.context.archivePath(g.Vault.id, d.id);
|
|
1972
|
+
await p.rename(m, u), d.vaultId = g.Vault.id, o.push(d.id);
|
|
1956
1973
|
}
|
|
1957
1974
|
const c = await this.context.loadVaults(), s = c.find((d) => d.id === a.id);
|
|
1958
1975
|
if (!s)
|
|
@@ -1963,11 +1980,11 @@ class ua {
|
|
|
1963
1980
|
);
|
|
1964
1981
|
s.status = S.Removed, await this.context.saveListEntries(i), await this.context.saveVaults(c);
|
|
1965
1982
|
const l = await this.context.loadConfig();
|
|
1966
|
-
return l.currentVaultId === a.id && (l.currentVaultId =
|
|
1983
|
+
return l.currentVaultId === a.id && (l.currentVaultId = g.Vault.id, await this.context.saveConfig(l)), { vault: s, movedArchiveIds: o };
|
|
1967
1984
|
}
|
|
1968
1985
|
async validateMoveToDefault(t) {
|
|
1969
1986
|
for (const a of t) {
|
|
1970
|
-
const i = this.context.archivePath(a.vaultId, a.id), n = this.context.archivePath(
|
|
1987
|
+
const i = this.context.archivePath(a.vaultId, a.id), n = this.context.archivePath(g.Vault.id, a.id);
|
|
1971
1988
|
if (!await E(i))
|
|
1972
1989
|
throw new Error(
|
|
1973
1990
|
r("service.vault.error.archived_object_missing", {
|
|
@@ -1991,31 +2008,31 @@ class ua {
|
|
|
1991
2008
|
}
|
|
1992
2009
|
async listArchivedIdsInVault(t) {
|
|
1993
2010
|
const a = this.context.vaultDir(t);
|
|
1994
|
-
return await E(a) ? (await
|
|
2011
|
+
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
2012
|
}
|
|
1996
2013
|
getVaultDisplay(t) {
|
|
1997
|
-
return t.id ===
|
|
2014
|
+
return t.id === g.Vault.id ? `${t.name}(${t.id})` : `${t.name}(${t.id})`;
|
|
1998
2015
|
}
|
|
1999
2016
|
vaultRoot(t) {
|
|
2000
|
-
return h.join(
|
|
2017
|
+
return h.join(f.Dir.vaults, String(t.id));
|
|
2001
2018
|
}
|
|
2002
2019
|
}
|
|
2003
|
-
async function
|
|
2004
|
-
const t =
|
|
2020
|
+
async function ot(e) {
|
|
2021
|
+
const t = pt.createInterface({ input: wt, output: _t });
|
|
2005
2022
|
try {
|
|
2006
2023
|
return (await t.question(e)).trim();
|
|
2007
2024
|
} finally {
|
|
2008
2025
|
t.close();
|
|
2009
2026
|
}
|
|
2010
2027
|
}
|
|
2011
|
-
async function
|
|
2012
|
-
const a = (await
|
|
2028
|
+
async function Oe(e, t = !0) {
|
|
2029
|
+
const a = (await ot(e)).toLowerCase();
|
|
2013
2030
|
return a ? ["y", "yes"].includes(a) : !t;
|
|
2014
2031
|
}
|
|
2015
|
-
function
|
|
2032
|
+
function Ia(e, t) {
|
|
2016
2033
|
const a = e.command("vault").description(r("command.vault.description"));
|
|
2017
2034
|
a.command("use").description(r("command.vault.use.description")).argument("<name-or-id>", r("command.vault.use.argument")).action(
|
|
2018
|
-
(i) =>
|
|
2035
|
+
(i) => b(async () => {
|
|
2019
2036
|
const n = await t.vaultService.useVault(i);
|
|
2020
2037
|
C(
|
|
2021
2038
|
r("command.vault.use.updated", {
|
|
@@ -2033,7 +2050,7 @@ function ma(e, t) {
|
|
|
2033
2050
|
), await V(t);
|
|
2034
2051
|
})
|
|
2035
2052
|
), 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) =>
|
|
2053
|
+
(i, n) => b(async () => {
|
|
2037
2054
|
let o = !1;
|
|
2038
2055
|
const c = async (s) => {
|
|
2039
2056
|
const l = await t.vaultService.createVault({
|
|
@@ -2073,13 +2090,13 @@ function ma(e, t) {
|
|
|
2073
2090
|
try {
|
|
2074
2091
|
await c(!1);
|
|
2075
2092
|
} catch (s) {
|
|
2076
|
-
if (s instanceof
|
|
2077
|
-
if (!await
|
|
2093
|
+
if (s instanceof rt) {
|
|
2094
|
+
if (!await Oe(
|
|
2078
2095
|
r("command.vault.create.confirm_recover", {
|
|
2079
2096
|
name: i
|
|
2080
2097
|
})
|
|
2081
2098
|
)) {
|
|
2082
|
-
|
|
2099
|
+
se(r("command.vault.operation.cancelled"));
|
|
2083
2100
|
return;
|
|
2084
2101
|
}
|
|
2085
2102
|
await c(!0);
|
|
@@ -2089,22 +2106,22 @@ function ma(e, t) {
|
|
|
2089
2106
|
await V(t);
|
|
2090
2107
|
})
|
|
2091
2108
|
), a.command("remove").description(r("command.vault.remove.description")).argument("<name-or-id>", r("command.vault.remove.argument")).action(
|
|
2092
|
-
(i) =>
|
|
2093
|
-
if (!await
|
|
2109
|
+
(i) => b(async () => {
|
|
2110
|
+
if (!await Oe(
|
|
2094
2111
|
r("command.vault.remove.confirm", {
|
|
2095
2112
|
nameOrId: i
|
|
2096
2113
|
})
|
|
2097
2114
|
)) {
|
|
2098
|
-
|
|
2115
|
+
se(r("command.vault.operation.cancelled"));
|
|
2099
2116
|
return;
|
|
2100
2117
|
}
|
|
2101
2118
|
const o = Math.random().toString(36).slice(2, 8).toUpperCase();
|
|
2102
|
-
if (await
|
|
2119
|
+
if (await ot(
|
|
2103
2120
|
r("command.vault.remove.verify_prompt", {
|
|
2104
2121
|
verifyCode: o
|
|
2105
2122
|
})
|
|
2106
2123
|
) !== o) {
|
|
2107
|
-
|
|
2124
|
+
se(r("command.vault.remove.verify_mismatch"));
|
|
2108
2125
|
return;
|
|
2109
2126
|
}
|
|
2110
2127
|
const s = await t.vaultService.removeVault(i);
|
|
@@ -2116,7 +2133,7 @@ function ma(e, t) {
|
|
|
2116
2133
|
), s.movedArchiveIds.length > 0 && A(
|
|
2117
2134
|
r("command.vault.remove.moved_to_default", {
|
|
2118
2135
|
count: s.movedArchiveIds.length,
|
|
2119
|
-
name:
|
|
2136
|
+
name: g.Vault.name
|
|
2120
2137
|
})
|
|
2121
2138
|
), await t.auditLogger.log(
|
|
2122
2139
|
"WARN",
|
|
@@ -2134,7 +2151,7 @@ function ma(e, t) {
|
|
|
2134
2151
|
), await V(t);
|
|
2135
2152
|
})
|
|
2136
2153
|
), a.command("recover").description(r("command.vault.recover.description")).argument("<name-or-id>", r("command.vault.recover.argument")).action(
|
|
2137
|
-
(i) =>
|
|
2154
|
+
(i) => b(async () => {
|
|
2138
2155
|
const n = await t.vaultService.recoverVault(i);
|
|
2139
2156
|
C(
|
|
2140
2157
|
r("command.vault.recover.done", {
|
|
@@ -2157,7 +2174,7 @@ function ma(e, t) {
|
|
|
2157
2174
|
), await V(t);
|
|
2158
2175
|
})
|
|
2159
2176
|
), 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) =>
|
|
2177
|
+
(i, n) => b(async () => {
|
|
2161
2178
|
const o = await t.vaultService.renameVault(i, n);
|
|
2162
2179
|
C(
|
|
2163
2180
|
r("command.vault.rename.done", {
|
|
@@ -2180,7 +2197,7 @@ function ma(e, t) {
|
|
|
2180
2197
|
), await V(t);
|
|
2181
2198
|
})
|
|
2182
2199
|
), a.command("list").description(r("command.vault.list.description")).option("-a, --all", r("command.vault.list.option.all")).action(
|
|
2183
|
-
(i) =>
|
|
2200
|
+
(i) => b(async () => {
|
|
2184
2201
|
const n = await t.vaultService.listVaults(!!i.all);
|
|
2185
2202
|
if (n.length === 0) {
|
|
2186
2203
|
A(r("command.vault.list.empty"));
|
|
@@ -2192,11 +2209,11 @@ function ma(e, t) {
|
|
|
2192
2209
|
})
|
|
2193
2210
|
);
|
|
2194
2211
|
}
|
|
2195
|
-
function
|
|
2196
|
-
const t = new
|
|
2197
|
-
return t.name(
|
|
2212
|
+
function ya(e) {
|
|
2213
|
+
const t = new gt();
|
|
2214
|
+
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
2215
|
}
|
|
2199
|
-
const
|
|
2216
|
+
const Fe = {
|
|
2200
2217
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2201
2218
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2202
2219
|
functionPattern: /(^|\n)\s*(function\s+)?arv\s*(\(\))?\s*\{/m,
|
|
@@ -2221,7 +2238,7 @@ const Le = {
|
|
|
2221
2238
|
fi
|
|
2222
2239
|
return $status
|
|
2223
2240
|
}`
|
|
2224
|
-
},
|
|
2241
|
+
}, ba = {
|
|
2225
2242
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2226
2243
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2227
2244
|
functionPattern: /(^|\n)\s*function\s+arv\b/m,
|
|
@@ -2247,7 +2264,7 @@ const Le = {
|
|
|
2247
2264
|
rm -f $target_tmp
|
|
2248
2265
|
return $status
|
|
2249
2266
|
end`
|
|
2250
|
-
},
|
|
2267
|
+
}, ka = {
|
|
2251
2268
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2252
2269
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2253
2270
|
functionPattern: /(^|\r?\n)\s*function\s+arv\b/im,
|
|
@@ -2287,7 +2304,7 @@ end`
|
|
|
2287
2304
|
$global:LASTEXITCODE = $status
|
|
2288
2305
|
}`
|
|
2289
2306
|
};
|
|
2290
|
-
function
|
|
2307
|
+
function Ca(e) {
|
|
2291
2308
|
const t = h.basename(e).toLowerCase();
|
|
2292
2309
|
if (t.includes("bash"))
|
|
2293
2310
|
return "bash";
|
|
@@ -2298,17 +2315,17 @@ function ga(e) {
|
|
|
2298
2315
|
if (t.includes("pwsh") || t.includes("powershell"))
|
|
2299
2316
|
return "powershell";
|
|
2300
2317
|
}
|
|
2301
|
-
function
|
|
2318
|
+
function je(e) {
|
|
2302
2319
|
return e.endsWith(`
|
|
2303
2320
|
`) ? e : `${e}
|
|
2304
2321
|
`;
|
|
2305
2322
|
}
|
|
2306
|
-
function
|
|
2323
|
+
function ct(e) {
|
|
2307
2324
|
return `${e.startMarker}
|
|
2308
2325
|
${e.body}
|
|
2309
2326
|
${e.endMarker}`;
|
|
2310
2327
|
}
|
|
2311
|
-
function
|
|
2328
|
+
function Ea(e, t) {
|
|
2312
2329
|
const a = e.indexOf(t.startMarker);
|
|
2313
2330
|
if (a === -1)
|
|
2314
2331
|
return;
|
|
@@ -2319,8 +2336,8 @@ function pa(e, t) {
|
|
|
2319
2336
|
end: i + t.endMarker.length
|
|
2320
2337
|
};
|
|
2321
2338
|
}
|
|
2322
|
-
function
|
|
2323
|
-
const a =
|
|
2339
|
+
function Aa(e, t) {
|
|
2340
|
+
const a = ct(t);
|
|
2324
2341
|
if (e.trim().length === 0)
|
|
2325
2342
|
return `${a}
|
|
2326
2343
|
`;
|
|
@@ -2332,7 +2349,7 @@ function _a(e, t) {
|
|
|
2332
2349
|
return `${e}${i}${a}
|
|
2333
2350
|
`;
|
|
2334
2351
|
}
|
|
2335
|
-
async function
|
|
2352
|
+
async function Sa(e, t) {
|
|
2336
2353
|
for (const a of t) {
|
|
2337
2354
|
const i = h.join(e, a);
|
|
2338
2355
|
if (await E(i))
|
|
@@ -2340,35 +2357,35 @@ async function wa(e, t) {
|
|
|
2340
2357
|
}
|
|
2341
2358
|
return h.join(e, t[0] ?? ".bashrc");
|
|
2342
2359
|
}
|
|
2343
|
-
async function
|
|
2344
|
-
await
|
|
2345
|
-
const a = await
|
|
2360
|
+
async function J(e, t) {
|
|
2361
|
+
await X(e);
|
|
2362
|
+
const a = await p.readFile(e, "utf8"), i = Ea(a, t);
|
|
2346
2363
|
if (i) {
|
|
2347
|
-
const o = a.slice(i.start, i.end), c =
|
|
2364
|
+
const o = a.slice(i.start, i.end), c = ct(t);
|
|
2348
2365
|
if (o === c)
|
|
2349
2366
|
return !1;
|
|
2350
2367
|
const s = `${a.slice(0, i.start)}${c}${a.slice(i.end)}`;
|
|
2351
|
-
return await
|
|
2368
|
+
return await p.writeFile(e, je(s), "utf8"), !0;
|
|
2352
2369
|
}
|
|
2353
2370
|
if (t.functionPattern.test(a))
|
|
2354
2371
|
return !1;
|
|
2355
|
-
const n =
|
|
2356
|
-
return await
|
|
2372
|
+
const n = je(Aa(a, t));
|
|
2373
|
+
return await p.writeFile(e, n, "utf8"), !0;
|
|
2357
2374
|
}
|
|
2358
|
-
function
|
|
2375
|
+
function xa(e, t) {
|
|
2359
2376
|
const a = h.resolve(t), i = h.resolve(e);
|
|
2360
2377
|
if (i === a)
|
|
2361
2378
|
return "~";
|
|
2362
2379
|
const n = `${a}${h.sep}`;
|
|
2363
2380
|
return i.startsWith(n) ? `~${i.slice(a.length)}` : e;
|
|
2364
2381
|
}
|
|
2365
|
-
function
|
|
2382
|
+
function Va(e) {
|
|
2366
2383
|
return `'${e.replaceAll("'", "'\\''")}'`;
|
|
2367
2384
|
}
|
|
2368
|
-
function
|
|
2385
|
+
function Ra(e) {
|
|
2369
2386
|
return `'${e.replaceAll("'", "''")}'`;
|
|
2370
2387
|
}
|
|
2371
|
-
async function
|
|
2388
|
+
async function La(e) {
|
|
2372
2389
|
if (process.platform === "win32") {
|
|
2373
2390
|
const t = [
|
|
2374
2391
|
h.join(e, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1"),
|
|
@@ -2381,58 +2398,58 @@ async function ka(e) {
|
|
|
2381
2398
|
}
|
|
2382
2399
|
return h.join(e, ".config", "powershell", "Microsoft.PowerShell_profile.ps1");
|
|
2383
2400
|
}
|
|
2384
|
-
function
|
|
2385
|
-
const n =
|
|
2401
|
+
function G(e, t, a, i) {
|
|
2402
|
+
const n = xa(t, a);
|
|
2386
2403
|
return e === "powershell" ? {
|
|
2387
2404
|
installed: i,
|
|
2388
2405
|
shell: e,
|
|
2389
2406
|
profilePath: n,
|
|
2390
|
-
reloadCommand: `. ${
|
|
2407
|
+
reloadCommand: `. ${Ra(t)}`
|
|
2391
2408
|
} : {
|
|
2392
2409
|
installed: i,
|
|
2393
2410
|
shell: e,
|
|
2394
2411
|
profilePath: n,
|
|
2395
|
-
reloadCommand: `source ${
|
|
2412
|
+
reloadCommand: `source ${Va(t)}`
|
|
2396
2413
|
};
|
|
2397
2414
|
}
|
|
2398
|
-
async function
|
|
2415
|
+
async function Ta(e = {}) {
|
|
2399
2416
|
const t = e.env ?? process.env;
|
|
2400
2417
|
if (t.ARCHIVER_DISABLE_SHELL_INIT === "1")
|
|
2401
2418
|
return { installed: !1 };
|
|
2402
2419
|
if (!(e.stdinIsTTY ?? !!process.stdin.isTTY))
|
|
2403
2420
|
return { installed: !1 };
|
|
2404
|
-
const i = e.homeDir ?? t.HOME ?? t.USERPROFILE ??
|
|
2421
|
+
const i = e.homeDir ?? t.HOME ?? t.USERPROFILE ?? Je.homedir();
|
|
2405
2422
|
if (!i)
|
|
2406
2423
|
return { installed: !1 };
|
|
2407
|
-
const n = e.shellPath ?? t.SHELL ?? "", o =
|
|
2424
|
+
const n = e.shellPath ?? t.SHELL ?? "", o = Ca(n);
|
|
2408
2425
|
if (!o)
|
|
2409
2426
|
return { installed: !1 };
|
|
2410
2427
|
try {
|
|
2411
2428
|
if (o === "bash") {
|
|
2412
|
-
const l = await
|
|
2413
|
-
return
|
|
2429
|
+
const l = await Sa(i, [".bashrc", ".bash_profile", ".profile"]), d = await J(l, Fe);
|
|
2430
|
+
return G(o, l, i, d);
|
|
2414
2431
|
}
|
|
2415
2432
|
if (o === "zsh") {
|
|
2416
|
-
const l = h.join(i, ".zshrc"), d = await
|
|
2417
|
-
return
|
|
2433
|
+
const l = h.join(i, ".zshrc"), d = await J(l, Fe);
|
|
2434
|
+
return G(o, l, i, d);
|
|
2418
2435
|
}
|
|
2419
2436
|
if (o === "fish") {
|
|
2420
2437
|
const l = h.join(i, ".config", "fish", "functions", "arv.fish");
|
|
2421
|
-
await
|
|
2422
|
-
const d = await
|
|
2423
|
-
return
|
|
2438
|
+
await Y(h.dirname(l));
|
|
2439
|
+
const d = await J(l, ba);
|
|
2440
|
+
return G(o, l, i, d);
|
|
2424
2441
|
}
|
|
2425
|
-
const c = await
|
|
2426
|
-
await
|
|
2427
|
-
const s = await
|
|
2428
|
-
return
|
|
2442
|
+
const c = await La(i);
|
|
2443
|
+
await Y(h.dirname(c));
|
|
2444
|
+
const s = await J(c, ka);
|
|
2445
|
+
return G(o, c, i, s);
|
|
2429
2446
|
} catch {
|
|
2430
2447
|
return { installed: !1 };
|
|
2431
2448
|
}
|
|
2432
2449
|
}
|
|
2433
|
-
async function
|
|
2450
|
+
async function ie(e) {
|
|
2434
2451
|
try {
|
|
2435
|
-
const t = await
|
|
2452
|
+
const t = await p.readFile(e, "utf8");
|
|
2436
2453
|
return t.trim() ? t.split(/\r?\n/).map((i) => i.trim()).filter((i) => i.length > 0).map((i, n) => {
|
|
2437
2454
|
try {
|
|
2438
2455
|
return JSON.parse(i);
|
|
@@ -2451,36 +2468,36 @@ async function ee(e) {
|
|
|
2451
2468
|
throw t;
|
|
2452
2469
|
}
|
|
2453
2470
|
}
|
|
2454
|
-
async function
|
|
2471
|
+
async function Ye(e, t) {
|
|
2455
2472
|
const a = t.map((i) => JSON.stringify(i)).join(`
|
|
2456
2473
|
`);
|
|
2457
|
-
await
|
|
2474
|
+
await p.writeFile(e, a.length > 0 ? `${a}
|
|
2458
2475
|
` : "", "utf8");
|
|
2459
2476
|
}
|
|
2460
|
-
async function
|
|
2461
|
-
await
|
|
2477
|
+
async function st(e, t) {
|
|
2478
|
+
await p.appendFile(e, `${JSON.stringify(t)}
|
|
2462
2479
|
`, "utf8");
|
|
2463
2480
|
}
|
|
2464
|
-
function
|
|
2481
|
+
function He(e) {
|
|
2465
2482
|
return {
|
|
2466
|
-
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId :
|
|
2483
|
+
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId : g.Config.currentVaultId,
|
|
2467
2484
|
updateCheck: e.updateCheck === "off" ? "off" : "on",
|
|
2468
2485
|
lastUpdateCheck: typeof e.lastUpdateCheck == "string" ? e.lastUpdateCheck : "",
|
|
2469
|
-
vaultItemSeparator: typeof e.vaultItemSeparator == "string" && e.vaultItemSeparator.length > 0 ? e.vaultItemSeparator :
|
|
2486
|
+
vaultItemSeparator: typeof e.vaultItemSeparator == "string" && e.vaultItemSeparator.length > 0 ? e.vaultItemSeparator : g.Config.vaultItemSeparator,
|
|
2470
2487
|
style: e.style === "off" ? "off" : "on",
|
|
2471
2488
|
language: e.language === "en" ? "en" : "zh",
|
|
2472
2489
|
noCommandAction: e.noCommandAction === "help" || e.noCommandAction === "list" ? e.noCommandAction : "unknown"
|
|
2473
2490
|
};
|
|
2474
2491
|
}
|
|
2475
|
-
function
|
|
2492
|
+
function Ue(e) {
|
|
2476
2493
|
return {
|
|
2477
2494
|
logId: Number.isInteger(e.logId) && e.logId >= 0 ? e.logId : 0,
|
|
2478
2495
|
vaultId: Number.isInteger(e.vaultId) && e.vaultId >= 0 ? e.vaultId : 0,
|
|
2479
2496
|
archiveId: Number.isInteger(e.archiveId) && e.archiveId >= 0 ? e.archiveId : 0
|
|
2480
2497
|
};
|
|
2481
2498
|
}
|
|
2482
|
-
function
|
|
2483
|
-
const t = e.isDirectory === 1 ? 1 : 0, a = e.status ===
|
|
2499
|
+
function ze(e) {
|
|
2500
|
+
const t = e.isDirectory === 1 ? 1 : 0, a = e.status === y.Restored ? y.Restored : y.Archived;
|
|
2484
2501
|
return {
|
|
2485
2502
|
archivedAt: String(e.archivedAt ?? ""),
|
|
2486
2503
|
status: a,
|
|
@@ -2493,7 +2510,7 @@ function Me(e) {
|
|
|
2493
2510
|
remark: String(e.remark ?? "")
|
|
2494
2511
|
};
|
|
2495
2512
|
}
|
|
2496
|
-
function
|
|
2513
|
+
function Be(e) {
|
|
2497
2514
|
const t = S[e.status] ?? S.Valid;
|
|
2498
2515
|
return {
|
|
2499
2516
|
id: e.id,
|
|
@@ -2503,35 +2520,35 @@ function Fe(e) {
|
|
|
2503
2520
|
status: t
|
|
2504
2521
|
};
|
|
2505
2522
|
}
|
|
2506
|
-
class
|
|
2523
|
+
class $a {
|
|
2507
2524
|
configCache;
|
|
2508
2525
|
autoIncrCache;
|
|
2509
2526
|
listCache;
|
|
2510
2527
|
vaultCache;
|
|
2511
2528
|
async init() {
|
|
2512
|
-
for (const a of Object.values(
|
|
2513
|
-
await
|
|
2514
|
-
await
|
|
2529
|
+
for (const a of Object.values(f.Dir))
|
|
2530
|
+
await Y(a);
|
|
2531
|
+
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
2532
|
const t = await this.loadConfig();
|
|
2516
|
-
t.currentVaultId === 0 || await E(this.vaultDir(t.currentVaultId)) || (t.currentVaultId =
|
|
2533
|
+
t.currentVaultId === 0 || await E(this.vaultDir(t.currentVaultId)) || (t.currentVaultId = g.Vault.id, await this.saveConfig(t));
|
|
2517
2534
|
}
|
|
2518
2535
|
async loadConfig(t = !1) {
|
|
2519
2536
|
if (this.configCache && !t)
|
|
2520
2537
|
return this.configCache;
|
|
2521
|
-
const a = await
|
|
2522
|
-
return
|
|
2538
|
+
const a = await ve(f.File.config, g.Config), i = He({ ...g.Config, ...a });
|
|
2539
|
+
return Z(i.language), this.configCache = i, i;
|
|
2523
2540
|
}
|
|
2524
2541
|
async saveConfig(t) {
|
|
2525
|
-
this.configCache =
|
|
2542
|
+
this.configCache = He(t), Z(this.configCache.language), await xe(f.File.config, this.configCache, de);
|
|
2526
2543
|
}
|
|
2527
2544
|
async loadAutoIncr(t = !1) {
|
|
2528
2545
|
if (this.autoIncrCache && !t)
|
|
2529
2546
|
return this.autoIncrCache;
|
|
2530
|
-
const a = await
|
|
2547
|
+
const a = await ve(f.File.autoIncr, g.AutoIncr), i = Ue({ ...g.AutoIncr, ...a });
|
|
2531
2548
|
return this.autoIncrCache = i, i;
|
|
2532
2549
|
}
|
|
2533
2550
|
async saveAutoIncr(t) {
|
|
2534
|
-
this.autoIncrCache =
|
|
2551
|
+
this.autoIncrCache = Ue(t), await xe(f.File.autoIncr, this.autoIncrCache, ue);
|
|
2535
2552
|
}
|
|
2536
2553
|
async nextAutoIncrement(t) {
|
|
2537
2554
|
const a = await this.loadAutoIncr();
|
|
@@ -2540,31 +2557,31 @@ class Ea {
|
|
|
2540
2557
|
async loadListEntries(t = !1) {
|
|
2541
2558
|
if (this.listCache && !t)
|
|
2542
2559
|
return this.listCache;
|
|
2543
|
-
const a = await
|
|
2544
|
-
return this.listCache = a.map((i) =>
|
|
2560
|
+
const a = await ie(f.File.list);
|
|
2561
|
+
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
2562
|
}
|
|
2546
2563
|
async saveListEntries(t) {
|
|
2547
|
-
this.listCache = [...t].sort((a, i) => a.id - i.id), await
|
|
2564
|
+
this.listCache = [...t].sort((a, i) => a.id - i.id), await Ye(f.File.list, this.listCache);
|
|
2548
2565
|
}
|
|
2549
2566
|
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
|
|
2567
|
+
const a = ze(t);
|
|
2568
|
+
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
2569
|
}
|
|
2553
2570
|
async loadVaults(t = !1) {
|
|
2554
2571
|
if (this.vaultCache && !t)
|
|
2555
2572
|
return this.vaultCache;
|
|
2556
|
-
const a = await
|
|
2557
|
-
return this.vaultCache = a.map((i) =>
|
|
2573
|
+
const a = await ie(f.File.vaults);
|
|
2574
|
+
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
2575
|
}
|
|
2559
2576
|
async saveVaults(t) {
|
|
2560
|
-
const a = t.map((i) =>
|
|
2561
|
-
this.vaultCache = a, await
|
|
2577
|
+
const a = t.map((i) => Be(i)).filter((i) => i.id > 0).sort((i, n) => i.id - n.id);
|
|
2578
|
+
this.vaultCache = a, await Ye(f.File.vaults, a);
|
|
2562
2579
|
}
|
|
2563
2580
|
async getVaults(t) {
|
|
2564
2581
|
const a = t?.includeRemoved ?? !1, i = t?.withDefault ?? !0, n = await this.loadVaults(), o = a ? n : n.filter((c) => c.status === "Valid");
|
|
2565
2582
|
return i ? [
|
|
2566
2583
|
{
|
|
2567
|
-
...
|
|
2584
|
+
...g.Vault,
|
|
2568
2585
|
remark: r("defaults.vault.remark")
|
|
2569
2586
|
},
|
|
2570
2587
|
...o
|
|
@@ -2587,7 +2604,7 @@ class Ea {
|
|
|
2587
2604
|
return s;
|
|
2588
2605
|
}
|
|
2589
2606
|
vaultDir(t) {
|
|
2590
|
-
return h.join(
|
|
2607
|
+
return h.join(f.Dir.vaults, String(t));
|
|
2591
2608
|
}
|
|
2592
2609
|
archivePath(t, a) {
|
|
2593
2610
|
return h.join(this.vaultDir(t), String(a));
|
|
@@ -2596,7 +2613,7 @@ class Ea {
|
|
|
2596
2613
|
return h.join(this.archivePath(t, a), i);
|
|
2597
2614
|
}
|
|
2598
2615
|
async resolveArchiveStorageLocation(t) {
|
|
2599
|
-
const a = this.archivePath(t.vaultId, t.id), i = await
|
|
2616
|
+
const a = this.archivePath(t.vaultId, t.id), i = await ae(a);
|
|
2600
2617
|
if (!i || !i.isDirectory())
|
|
2601
2618
|
return;
|
|
2602
2619
|
const n = this.archiveObjectPath(t.vaultId, t.id, t.item);
|
|
@@ -2607,13 +2624,13 @@ class Ea {
|
|
|
2607
2624
|
};
|
|
2608
2625
|
}
|
|
2609
2626
|
async ensureVaultDir(t) {
|
|
2610
|
-
await
|
|
2627
|
+
await Y(this.vaultDir(t));
|
|
2611
2628
|
}
|
|
2612
2629
|
async removeVaultDir(t) {
|
|
2613
|
-
t !==
|
|
2630
|
+
t !== g.Vault.id && await p.rm(this.vaultDir(t), { recursive: !0, force: !0 });
|
|
2614
2631
|
}
|
|
2615
2632
|
}
|
|
2616
|
-
class
|
|
2633
|
+
class Na {
|
|
2617
2634
|
constructor(t, a) {
|
|
2618
2635
|
this.context = t, this.logger = a;
|
|
2619
2636
|
}
|
|
@@ -2627,8 +2644,8 @@ class Aa {
|
|
|
2627
2644
|
const o = { ok: [], failed: [] };
|
|
2628
2645
|
for (const c of n) {
|
|
2629
2646
|
const s = await this.context.nextAutoIncrement("archiveId"), l = this.context.archivePath(i.id, s), d = {
|
|
2630
|
-
archivedAt:
|
|
2631
|
-
status:
|
|
2647
|
+
archivedAt: _e(),
|
|
2648
|
+
status: y.Archived,
|
|
2632
2649
|
isDirectory: c.stats.isDirectory() ? 1 : 0,
|
|
2633
2650
|
vaultId: i.id,
|
|
2634
2651
|
id: s,
|
|
@@ -2644,13 +2661,13 @@ class Aa {
|
|
|
2644
2661
|
path: l
|
|
2645
2662
|
})
|
|
2646
2663
|
);
|
|
2647
|
-
await
|
|
2648
|
-
const
|
|
2664
|
+
await p.mkdir(l, { recursive: !1 });
|
|
2665
|
+
const m = this.context.archiveObjectPath(i.id, s, d.item);
|
|
2649
2666
|
try {
|
|
2650
|
-
await
|
|
2651
|
-
} catch (
|
|
2652
|
-
throw await
|
|
2653
|
-
}),
|
|
2667
|
+
await p.rename(c.resolvedPath, m);
|
|
2668
|
+
} catch (u) {
|
|
2669
|
+
throw await p.rmdir(l).catch(() => {
|
|
2670
|
+
}), u;
|
|
2654
2671
|
}
|
|
2655
2672
|
await this.context.appendListEntry(d), await this.logger.log(
|
|
2656
2673
|
"INFO",
|
|
@@ -2675,8 +2692,8 @@ class Aa {
|
|
|
2675
2692
|
id: i.id
|
|
2676
2693
|
})
|
|
2677
2694
|
});
|
|
2678
|
-
} catch (
|
|
2679
|
-
const
|
|
2695
|
+
} catch (m) {
|
|
2696
|
+
const u = m.message;
|
|
2680
2697
|
await this.logger.log(
|
|
2681
2698
|
"ERROR",
|
|
2682
2699
|
{
|
|
@@ -2689,13 +2706,13 @@ class Aa {
|
|
|
2689
2706
|
},
|
|
2690
2707
|
r("service.archive.log.archive_failed", {
|
|
2691
2708
|
input: c.input,
|
|
2692
|
-
message:
|
|
2709
|
+
message: u
|
|
2693
2710
|
})
|
|
2694
2711
|
), o.failed.push({
|
|
2695
2712
|
id: s,
|
|
2696
2713
|
input: c.input,
|
|
2697
2714
|
success: !1,
|
|
2698
|
-
message:
|
|
2715
|
+
message: u
|
|
2699
2716
|
});
|
|
2700
2717
|
}
|
|
2701
2718
|
}
|
|
@@ -2713,7 +2730,7 @@ class Aa {
|
|
|
2713
2730
|
id: c
|
|
2714
2731
|
})
|
|
2715
2732
|
);
|
|
2716
|
-
if (s.status !==
|
|
2733
|
+
if (s.status !== y.Archived)
|
|
2717
2734
|
throw new Error(
|
|
2718
2735
|
r("service.archive.error.id_already_restored", {
|
|
2719
2736
|
id: c
|
|
@@ -2746,10 +2763,10 @@ class Aa {
|
|
|
2746
2763
|
path: d
|
|
2747
2764
|
})
|
|
2748
2765
|
);
|
|
2749
|
-
await
|
|
2750
|
-
if (
|
|
2751
|
-
throw
|
|
2752
|
-
}), s.status =
|
|
2766
|
+
await p.mkdir(s.directory, { recursive: !0 }), await p.rename(l.objectPath, d), await p.rmdir(l.slotPath).catch((m) => {
|
|
2767
|
+
if (m.code !== "ENOENT")
|
|
2768
|
+
throw m;
|
|
2769
|
+
}), s.status = y.Restored, o = !0, await this.logger.log(
|
|
2753
2770
|
"INFO",
|
|
2754
2771
|
{
|
|
2755
2772
|
main: "restore",
|
|
@@ -2764,8 +2781,8 @@ class Aa {
|
|
|
2764
2781
|
success: !0,
|
|
2765
2782
|
message: r("service.archive.result.restored_to", { path: d })
|
|
2766
2783
|
});
|
|
2767
|
-
} catch (
|
|
2768
|
-
const
|
|
2784
|
+
} catch (m) {
|
|
2785
|
+
const u = m.message;
|
|
2769
2786
|
await this.logger.log(
|
|
2770
2787
|
"ERROR",
|
|
2771
2788
|
{
|
|
@@ -2773,13 +2790,13 @@ class Aa {
|
|
|
2773
2790
|
args: [String(c)],
|
|
2774
2791
|
source: "u"
|
|
2775
2792
|
},
|
|
2776
|
-
r("service.archive.log.restore_failed", { id: c, message:
|
|
2793
|
+
r("service.archive.log.restore_failed", { id: c, message: u }),
|
|
2777
2794
|
{ aid: c, vid: s.vaultId }
|
|
2778
2795
|
), n.failed.push({
|
|
2779
2796
|
id: c,
|
|
2780
2797
|
input: String(c),
|
|
2781
2798
|
success: !1,
|
|
2782
|
-
message:
|
|
2799
|
+
message: u
|
|
2783
2800
|
});
|
|
2784
2801
|
}
|
|
2785
2802
|
}
|
|
@@ -2801,49 +2818,49 @@ class Aa {
|
|
|
2801
2818
|
await this.context.ensureVaultDir(i.id);
|
|
2802
2819
|
const n = await this.context.loadListEntries(), o = new Map(n.map((d) => [d.id, d])), c = /* @__PURE__ */ new Map();
|
|
2803
2820
|
for (const d of t) {
|
|
2804
|
-
const
|
|
2805
|
-
if (!
|
|
2821
|
+
const m = o.get(d);
|
|
2822
|
+
if (!m)
|
|
2806
2823
|
throw new Error(
|
|
2807
2824
|
r("service.archive.error.id_not_exists", {
|
|
2808
2825
|
id: d
|
|
2809
2826
|
})
|
|
2810
2827
|
);
|
|
2811
|
-
if (
|
|
2828
|
+
if (m.status !== y.Archived)
|
|
2812
2829
|
throw new Error(
|
|
2813
2830
|
r("service.archive.error.id_restored_cannot_move", {
|
|
2814
2831
|
id: d
|
|
2815
2832
|
})
|
|
2816
2833
|
);
|
|
2817
|
-
if (
|
|
2834
|
+
if (m.vaultId === i.id)
|
|
2818
2835
|
throw new Error(
|
|
2819
2836
|
r("service.archive.error.id_already_in_vault", {
|
|
2820
2837
|
id: d,
|
|
2821
2838
|
vault: i.name
|
|
2822
2839
|
})
|
|
2823
2840
|
);
|
|
2824
|
-
const
|
|
2825
|
-
if (!
|
|
2841
|
+
const u = await this.context.resolveArchiveStorageLocation(m), _ = this.context.archivePath(m.vaultId, m.id), k = this.context.archivePath(i.id, m.id);
|
|
2842
|
+
if (!u)
|
|
2826
2843
|
throw new Error(
|
|
2827
2844
|
r("service.archive.error.object_missing", {
|
|
2828
|
-
path:
|
|
2845
|
+
path: _
|
|
2829
2846
|
})
|
|
2830
2847
|
);
|
|
2831
|
-
if (await E(
|
|
2848
|
+
if (await E(k))
|
|
2832
2849
|
throw new Error(
|
|
2833
2850
|
r("service.archive.error.target_slot_exists", {
|
|
2834
|
-
path:
|
|
2851
|
+
path: k
|
|
2835
2852
|
})
|
|
2836
2853
|
);
|
|
2837
|
-
c.set(d,
|
|
2854
|
+
c.set(d, u);
|
|
2838
2855
|
}
|
|
2839
2856
|
const s = { ok: [], failed: [] };
|
|
2840
2857
|
let l = !1;
|
|
2841
2858
|
for (const d of t) {
|
|
2842
|
-
const
|
|
2843
|
-
if (!
|
|
2859
|
+
const m = o.get(d);
|
|
2860
|
+
if (!m)
|
|
2844
2861
|
continue;
|
|
2845
|
-
const
|
|
2846
|
-
if (!
|
|
2862
|
+
const u = c.get(d);
|
|
2863
|
+
if (!u) {
|
|
2847
2864
|
s.failed.push({
|
|
2848
2865
|
id: d,
|
|
2849
2866
|
input: String(d),
|
|
@@ -2852,9 +2869,9 @@ class Aa {
|
|
|
2852
2869
|
});
|
|
2853
2870
|
continue;
|
|
2854
2871
|
}
|
|
2855
|
-
const
|
|
2872
|
+
const _ = this.context.archivePath(i.id, m.id), k = m.vaultId;
|
|
2856
2873
|
try {
|
|
2857
|
-
await
|
|
2874
|
+
await p.rename(u.slotPath, _), m.vaultId = i.id, l = !0, await this.logger.log(
|
|
2858
2875
|
"INFO",
|
|
2859
2876
|
{
|
|
2860
2877
|
main: "move",
|
|
@@ -2864,7 +2881,7 @@ class Aa {
|
|
|
2864
2881
|
},
|
|
2865
2882
|
r("service.archive.log.moved", {
|
|
2866
2883
|
id: d,
|
|
2867
|
-
fromVaultId:
|
|
2884
|
+
fromVaultId: k,
|
|
2868
2885
|
toVaultId: i.id
|
|
2869
2886
|
}),
|
|
2870
2887
|
{ aid: d, vid: i.id }
|
|
@@ -2878,7 +2895,7 @@ class Aa {
|
|
|
2878
2895
|
})
|
|
2879
2896
|
});
|
|
2880
2897
|
} catch (x) {
|
|
2881
|
-
const
|
|
2898
|
+
const L = x.message;
|
|
2882
2899
|
await this.logger.log(
|
|
2883
2900
|
"ERROR",
|
|
2884
2901
|
{
|
|
@@ -2889,14 +2906,14 @@ class Aa {
|
|
|
2889
2906
|
},
|
|
2890
2907
|
r("service.archive.log.move_failed", {
|
|
2891
2908
|
id: d,
|
|
2892
|
-
message:
|
|
2909
|
+
message: L
|
|
2893
2910
|
}),
|
|
2894
|
-
{ aid: d, vid:
|
|
2911
|
+
{ aid: d, vid: k }
|
|
2895
2912
|
), s.failed.push({
|
|
2896
2913
|
id: d,
|
|
2897
2914
|
input: String(d),
|
|
2898
2915
|
success: !1,
|
|
2899
|
-
message:
|
|
2916
|
+
message: L
|
|
2900
2917
|
});
|
|
2901
2918
|
}
|
|
2902
2919
|
}
|
|
@@ -2913,7 +2930,7 @@ class Aa {
|
|
|
2913
2930
|
id: n
|
|
2914
2931
|
})
|
|
2915
2932
|
);
|
|
2916
|
-
if (c.status !==
|
|
2933
|
+
if (c.status !== y.Archived)
|
|
2917
2934
|
throw new Error(
|
|
2918
2935
|
r("service.archive.error.id_restored_no_slot", {
|
|
2919
2936
|
id: n
|
|
@@ -2965,7 +2982,7 @@ class Aa {
|
|
|
2965
2982
|
}
|
|
2966
2983
|
async listEntries(t) {
|
|
2967
2984
|
let i = await this.context.loadListEntries();
|
|
2968
|
-
if (t.all || (t.restored ? i = i.filter((n) => n.status ===
|
|
2985
|
+
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
2986
|
const n = await this.context.resolveVault(t.vault, {
|
|
2970
2987
|
includeRemoved: !0,
|
|
2971
2988
|
fallbackCurrent: !1
|
|
@@ -3042,17 +3059,17 @@ class Aa {
|
|
|
3042
3059
|
};
|
|
3043
3060
|
}
|
|
3044
3061
|
async preValidatePutItems(t) {
|
|
3045
|
-
const a = [], i = /* @__PURE__ */ new Set(), n = await
|
|
3062
|
+
const a = [], i = /* @__PURE__ */ new Set(), n = await Me(f.Dir.root);
|
|
3046
3063
|
for (const o of t) {
|
|
3047
|
-
const c = h.resolve(o), s = await
|
|
3064
|
+
const c = h.resolve(o), s = await ae(c);
|
|
3048
3065
|
if (!s)
|
|
3049
3066
|
throw new Error(
|
|
3050
3067
|
r("service.archive.error.path_not_exists", {
|
|
3051
3068
|
path: o
|
|
3052
3069
|
})
|
|
3053
3070
|
);
|
|
3054
|
-
const l = await
|
|
3055
|
-
if (
|
|
3071
|
+
const l = await Me(c);
|
|
3072
|
+
if (pa(l, n) || nt(n, l))
|
|
3056
3073
|
throw new Error(
|
|
3057
3074
|
r("service.archive.error.path_forbidden_archiver_scope", {
|
|
3058
3075
|
path: o
|
|
@@ -3086,24 +3103,24 @@ class Aa {
|
|
|
3086
3103
|
}
|
|
3087
3104
|
}
|
|
3088
3105
|
}
|
|
3089
|
-
class
|
|
3106
|
+
class Da {
|
|
3090
3107
|
constructor(t) {
|
|
3091
3108
|
this.context = t;
|
|
3092
3109
|
}
|
|
3093
3110
|
async log(t, a, i, n) {
|
|
3094
3111
|
const s = {
|
|
3095
3112
|
id: await this.context.nextAutoIncrement("logId"),
|
|
3096
|
-
operedAt:
|
|
3113
|
+
operedAt: _e(/* @__PURE__ */ new Date()),
|
|
3097
3114
|
level: t,
|
|
3098
3115
|
oper: a,
|
|
3099
3116
|
message: i,
|
|
3100
3117
|
...n?.aid !== void 0 ? { archiveIds: n.aid } : {},
|
|
3101
3118
|
...n?.vid !== void 0 ? { vaultIds: n.vid } : {}
|
|
3102
3119
|
};
|
|
3103
|
-
return await
|
|
3120
|
+
return await st(f.File.log, s), s;
|
|
3104
3121
|
}
|
|
3105
3122
|
}
|
|
3106
|
-
function
|
|
3123
|
+
function le(e) {
|
|
3107
3124
|
const t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
3108
3125
|
for (const i of e)
|
|
3109
3126
|
t.has(i) ? a.add(i) : t.add(i);
|
|
@@ -3112,7 +3129,7 @@ function ne(e) {
|
|
|
3112
3129
|
function I(e, t, a, i) {
|
|
3113
3130
|
e.push({ level: t, code: a, message: i });
|
|
3114
3131
|
}
|
|
3115
|
-
class
|
|
3132
|
+
class Pa {
|
|
3116
3133
|
constructor(t) {
|
|
3117
3134
|
this.context = t;
|
|
3118
3135
|
}
|
|
@@ -3135,9 +3152,9 @@ class Va {
|
|
|
3135
3152
|
}
|
|
3136
3153
|
async checkRequiredPaths(t) {
|
|
3137
3154
|
const a = [
|
|
3138
|
-
...Object.values(
|
|
3139
|
-
...Object.values(
|
|
3140
|
-
this.context.vaultDir(
|
|
3155
|
+
...Object.values(f.Dir),
|
|
3156
|
+
...Object.values(f.File),
|
|
3157
|
+
this.context.vaultDir(g.Vault.id)
|
|
3141
3158
|
];
|
|
3142
3159
|
for (const i of a)
|
|
3143
3160
|
await E(i) || I(
|
|
@@ -3160,7 +3177,7 @@ class Va {
|
|
|
3160
3177
|
);
|
|
3161
3178
|
}
|
|
3162
3179
|
checkListIds(t, a, i) {
|
|
3163
|
-
const n = a.map((s) => s.id), o =
|
|
3180
|
+
const n = a.map((s) => s.id), o = le(n);
|
|
3164
3181
|
o.length > 0 && I(
|
|
3165
3182
|
t.issues,
|
|
3166
3183
|
w.Error,
|
|
@@ -3181,7 +3198,7 @@ class Va {
|
|
|
3181
3198
|
);
|
|
3182
3199
|
}
|
|
3183
3200
|
checkVaultIds(t, a, i) {
|
|
3184
|
-
const n = a.filter((
|
|
3201
|
+
const n = a.filter((m) => m.id !== g.Vault.id), o = n.map((m) => m.id), c = le(o);
|
|
3185
3202
|
c.length > 0 && I(
|
|
3186
3203
|
t.issues,
|
|
3187
3204
|
w.Error,
|
|
@@ -3190,7 +3207,7 @@ class Va {
|
|
|
3190
3207
|
ids: c.join(", ")
|
|
3191
3208
|
})
|
|
3192
3209
|
);
|
|
3193
|
-
const s = n.map((
|
|
3210
|
+
const s = n.map((m) => m.name), l = s.filter((m, u) => s.indexOf(m) !== u);
|
|
3194
3211
|
l.length > 0 && I(
|
|
3195
3212
|
t.issues,
|
|
3196
3213
|
w.Error,
|
|
@@ -3226,7 +3243,7 @@ class Va {
|
|
|
3226
3243
|
continue;
|
|
3227
3244
|
}
|
|
3228
3245
|
const s = this.context.archivePath(o.vaultId, o.id), l = h.join(o.directory, o.item);
|
|
3229
|
-
if (o.status ===
|
|
3246
|
+
if (o.status === y.Archived) {
|
|
3230
3247
|
const d = await this.context.resolveArchiveStorageLocation(o);
|
|
3231
3248
|
if (!d)
|
|
3232
3249
|
I(
|
|
@@ -3239,17 +3256,17 @@ class Va {
|
|
|
3239
3256
|
})
|
|
3240
3257
|
);
|
|
3241
3258
|
else {
|
|
3242
|
-
const
|
|
3243
|
-
if (
|
|
3244
|
-
const
|
|
3245
|
-
|
|
3259
|
+
const m = await ae(d.objectPath);
|
|
3260
|
+
if (m) {
|
|
3261
|
+
const u = m.isDirectory(), _ = o.isDirectory === 1;
|
|
3262
|
+
u !== _ && I(
|
|
3246
3263
|
t.issues,
|
|
3247
3264
|
w.Error,
|
|
3248
3265
|
"TYPE_MISMATCH_ARCHIVED",
|
|
3249
3266
|
r("service.check.issue.type_mismatch_archived", {
|
|
3250
3267
|
archiveId: o.id,
|
|
3251
|
-
expectedIsDir:
|
|
3252
|
-
actualIsDir:
|
|
3268
|
+
expectedIsDir: _,
|
|
3269
|
+
actualIsDir: u
|
|
3253
3270
|
})
|
|
3254
3271
|
);
|
|
3255
3272
|
}
|
|
@@ -3263,7 +3280,7 @@ class Va {
|
|
|
3263
3280
|
restorePath: l
|
|
3264
3281
|
})
|
|
3265
3282
|
);
|
|
3266
|
-
} else if (o.status ===
|
|
3283
|
+
} else if (o.status === y.Restored)
|
|
3267
3284
|
if (await E(s) && I(
|
|
3268
3285
|
t.issues,
|
|
3269
3286
|
w.Warn,
|
|
@@ -3273,17 +3290,17 @@ class Va {
|
|
|
3273
3290
|
archivePath: s
|
|
3274
3291
|
})
|
|
3275
3292
|
), await E(l)) {
|
|
3276
|
-
const d = await
|
|
3293
|
+
const d = await ae(l);
|
|
3277
3294
|
if (d) {
|
|
3278
|
-
const
|
|
3279
|
-
|
|
3295
|
+
const m = d.isDirectory(), u = o.isDirectory === 1;
|
|
3296
|
+
m !== u && I(
|
|
3280
3297
|
t.issues,
|
|
3281
3298
|
w.Warn,
|
|
3282
3299
|
"TYPE_MISMATCH_RESTORED",
|
|
3283
3300
|
r("service.check.issue.type_mismatch_restored", {
|
|
3284
3301
|
archiveId: o.id,
|
|
3285
|
-
expectedIsDir:
|
|
3286
|
-
actualIsDir:
|
|
3302
|
+
expectedIsDir: u,
|
|
3303
|
+
actualIsDir: m
|
|
3287
3304
|
})
|
|
3288
3305
|
);
|
|
3289
3306
|
}
|
|
@@ -3311,8 +3328,8 @@ class Va {
|
|
|
3311
3328
|
}
|
|
3312
3329
|
async checkVaultDirectoryConsistency(t, a, i) {
|
|
3313
3330
|
const n = new Set(i.map((s) => s.id)), o = new Set(
|
|
3314
|
-
a.filter((s) => s.status ===
|
|
3315
|
-
), c = await
|
|
3331
|
+
a.filter((s) => s.status === y.Archived).map((s) => `${s.vaultId}/${s.id}`)
|
|
3332
|
+
), c = await _a(f.Dir.vaults);
|
|
3316
3333
|
for (const s of c) {
|
|
3317
3334
|
if (!/^\d+$/.test(s)) {
|
|
3318
3335
|
I(
|
|
@@ -3320,7 +3337,7 @@ class Va {
|
|
|
3320
3337
|
w.Warn,
|
|
3321
3338
|
"NON_NUMERIC_VAULT_DIR",
|
|
3322
3339
|
r("service.check.issue.non_numeric_vault_dir", {
|
|
3323
|
-
path: h.join(
|
|
3340
|
+
path: h.join(f.Dir.vaults, s)
|
|
3324
3341
|
})
|
|
3325
3342
|
);
|
|
3326
3343
|
continue;
|
|
@@ -3331,42 +3348,42 @@ class Va {
|
|
|
3331
3348
|
w.Warn,
|
|
3332
3349
|
"ORPHAN_VAULT_DIR",
|
|
3333
3350
|
r("service.check.issue.orphan_vault_dir", {
|
|
3334
|
-
path: h.join(
|
|
3351
|
+
path: h.join(f.Dir.vaults, s)
|
|
3335
3352
|
})
|
|
3336
3353
|
);
|
|
3337
|
-
const d = this.context.vaultDir(l),
|
|
3338
|
-
for (const
|
|
3339
|
-
if (!/^[0-9]+$/.test(
|
|
3354
|
+
const d = this.context.vaultDir(l), m = await p.readdir(d, { withFileTypes: !0 });
|
|
3355
|
+
for (const u of m) {
|
|
3356
|
+
if (!/^[0-9]+$/.test(u.name)) {
|
|
3340
3357
|
I(
|
|
3341
3358
|
t.issues,
|
|
3342
3359
|
w.Warn,
|
|
3343
3360
|
"NON_NUMERIC_ARCHIVE_OBJECT",
|
|
3344
3361
|
r("service.check.issue.non_numeric_archive_object", {
|
|
3345
3362
|
vaultId: l,
|
|
3346
|
-
name:
|
|
3363
|
+
name: u.name
|
|
3347
3364
|
})
|
|
3348
3365
|
);
|
|
3349
3366
|
continue;
|
|
3350
3367
|
}
|
|
3351
|
-
if (!
|
|
3368
|
+
if (!u.isDirectory()) {
|
|
3352
3369
|
I(
|
|
3353
3370
|
t.issues,
|
|
3354
3371
|
w.Error,
|
|
3355
3372
|
"INVALID_ARCHIVE_SLOT",
|
|
3356
3373
|
r("service.check.issue.invalid_archive_slot", {
|
|
3357
3374
|
vaultId: l,
|
|
3358
|
-
slotName:
|
|
3375
|
+
slotName: u.name
|
|
3359
3376
|
})
|
|
3360
3377
|
);
|
|
3361
3378
|
continue;
|
|
3362
3379
|
}
|
|
3363
|
-
const
|
|
3364
|
-
o.has(
|
|
3380
|
+
const _ = `${l}/${Number(u.name)}`;
|
|
3381
|
+
o.has(_) || I(
|
|
3365
3382
|
t.issues,
|
|
3366
3383
|
w.Warn,
|
|
3367
3384
|
"ORPHAN_ARCHIVE_OBJECT",
|
|
3368
3385
|
r("service.check.issue.orphan_archive_object", {
|
|
3369
|
-
pairKey:
|
|
3386
|
+
pairKey: _
|
|
3370
3387
|
})
|
|
3371
3388
|
);
|
|
3372
3389
|
}
|
|
@@ -3388,7 +3405,7 @@ class Va {
|
|
|
3388
3405
|
}
|
|
3389
3406
|
}
|
|
3390
3407
|
async checkLogConsistency(t, a) {
|
|
3391
|
-
const n = (await
|
|
3408
|
+
const n = (await ie(f.File.log)).map((s) => Number(s.id)).filter((s) => Number.isInteger(s)), o = le(n);
|
|
3392
3409
|
o.length > 0 && I(
|
|
3393
3410
|
t.issues,
|
|
3394
3411
|
w.Error,
|
|
@@ -3409,7 +3426,7 @@ class Va {
|
|
|
3409
3426
|
);
|
|
3410
3427
|
}
|
|
3411
3428
|
}
|
|
3412
|
-
class
|
|
3429
|
+
class Ma {
|
|
3413
3430
|
constructor(t) {
|
|
3414
3431
|
this.context = t;
|
|
3415
3432
|
}
|
|
@@ -3445,7 +3462,7 @@ class Ra {
|
|
|
3445
3462
|
a.lastUpdateCheck = t, await this.context.saveConfig(a);
|
|
3446
3463
|
}
|
|
3447
3464
|
}
|
|
3448
|
-
function
|
|
3465
|
+
function Oa(e) {
|
|
3449
3466
|
return {
|
|
3450
3467
|
id: Number(e.id),
|
|
3451
3468
|
operedAt: String(e.operedAt ?? ""),
|
|
@@ -3456,17 +3473,17 @@ function xa(e) {
|
|
|
3456
3473
|
...e.vaultIds !== void 0 ? { vaultIds: Number(e.vaultIds) } : {}
|
|
3457
3474
|
};
|
|
3458
3475
|
}
|
|
3459
|
-
function
|
|
3476
|
+
function Fa(e) {
|
|
3460
3477
|
return e.operedAt.replace(/[-:\sT]/g, "").slice(0, 6);
|
|
3461
3478
|
}
|
|
3462
|
-
class
|
|
3479
|
+
class ja {
|
|
3463
3480
|
constructor(t) {
|
|
3464
3481
|
this.context = t;
|
|
3465
3482
|
}
|
|
3466
3483
|
async getLogs(t) {
|
|
3467
3484
|
const a = await this.loadAllLogs();
|
|
3468
3485
|
return t.mode === "all" ? a : a.filter((i) => {
|
|
3469
|
-
const n =
|
|
3486
|
+
const n = Fa(i);
|
|
3470
3487
|
return !n || n.length !== 6 ? !1 : n >= t.from && n <= t.to;
|
|
3471
3488
|
});
|
|
3472
3489
|
}
|
|
@@ -3486,19 +3503,19 @@ class $a {
|
|
|
3486
3503
|
return n;
|
|
3487
3504
|
}
|
|
3488
3505
|
async loadAllLogs() {
|
|
3489
|
-
const a = (await
|
|
3506
|
+
const a = (await ie(f.File.log)).map((i) => Oa(i));
|
|
3490
3507
|
return a.sort((i, n) => i.id - n.id), a;
|
|
3491
3508
|
}
|
|
3492
3509
|
}
|
|
3493
|
-
const
|
|
3494
|
-
function
|
|
3510
|
+
const Ya = yt(It);
|
|
3511
|
+
function fe(e) {
|
|
3495
3512
|
return e.trim().replace(/^v/i, "");
|
|
3496
3513
|
}
|
|
3497
|
-
function
|
|
3498
|
-
return
|
|
3514
|
+
function qe(e) {
|
|
3515
|
+
return fe(e).split(".").map((t) => Number(t.replace(/[^0-9].*$/, ""))).map((t) => Number.isFinite(t) ? t : 0);
|
|
3499
3516
|
}
|
|
3500
|
-
function
|
|
3501
|
-
const a =
|
|
3517
|
+
function Ha(e, t) {
|
|
3518
|
+
const a = qe(e), i = qe(t), n = Math.max(a.length, i.length);
|
|
3502
3519
|
for (let o = 0; o < n; o += 1) {
|
|
3503
3520
|
const c = a[o] ?? 0, s = i[o] ?? 0;
|
|
3504
3521
|
if (s > c)
|
|
@@ -3508,22 +3525,22 @@ function Na(e, t) {
|
|
|
3508
3525
|
}
|
|
3509
3526
|
return !1;
|
|
3510
3527
|
}
|
|
3511
|
-
class
|
|
3528
|
+
class Ua {
|
|
3512
3529
|
currentVersion;
|
|
3513
3530
|
constructor(t) {
|
|
3514
|
-
this.currentVersion =
|
|
3531
|
+
this.currentVersion = fe(t);
|
|
3515
3532
|
}
|
|
3516
|
-
async checkLatest(t =
|
|
3517
|
-
const a = await this.fetchLatestRelease(t), i =
|
|
3533
|
+
async checkLatest(t = M.Repo) {
|
|
3534
|
+
const a = await this.fetchLatestRelease(t), i = fe(a.tag_name);
|
|
3518
3535
|
return {
|
|
3519
3536
|
currentVersion: this.currentVersion,
|
|
3520
3537
|
latestVersion: i,
|
|
3521
|
-
hasUpdate:
|
|
3538
|
+
hasUpdate: Ha(this.currentVersion, i),
|
|
3522
3539
|
htmlUrl: a.html_url,
|
|
3523
3540
|
publishedAt: a.published_at
|
|
3524
3541
|
};
|
|
3525
3542
|
}
|
|
3526
|
-
async installLatest(t =
|
|
3543
|
+
async installLatest(t = M.Repo) {
|
|
3527
3544
|
const i = (await this.fetchLatestRelease(t)).assets?.find((s) => /install.*\.sh$/i.test(s.name));
|
|
3528
3545
|
if (!i)
|
|
3529
3546
|
throw new Error(r("service.update.error.no_install_asset"));
|
|
@@ -3531,7 +3548,7 @@ class Da {
|
|
|
3531
3548
|
headers: {
|
|
3532
3549
|
"user-agent": "archiver-ts"
|
|
3533
3550
|
},
|
|
3534
|
-
signal: AbortSignal.timeout(
|
|
3551
|
+
signal: AbortSignal.timeout(M.Timeout)
|
|
3535
3552
|
});
|
|
3536
3553
|
if (!n.ok)
|
|
3537
3554
|
throw new Error(
|
|
@@ -3539,14 +3556,14 @@ class Da {
|
|
|
3539
3556
|
status: n.status
|
|
3540
3557
|
})
|
|
3541
3558
|
);
|
|
3542
|
-
const o = await n.text(), c = h.join(
|
|
3543
|
-
await
|
|
3559
|
+
const o = await n.text(), c = h.join(Je.tmpdir(), `archiver-update-${Date.now()}.sh`);
|
|
3560
|
+
await p.writeFile(c, o, { encoding: "utf8", mode: 493 });
|
|
3544
3561
|
try {
|
|
3545
|
-
const s = await
|
|
3562
|
+
const s = await Ya("bash", [c], { maxBuffer: 4194304 });
|
|
3546
3563
|
return [s.stdout, s.stderr].filter(Boolean).join(`
|
|
3547
3564
|
`).trim();
|
|
3548
3565
|
} finally {
|
|
3549
|
-
await
|
|
3566
|
+
await p.rm(c, { force: !0 });
|
|
3550
3567
|
}
|
|
3551
3568
|
}
|
|
3552
3569
|
async fetchLatestRelease(t) {
|
|
@@ -3555,7 +3572,7 @@ class Da {
|
|
|
3555
3572
|
accept: "application/vnd.github+json",
|
|
3556
3573
|
"user-agent": "archiver-ts"
|
|
3557
3574
|
},
|
|
3558
|
-
signal: AbortSignal.timeout(
|
|
3575
|
+
signal: AbortSignal.timeout(M.Timeout)
|
|
3559
3576
|
});
|
|
3560
3577
|
if (!i.ok)
|
|
3561
3578
|
throw new Error(
|
|
@@ -3574,10 +3591,10 @@ class Da {
|
|
|
3574
3591
|
return n;
|
|
3575
3592
|
}
|
|
3576
3593
|
}
|
|
3577
|
-
async function
|
|
3578
|
-
const e = new
|
|
3594
|
+
async function za() {
|
|
3595
|
+
const e = new $a();
|
|
3579
3596
|
await e.init();
|
|
3580
|
-
const t = new
|
|
3597
|
+
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.2", l = new Ua(s);
|
|
3581
3598
|
return {
|
|
3582
3599
|
context: e,
|
|
3583
3600
|
archiveService: i,
|
|
@@ -3590,15 +3607,16 @@ async function Pa() {
|
|
|
3590
3607
|
version: s
|
|
3591
3608
|
};
|
|
3592
3609
|
}
|
|
3593
|
-
async function
|
|
3594
|
-
if (!
|
|
3610
|
+
async function Ba(e) {
|
|
3611
|
+
if (!Ie())
|
|
3595
3612
|
return "help";
|
|
3596
3613
|
A(r("index.no_command_action.unknown"));
|
|
3597
|
-
const t = await
|
|
3614
|
+
const t = await qt({
|
|
3598
3615
|
title: r("index.no_command_action.question"),
|
|
3616
|
+
description: r("index.no_command_action.note"),
|
|
3599
3617
|
options: [
|
|
3600
|
-
{ value: "list", label: r("
|
|
3601
|
-
{ value: "help", label: r("
|
|
3618
|
+
{ value: "list", label: r("index.no_command_action.option.list") },
|
|
3619
|
+
{ value: "help", label: r("index.no_command_action.option.help") }
|
|
3602
3620
|
],
|
|
3603
3621
|
initialValue: "list",
|
|
3604
3622
|
hint: r("index.no_command_action.hint", {
|
|
@@ -3608,12 +3626,12 @@ async function Oa(e) {
|
|
|
3608
3626
|
});
|
|
3609
3627
|
return t || process.exit(130), await e.configService.setNoCommandAction(t), C(r("index.no_command_action.updated", { action: t })), t;
|
|
3610
3628
|
}
|
|
3611
|
-
async function
|
|
3612
|
-
const e = await
|
|
3613
|
-
|
|
3629
|
+
async function qa() {
|
|
3630
|
+
const e = await ve(f.File.config, g.Config);
|
|
3631
|
+
Z(e.language), ee({
|
|
3614
3632
|
style: e.style === "off" ? "off" : "on"
|
|
3615
3633
|
});
|
|
3616
|
-
const t = await
|
|
3634
|
+
const t = await Ta();
|
|
3617
3635
|
if (t.installed) {
|
|
3618
3636
|
const o = t.profilePath ? ` ${t.profilePath}` : "";
|
|
3619
3637
|
A(r("index.shell_wrapper.installed", { where: o })), t.reloadCommand && A(
|
|
@@ -3623,11 +3641,11 @@ async function Ma() {
|
|
|
3623
3641
|
);
|
|
3624
3642
|
return;
|
|
3625
3643
|
}
|
|
3626
|
-
const a = await
|
|
3627
|
-
|
|
3628
|
-
const n =
|
|
3644
|
+
const a = await za(), i = await a.configService.getConfig();
|
|
3645
|
+
Z(i.language), ee(i);
|
|
3646
|
+
const n = ya(a);
|
|
3629
3647
|
if (process.argv.length <= 2) {
|
|
3630
|
-
if ((i.noCommandAction === "unknown" ? await
|
|
3648
|
+
if ((i.noCommandAction === "unknown" ? await Ba(a) : i.noCommandAction) === "list") {
|
|
3631
3649
|
await n.parseAsync([...process.argv, "list"]);
|
|
3632
3650
|
return;
|
|
3633
3651
|
}
|
|
@@ -3636,6 +3654,6 @@ async function Ma() {
|
|
|
3636
3654
|
}
|
|
3637
3655
|
await n.parseAsync(process.argv);
|
|
3638
3656
|
}
|
|
3639
|
-
|
|
3640
|
-
|
|
3657
|
+
qa().catch((e) => {
|
|
3658
|
+
j(e.message), process.exit(1);
|
|
3641
3659
|
});
|