archiver-ts 0.4.3 → 0.4.4
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 +1164 -1110
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import ot from "node:fs";
|
|
3
|
+
import h, { join as B } from "node:path";
|
|
4
4
|
import w from "node:fs/promises";
|
|
5
|
-
import { parse as
|
|
6
|
-
import
|
|
7
|
-
import { Command as
|
|
5
|
+
import { parse as Nt, printParseErrorCode as Dt, modify as Pt, applyEdits as Mt } from "jsonc-parser";
|
|
6
|
+
import ct, { homedir as Ot } from "node:os";
|
|
7
|
+
import { Command as Ft } 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
|
|
15
|
-
const t =
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
const
|
|
9
|
+
import Se from "node:readline";
|
|
10
|
+
import jt from "node:readline/promises";
|
|
11
|
+
import { stdout as Yt, stdin as Ht } from "node:process";
|
|
12
|
+
import { execFile as qt } from "node:child_process";
|
|
13
|
+
import { promisify as Ut } from "node:util";
|
|
14
|
+
function Bt(e) {
|
|
15
|
+
const t = h.join(import.meta.dirname, e);
|
|
16
|
+
return ot.existsSync(t) ? t : h.resolve(import.meta.dirname, "..", "..", "public", e);
|
|
17
|
+
}
|
|
18
|
+
function st(e) {
|
|
19
|
+
return ot.readFileSync(Bt(e), "utf8");
|
|
20
|
+
}
|
|
21
|
+
const Ce = st("config.default.jsonc"), Ee = st("auto-incr.default.jsonc"), zt = {
|
|
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",
|
|
@@ -28,7 +28,7 @@ const ye = ot("config.default.jsonc"), be = ot("auto-incr.default.jsonc"), Bt =
|
|
|
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
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",
|
|
31
|
+
"index.no_command_action.option.list": "Interactive Archiver list (Recommended)",
|
|
32
32
|
"index.no_command_action.option.help": "Show help text",
|
|
33
33
|
"index.no_command_action.option_list": " 1) list",
|
|
34
34
|
"index.no_command_action.option_help": " 2) help",
|
|
@@ -315,7 +315,7 @@ const ye = ot("config.default.jsonc"), be = ot("auto-incr.default.jsonc"), Bt =
|
|
|
315
315
|
"terminal.status.log.warn": "WARN",
|
|
316
316
|
"terminal.status.log.error": "ERROR",
|
|
317
317
|
"terminal.status.log.fatal": "FATAL"
|
|
318
|
-
},
|
|
318
|
+
}, Wt = {
|
|
319
319
|
"app.description": "将文件和文件夹归档到 ~/.archiver,并记录审计日志",
|
|
320
320
|
"defaults.vault.remark": "默认 vault",
|
|
321
321
|
"common.action.list": "list",
|
|
@@ -325,7 +325,7 @@ const ye = ot("config.default.jsonc"), be = ot("auto-incr.default.jsonc"), Bt =
|
|
|
325
325
|
"index.no_command_action.unknown": "未配置无子命令行为。",
|
|
326
326
|
"index.no_command_action.question": "当你输入 `arv` 且不带子命令时,希望执行什么?",
|
|
327
327
|
"index.no_command_action.note": "此行为可通过 config 命令随时更改。",
|
|
328
|
-
"index.no_command_action.option.list": "
|
|
328
|
+
"index.no_command_action.option.list": "交互式归档列表(推荐)",
|
|
329
329
|
"index.no_command_action.option.help": "显示帮助文本",
|
|
330
330
|
"index.no_command_action.option_list": " 1) list",
|
|
331
331
|
"index.no_command_action.option_help": " 2) help",
|
|
@@ -612,35 +612,35 @@ const ye = ot("config.default.jsonc"), be = ot("auto-incr.default.jsonc"), Bt =
|
|
|
612
612
|
"terminal.status.log.warn": "警告",
|
|
613
613
|
"terminal.status.log.error": "错误",
|
|
614
614
|
"terminal.status.log.fatal": "致命"
|
|
615
|
-
},
|
|
616
|
-
zh:
|
|
617
|
-
en:
|
|
615
|
+
}, je = {
|
|
616
|
+
zh: Wt,
|
|
617
|
+
en: zt
|
|
618
618
|
};
|
|
619
|
-
let
|
|
620
|
-
function
|
|
619
|
+
let xe = "zh";
|
|
620
|
+
function Jt(e) {
|
|
621
621
|
return e === "en" ? "en" : "zh";
|
|
622
622
|
}
|
|
623
|
-
function
|
|
624
|
-
return
|
|
623
|
+
function me(e) {
|
|
624
|
+
return xe = Jt(e), xe;
|
|
625
625
|
}
|
|
626
|
-
function
|
|
627
|
-
return t ? e.replace(/\{([a-zA-Z0-9_]+)\}/g, (a,
|
|
628
|
-
if (!(
|
|
629
|
-
return `{${
|
|
630
|
-
const n = t[
|
|
626
|
+
function Gt(e, t) {
|
|
627
|
+
return t ? e.replace(/\{([a-zA-Z0-9_]+)\}/g, (a, r) => {
|
|
628
|
+
if (!(r in t))
|
|
629
|
+
return `{${r}}`;
|
|
630
|
+
const n = t[r];
|
|
631
631
|
return n == null ? "" : String(n);
|
|
632
632
|
}) : e;
|
|
633
633
|
}
|
|
634
|
-
function
|
|
635
|
-
const a =
|
|
636
|
-
return
|
|
634
|
+
function i(e, t) {
|
|
635
|
+
const a = je[xe][e] ?? je.zh[e] ?? e;
|
|
636
|
+
return Gt(a, t);
|
|
637
637
|
}
|
|
638
|
-
function
|
|
638
|
+
function lt(e) {
|
|
639
639
|
return e.endsWith(`
|
|
640
640
|
`) ? e : `${e}
|
|
641
641
|
`;
|
|
642
642
|
}
|
|
643
|
-
async function
|
|
643
|
+
async function Le(e) {
|
|
644
644
|
try {
|
|
645
645
|
return await w.readFile(e, "utf8");
|
|
646
646
|
} catch (t) {
|
|
@@ -649,23 +649,23 @@ async function Re(e) {
|
|
|
649
649
|
throw t;
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
|
-
function
|
|
653
|
-
const a = [],
|
|
652
|
+
function ve(e, t) {
|
|
653
|
+
const a = [], r = Nt(e, a, { allowTrailingComma: !0 });
|
|
654
654
|
if (a.length > 0) {
|
|
655
|
-
const n = a.map((o) => `${
|
|
655
|
+
const n = a.map((o) => `${Dt(o.error)}@${o.offset}`).join(", ");
|
|
656
656
|
throw new Error(
|
|
657
|
-
|
|
657
|
+
i("util.jsonc.error.parse_file", {
|
|
658
658
|
filePath: t,
|
|
659
659
|
details: n
|
|
660
660
|
})
|
|
661
661
|
);
|
|
662
662
|
}
|
|
663
|
-
return
|
|
663
|
+
return r;
|
|
664
664
|
}
|
|
665
|
-
function
|
|
665
|
+
function Kt(e, t) {
|
|
666
666
|
let a = e;
|
|
667
|
-
for (const [
|
|
668
|
-
const o =
|
|
667
|
+
for (const [r, n] of Object.entries(t)) {
|
|
668
|
+
const o = Pt(a, [r], n, {
|
|
669
669
|
isArrayInsertion: !1,
|
|
670
670
|
formattingOptions: {
|
|
671
671
|
insertSpaces: !0,
|
|
@@ -674,161 +674,161 @@ function Gt(e, t) {
|
|
|
674
674
|
`
|
|
675
675
|
}
|
|
676
676
|
});
|
|
677
|
-
a =
|
|
677
|
+
a = Mt(a, o);
|
|
678
678
|
}
|
|
679
|
-
return
|
|
679
|
+
return lt(a);
|
|
680
680
|
}
|
|
681
|
-
async function
|
|
682
|
-
const a = await
|
|
683
|
-
return !a || !a.trim() ? t :
|
|
681
|
+
async function Ae(e, t) {
|
|
682
|
+
const a = await Le(e);
|
|
683
|
+
return !a || !a.trim() ? t : ve(a, e);
|
|
684
684
|
}
|
|
685
|
-
async function
|
|
686
|
-
await
|
|
685
|
+
async function Ye(e, t) {
|
|
686
|
+
await Le(e) === void 0 && await w.writeFile(e, lt(t), "utf8");
|
|
687
687
|
}
|
|
688
|
-
async function
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
const o =
|
|
688
|
+
async function He(e, t, a) {
|
|
689
|
+
const r = await Le(e), n = r && r.trim().length > 0 ? r : a;
|
|
690
|
+
ve(n, e);
|
|
691
|
+
const o = Kt(n, t);
|
|
692
692
|
await w.writeFile(e, o, "utf8");
|
|
693
693
|
}
|
|
694
|
-
var
|
|
694
|
+
var $ = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Protected = "Protected", e))($ || {}), C = /* @__PURE__ */ ((e) => (e.Archived = "Archived", e.Restored = "Restored", e))(C || {}), y = /* @__PURE__ */ ((e) => (e.Info = "Info", e.Warn = "Warn", e.Error = "Error", e))(y || {}), f;
|
|
695
695
|
((e) => {
|
|
696
|
-
e.VaultId = 0, e.VaultName = "@", e.Config =
|
|
697
|
-
|
|
696
|
+
e.VaultId = 0, e.VaultName = "@", e.Config = ve(Ce, "default-files/config.default.jsonc"), e.AutoIncr = ve(
|
|
697
|
+
Ee,
|
|
698
698
|
"default-files/auto-incr.default.jsonc"
|
|
699
699
|
), e.Vault = {
|
|
700
700
|
id: e.VaultId,
|
|
701
701
|
name: e.VaultName,
|
|
702
702
|
remark: "Default vault",
|
|
703
703
|
createdAt: "system",
|
|
704
|
-
status:
|
|
704
|
+
status: $.Protected
|
|
705
705
|
}, e.LogTail = 15;
|
|
706
|
-
})(
|
|
707
|
-
const
|
|
706
|
+
})(f || (f = {}));
|
|
707
|
+
const Xt = () => process.env.ARCHIVER_PATH ?? B(Ot(), ".archiver"), q = Xt();
|
|
708
708
|
var _;
|
|
709
709
|
((e) => {
|
|
710
710
|
e.Dir = {
|
|
711
|
-
root:
|
|
712
|
-
vaults:
|
|
711
|
+
root: q,
|
|
712
|
+
vaults: B(q, "vaults")
|
|
713
713
|
}, e.File = {
|
|
714
|
-
config:
|
|
715
|
-
autoIncr:
|
|
716
|
-
list:
|
|
717
|
-
vaults:
|
|
718
|
-
log:
|
|
714
|
+
config: B(q, "config.jsonc"),
|
|
715
|
+
autoIncr: B(q, "auto-incr.jsonc"),
|
|
716
|
+
list: B(q, "list.jsonl"),
|
|
717
|
+
vaults: B(q, "vaults.jsonl"),
|
|
718
|
+
log: B(q, "log.jsonl")
|
|
719
719
|
};
|
|
720
720
|
})(_ || (_ = {}));
|
|
721
|
-
var
|
|
721
|
+
var W;
|
|
722
722
|
((e) => {
|
|
723
723
|
e.CheckInterval = 1440 * 60 * 1e3, e.Repo = process.env.ARCHIVER_GITHUB_REPO ?? "aldia/archiver", e.Timeout = 1e4;
|
|
724
|
-
})(
|
|
725
|
-
const
|
|
726
|
-
function
|
|
727
|
-
const t = e.getFullYear(), a =
|
|
728
|
-
return `${t}-${a}-${
|
|
724
|
+
})(W || (W = {}));
|
|
725
|
+
const Qt = "archiver", te = (e) => e.toString().padStart(2, "0"), Zt = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
726
|
+
function $e(e = /* @__PURE__ */ new Date()) {
|
|
727
|
+
const t = e.getFullYear(), a = te(e.getMonth() + 1), r = te(e.getDate()), n = te(e.getHours()), o = te(e.getMinutes()), s = te(e.getSeconds());
|
|
728
|
+
return `${t}-${a}-${r} ${n}:${o}:${s}`;
|
|
729
729
|
}
|
|
730
|
-
function
|
|
730
|
+
function Ie(e) {
|
|
731
731
|
if (!/^\d{6}$/.test(e))
|
|
732
732
|
return;
|
|
733
733
|
const t = Number(e.slice(0, 4)), a = Number(e.slice(4, 6));
|
|
734
734
|
if (!(a < 1 || a > 12))
|
|
735
735
|
return { year: t, month: a };
|
|
736
736
|
}
|
|
737
|
-
function
|
|
737
|
+
function qe(e) {
|
|
738
738
|
if (e.length === 0)
|
|
739
|
-
throw new Error(
|
|
740
|
-
const t = e.map((
|
|
741
|
-
if (!/^\d+$/.test(
|
|
742
|
-
throw new Error(
|
|
743
|
-
return Number(
|
|
739
|
+
throw new Error(i("util.parse.error.at_least_one_id"));
|
|
740
|
+
const t = e.map((r) => {
|
|
741
|
+
if (!/^\d+$/.test(r))
|
|
742
|
+
throw new Error(i("util.parse.error.invalid_id", { id: r }));
|
|
743
|
+
return Number(r);
|
|
744
744
|
});
|
|
745
745
|
if (new Set(t).size !== t.length)
|
|
746
|
-
throw new Error(
|
|
746
|
+
throw new Error(i("util.parse.error.duplicate_ids"));
|
|
747
747
|
return t;
|
|
748
748
|
}
|
|
749
|
-
function
|
|
749
|
+
function ea(e) {
|
|
750
750
|
if (!e)
|
|
751
751
|
return { mode: "all" };
|
|
752
752
|
if (["all", "*", "a"].includes(e.toLowerCase()))
|
|
753
753
|
return { mode: "all" };
|
|
754
754
|
if (/^\d{6}$/.test(e)) {
|
|
755
|
-
if (!
|
|
756
|
-
throw new Error(
|
|
755
|
+
if (!Ie(e))
|
|
756
|
+
throw new Error(i("util.parse.error.invalid_month_range", { range: e }));
|
|
757
757
|
return { mode: "month", from: e, to: e };
|
|
758
758
|
}
|
|
759
759
|
const t = e.split("-");
|
|
760
760
|
if (t.length === 2 && /^\d{6}$/.test(t[0]) && /^\d{6}$/.test(t[1])) {
|
|
761
|
-
const a =
|
|
762
|
-
if (!a || !
|
|
763
|
-
throw new Error(
|
|
761
|
+
const a = Ie(t[0]), r = Ie(t[1]);
|
|
762
|
+
if (!a || !r)
|
|
763
|
+
throw new Error(i("util.parse.error.invalid_range", { range: e }));
|
|
764
764
|
if (t[0] > t[1])
|
|
765
|
-
throw new Error(
|
|
765
|
+
throw new Error(i("util.parse.error.invalid_range_order", { range: e }));
|
|
766
766
|
return { mode: "month", from: t[0], to: t[1] };
|
|
767
767
|
}
|
|
768
|
-
throw new Error(
|
|
768
|
+
throw new Error(i("util.parse.error.invalid_range_format", { range: e }));
|
|
769
769
|
}
|
|
770
|
-
function
|
|
770
|
+
function _e(e, t) {
|
|
771
771
|
return t === "green" ? v.black.bgGreen(` ${e} `) : t === "cyan" ? v.black.bgCyan(` ${e} `) : t === "yellow" ? v.black.bgYellow(` ${e} `) : v.white.bgRed(` ${e} `);
|
|
772
772
|
}
|
|
773
|
-
function
|
|
774
|
-
console.log(`${
|
|
773
|
+
function T(e) {
|
|
774
|
+
console.log(`${_e(i("terminal.badge.ok"), "green")} ${v.green(e)}`);
|
|
775
775
|
}
|
|
776
|
-
function
|
|
777
|
-
console.log(`${
|
|
776
|
+
function A(e) {
|
|
777
|
+
console.log(`${_e(i("terminal.badge.info"), "cyan")} ${v.cyan(e)}`);
|
|
778
778
|
}
|
|
779
|
-
function
|
|
780
|
-
console.log(`${
|
|
779
|
+
function ye(e) {
|
|
780
|
+
console.log(`${_e(i("terminal.badge.warn"), "yellow")} ${v.yellow(e)}`);
|
|
781
781
|
}
|
|
782
|
-
function
|
|
783
|
-
console.error(`${
|
|
782
|
+
function K(e) {
|
|
783
|
+
console.error(`${_e(i("terminal.badge.error"), "red")} ${v.red(e)}`);
|
|
784
784
|
}
|
|
785
|
-
function
|
|
786
|
-
return Array.from({ length: t }, (a,
|
|
785
|
+
function ta(e, t) {
|
|
786
|
+
return Array.from({ length: t }, (a, r) => e[r] ?? "");
|
|
787
787
|
}
|
|
788
|
-
function
|
|
788
|
+
function oe(e, t) {
|
|
789
789
|
if (e.length === 0)
|
|
790
790
|
return "";
|
|
791
|
-
const a = e.length,
|
|
792
|
-
|
|
791
|
+
const a = e.length, r = [];
|
|
792
|
+
r.push(v.bold(e.join(" "))), r.push(v.dim(e.map((n) => "-".repeat(Math.max(n.length, 3))).join(" ")));
|
|
793
793
|
for (const n of t)
|
|
794
|
-
|
|
795
|
-
return
|
|
794
|
+
r.push(ta(n, a).join(" "));
|
|
795
|
+
return r.join(`
|
|
796
796
|
`);
|
|
797
797
|
}
|
|
798
|
-
function
|
|
798
|
+
function dt(e) {
|
|
799
799
|
const t = e.toLowerCase();
|
|
800
|
-
return e === "A" || t === "archived" ? e === "A" ? v.green(e) : v.green(
|
|
800
|
+
return e === "A" || t === "archived" ? e === "A" ? v.green(e) : v.green(i("terminal.status.archive.archived")) : e === "R" || t === "restored" ? e === "R" ? v.gray(e) : v.gray(i("terminal.status.archive.restored")) : e;
|
|
801
801
|
}
|
|
802
|
-
function
|
|
803
|
-
return e === "Valid" ? v.green(
|
|
802
|
+
function aa(e) {
|
|
803
|
+
return e === "Valid" ? v.green(i("terminal.status.vault.valid")) : e === "Removed" ? v.yellow(i("terminal.status.vault.removed")) : e === "Protected" ? v.cyan(i("terminal.status.vault.protected")) : e;
|
|
804
804
|
}
|
|
805
|
-
function
|
|
806
|
-
return e === "ERROR" || e === "FATAL" ? v.red(
|
|
805
|
+
function Ue(e) {
|
|
806
|
+
return e === "ERROR" || e === "FATAL" ? v.red(i(e === "ERROR" ? "terminal.status.log.error" : "terminal.status.log.fatal")) : e === "WARN" ? v.yellow(i("terminal.status.log.warn")) : e === "INFO" ? v.cyan(i("terminal.status.log.info")) : e;
|
|
807
807
|
}
|
|
808
|
-
function
|
|
809
|
-
return e === "put" ?
|
|
808
|
+
function ra(e) {
|
|
809
|
+
return e === "put" ? i("command.batch.operation.put") : e === "restore" ? i("command.batch.operation.restore") : e === "move" ? i("command.batch.operation.move") : e;
|
|
810
810
|
}
|
|
811
|
-
function
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
operation:
|
|
811
|
+
function le(e, t) {
|
|
812
|
+
A(
|
|
813
|
+
i("command.batch.summary", {
|
|
814
|
+
operation: ra(e),
|
|
815
815
|
ok: t.ok.length,
|
|
816
816
|
failed: t.failed.length
|
|
817
817
|
})
|
|
818
818
|
);
|
|
819
819
|
}
|
|
820
|
-
async function
|
|
820
|
+
async function O(e) {
|
|
821
821
|
const t = await e.configService.getConfig();
|
|
822
822
|
if (t.updateCheck === "on") {
|
|
823
823
|
if (t.lastUpdateCheck) {
|
|
824
824
|
const a = new Date(t.lastUpdateCheck);
|
|
825
|
-
if (!Number.isNaN(a.getTime()) && Date.now() - a.getTime() <
|
|
825
|
+
if (!Number.isNaN(a.getTime()) && Date.now() - a.getTime() < W.CheckInterval)
|
|
826
826
|
return;
|
|
827
827
|
}
|
|
828
828
|
try {
|
|
829
829
|
const a = await e.updateService.checkLatest();
|
|
830
|
-
await e.configService.updateLastCheck(
|
|
831
|
-
|
|
830
|
+
await e.configService.updateLastCheck(Zt()), a.hasUpdate && A(
|
|
831
|
+
i("command.auto_update.new_available", {
|
|
832
832
|
latestVersion: a.latestVersion,
|
|
833
833
|
currentVersion: a.currentVersion
|
|
834
834
|
})
|
|
@@ -837,104 +837,104 @@ async function N(e) {
|
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
839
|
}
|
|
840
|
-
async function
|
|
840
|
+
async function P(e) {
|
|
841
841
|
try {
|
|
842
842
|
await e();
|
|
843
843
|
} catch (t) {
|
|
844
|
-
|
|
844
|
+
K(t.message), process.exitCode = 1;
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
847
|
function ia(e, t) {
|
|
848
|
-
e.command("put").description(
|
|
849
|
-
(a,
|
|
850
|
-
const n = await t.archiveService.put(a,
|
|
848
|
+
e.command("put").description(i("command.archive.put.description")).argument("<items...>", i("command.archive.put.argument.items")).option("-v, --vault <vault>", i("command.archive.put.option.vault")).option("-m, --message <message>", i("command.archive.put.option.message")).option("-r, --remark <remark>", i("command.archive.put.option.remark")).action(
|
|
849
|
+
(a, r) => P(async () => {
|
|
850
|
+
const n = await t.archiveService.put(a, r);
|
|
851
851
|
for (const o of n.ok)
|
|
852
|
-
|
|
853
|
-
|
|
852
|
+
T(
|
|
853
|
+
i("command.archive.result.put.ok", {
|
|
854
854
|
id: o.id,
|
|
855
855
|
input: o.input,
|
|
856
856
|
message: o.message
|
|
857
857
|
})
|
|
858
858
|
);
|
|
859
859
|
for (const o of n.failed)
|
|
860
|
-
|
|
861
|
-
|
|
860
|
+
K(
|
|
861
|
+
i("command.archive.result.put.failed", {
|
|
862
862
|
id: o.id ?? "-",
|
|
863
863
|
input: o.input,
|
|
864
864
|
message: o.message
|
|
865
865
|
})
|
|
866
866
|
);
|
|
867
|
-
|
|
867
|
+
le("put", n), await O(t);
|
|
868
868
|
})
|
|
869
|
-
), e.command("restore").description(
|
|
870
|
-
(a) =>
|
|
871
|
-
const
|
|
869
|
+
), e.command("restore").description(i("command.archive.restore.description")).argument("<ids...>", i("command.archive.restore.argument.ids")).action(
|
|
870
|
+
(a) => P(async () => {
|
|
871
|
+
const r = qe(a), n = await t.archiveService.restore(r);
|
|
872
872
|
for (const o of n.ok)
|
|
873
|
-
|
|
874
|
-
|
|
873
|
+
T(
|
|
874
|
+
i("command.archive.result.restore.ok", {
|
|
875
875
|
id: o.id,
|
|
876
876
|
message: o.message
|
|
877
877
|
})
|
|
878
878
|
);
|
|
879
879
|
for (const o of n.failed)
|
|
880
|
-
|
|
881
|
-
|
|
880
|
+
K(
|
|
881
|
+
i("command.archive.result.restore.failed", {
|
|
882
882
|
id: o.id ?? "-",
|
|
883
883
|
message: o.message
|
|
884
884
|
})
|
|
885
885
|
);
|
|
886
|
-
|
|
886
|
+
le("restore", n), await O(t);
|
|
887
887
|
})
|
|
888
|
-
), e.command("move").description(
|
|
889
|
-
(a,
|
|
890
|
-
const n =
|
|
888
|
+
), e.command("move").description(i("command.archive.move.description")).argument("<ids...>", i("command.archive.move.argument.ids")).requiredOption("--to <vault>", i("command.archive.move.option.to")).action(
|
|
889
|
+
(a, r) => P(async () => {
|
|
890
|
+
const n = qe(a), o = await t.archiveService.move(n, r.to);
|
|
891
891
|
for (const s of o.ok)
|
|
892
|
-
|
|
893
|
-
|
|
892
|
+
T(
|
|
893
|
+
i("command.archive.result.move.ok", {
|
|
894
894
|
id: s.id,
|
|
895
895
|
message: s.message
|
|
896
896
|
})
|
|
897
897
|
);
|
|
898
898
|
for (const s of o.failed)
|
|
899
|
-
|
|
900
|
-
|
|
899
|
+
K(
|
|
900
|
+
i("command.archive.result.move.failed", {
|
|
901
901
|
id: s.id ?? "-",
|
|
902
902
|
message: s.message
|
|
903
903
|
})
|
|
904
904
|
);
|
|
905
|
-
|
|
905
|
+
le("move", o), await O(t);
|
|
906
906
|
})
|
|
907
907
|
);
|
|
908
908
|
}
|
|
909
|
-
const
|
|
910
|
-
function
|
|
909
|
+
const na = v.level;
|
|
910
|
+
function oa(e) {
|
|
911
911
|
if (typeof e != "string")
|
|
912
912
|
return;
|
|
913
913
|
const t = e.trim().toLowerCase();
|
|
914
914
|
if (t === "on" || t === "off")
|
|
915
915
|
return t;
|
|
916
916
|
}
|
|
917
|
-
function
|
|
918
|
-
return
|
|
917
|
+
function ca(e, t = process.env) {
|
|
918
|
+
return oa(t.ARCHIVER_STYLE) ?? e;
|
|
919
919
|
}
|
|
920
|
-
function
|
|
920
|
+
function sa(e) {
|
|
921
921
|
if (e === "off") {
|
|
922
922
|
v.level = 0;
|
|
923
923
|
return;
|
|
924
924
|
}
|
|
925
|
-
v.level = Math.max(
|
|
925
|
+
v.level = Math.max(na, 1);
|
|
926
926
|
}
|
|
927
|
-
function
|
|
928
|
-
const a =
|
|
929
|
-
return
|
|
927
|
+
function he(e, t = process.env) {
|
|
928
|
+
const a = ca(e.style, t);
|
|
929
|
+
return sa(a), a;
|
|
930
930
|
}
|
|
931
|
-
function
|
|
931
|
+
function ut(e, t) {
|
|
932
932
|
return e < 0 ? 0 : e > t.length ? t.length : e;
|
|
933
933
|
}
|
|
934
|
-
function
|
|
935
|
-
return { value: e, cursor:
|
|
934
|
+
function z(e, t) {
|
|
935
|
+
return { value: e, cursor: ut(t, e) };
|
|
936
936
|
}
|
|
937
|
-
function
|
|
937
|
+
function la(e) {
|
|
938
938
|
if (!e)
|
|
939
939
|
return !1;
|
|
940
940
|
for (const t of e) {
|
|
@@ -944,13 +944,13 @@ function sa(e) {
|
|
|
944
944
|
}
|
|
945
945
|
return !0;
|
|
946
946
|
}
|
|
947
|
-
function
|
|
947
|
+
function mt(e = "") {
|
|
948
948
|
return { value: e, cursor: e.length };
|
|
949
949
|
}
|
|
950
|
-
function
|
|
951
|
-
return t === "left" ?
|
|
950
|
+
function Be(e, t) {
|
|
951
|
+
return t === "left" ? z(e.value, e.cursor - 1) : z(e.value, e.cursor + 1);
|
|
952
952
|
}
|
|
953
|
-
function
|
|
953
|
+
function fe(e, t, a) {
|
|
954
954
|
if (a.ctrl && a.name === "c")
|
|
955
955
|
return { state: e, action: "cancel" };
|
|
956
956
|
if (a.name === "escape")
|
|
@@ -958,129 +958,129 @@ function me(e, t, a) {
|
|
|
958
958
|
if (a.name === "return" || a.name === "enter")
|
|
959
959
|
return { state: e, action: "submit" };
|
|
960
960
|
if (a.name === "left")
|
|
961
|
-
return { state:
|
|
961
|
+
return { state: Be(e, "left"), action: "continue" };
|
|
962
962
|
if (a.name === "right")
|
|
963
|
-
return { state:
|
|
963
|
+
return { state: Be(e, "right"), action: "continue" };
|
|
964
964
|
if (a.name === "home")
|
|
965
|
-
return { state:
|
|
965
|
+
return { state: z(e.value, 0), action: "continue" };
|
|
966
966
|
if (a.name === "end")
|
|
967
|
-
return { state:
|
|
967
|
+
return { state: z(e.value, e.value.length), action: "continue" };
|
|
968
968
|
if (a.name === "backspace") {
|
|
969
969
|
if (e.cursor === 0)
|
|
970
970
|
return { state: e, action: "continue" };
|
|
971
971
|
const n = `${e.value.slice(0, e.cursor - 1)}${e.value.slice(e.cursor)}`;
|
|
972
|
-
return { state:
|
|
972
|
+
return { state: z(n, e.cursor - 1), action: "continue" };
|
|
973
973
|
}
|
|
974
974
|
if (a.name === "delete") {
|
|
975
975
|
if (e.cursor >= e.value.length)
|
|
976
976
|
return { state: e, action: "continue" };
|
|
977
977
|
const n = `${e.value.slice(0, e.cursor)}${e.value.slice(e.cursor + 1)}`;
|
|
978
|
-
return { state:
|
|
978
|
+
return { state: z(n, e.cursor), action: "continue" };
|
|
979
979
|
}
|
|
980
|
-
if (!
|
|
980
|
+
if (!la(t))
|
|
981
981
|
return { state: e, action: "continue" };
|
|
982
|
-
const
|
|
983
|
-
return { state:
|
|
982
|
+
const r = `${e.value.slice(0, e.cursor)}${t}${e.value.slice(e.cursor)}`;
|
|
983
|
+
return { state: z(r, e.cursor + t.length), action: "continue" };
|
|
984
984
|
}
|
|
985
|
-
function
|
|
985
|
+
function vt(e, t = !0, a = "") {
|
|
986
986
|
if (!t) {
|
|
987
987
|
const c = e.value || a;
|
|
988
988
|
return v.dim(`[${c}]`);
|
|
989
989
|
}
|
|
990
990
|
if (!e.value)
|
|
991
991
|
return a ? `[${v.dim(a)}]` : `[${v.inverse(" ")}]`;
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
992
|
+
const r = ut(e.cursor, e.value);
|
|
993
|
+
if (r >= e.value.length)
|
|
994
994
|
return `[${e.value}${v.inverse(" ")}]`;
|
|
995
|
-
const n = e.value.slice(0,
|
|
995
|
+
const n = e.value.slice(0, r), o = e.value.slice(r, r + 1), s = e.value.slice(r + 1);
|
|
996
996
|
return `[${n}${v.inverse(o)}${s}]`;
|
|
997
997
|
}
|
|
998
|
-
function
|
|
998
|
+
function da(e) {
|
|
999
999
|
return typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : 24;
|
|
1000
1000
|
}
|
|
1001
|
-
function
|
|
1002
|
-
const t = e.contentLines.length > 0 ? e.contentLines : [""], a = e.footerLines ?? [],
|
|
1001
|
+
function ua(e) {
|
|
1002
|
+
const t = e.contentLines.length > 0 ? e.contentLines : [""], a = e.footerLines ?? [], r = da(e.rows), n = Math.max(r - t.length - a.length, 0);
|
|
1003
1003
|
return [...t, ...Array.from({ length: n }, () => ""), ...a];
|
|
1004
1004
|
}
|
|
1005
|
-
function
|
|
1006
|
-
return
|
|
1005
|
+
function Te(e) {
|
|
1006
|
+
return ua({
|
|
1007
1007
|
contentLines: e.contentLines,
|
|
1008
1008
|
footerLines: [e.hintLine ?? "", e.statusLine ?? ""],
|
|
1009
1009
|
rows: e.rows
|
|
1010
1010
|
});
|
|
1011
1011
|
}
|
|
1012
|
-
function
|
|
1013
|
-
const t = e.stdinIsTTY ?? !!process.stdin.isTTY, a = e.stdoutIsTTY ?? !!process.stdout.isTTY,
|
|
1014
|
-
return t && n && (a ||
|
|
1012
|
+
function Ne(e = {}) {
|
|
1013
|
+
const t = e.stdinIsTTY ?? !!process.stdin.isTTY, a = e.stdoutIsTTY ?? !!process.stdout.isTTY, r = e.forceInteractive ?? process.env.ARCHIVER_FORCE_INTERACTIVE === "1", n = e.hasRawMode ?? typeof process.stdin.setRawMode == "function";
|
|
1014
|
+
return t && n && (a || r);
|
|
1015
1015
|
}
|
|
1016
|
-
function
|
|
1016
|
+
function ma(e) {
|
|
1017
1017
|
const t = e.codePointAt(0);
|
|
1018
1018
|
return t === void 0 || t <= 31 || t >= 127 && t <= 160 ? 0 : t >= 4352 && (t <= 4447 || t === 9001 || t === 9002 || t >= 11904 && t <= 42191 && t !== 12351 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65135 || t >= 65280 && t <= 65376 || t >= 65504 && t <= 65510 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141) ? 2 : 1;
|
|
1019
1019
|
}
|
|
1020
|
-
function
|
|
1020
|
+
function X(e) {
|
|
1021
1021
|
let t = 0;
|
|
1022
1022
|
for (const a of e)
|
|
1023
|
-
t +=
|
|
1023
|
+
t += ma(a);
|
|
1024
1024
|
return t;
|
|
1025
1025
|
}
|
|
1026
|
-
function
|
|
1027
|
-
const a =
|
|
1028
|
-
return `${e}${" ".repeat(
|
|
1026
|
+
function De(e, t) {
|
|
1027
|
+
const a = X(e), r = Math.max(t - a, 0);
|
|
1028
|
+
return `${e}${" ".repeat(r)}`;
|
|
1029
1029
|
}
|
|
1030
|
-
function
|
|
1030
|
+
function ht(e, t, a) {
|
|
1031
1031
|
if (e.length === 0)
|
|
1032
1032
|
return;
|
|
1033
|
-
const
|
|
1033
|
+
const r = a === "left" ? -1 : 1;
|
|
1034
1034
|
for (let n = 1; n <= e.length; n += 1) {
|
|
1035
|
-
const o = (t +
|
|
1035
|
+
const o = (t + r * n + e.length) % e.length;
|
|
1036
1036
|
if (!e[o]?.disabled)
|
|
1037
1037
|
return o;
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1040
|
+
function F(e, t) {
|
|
1041
1041
|
if (e.length === 0)
|
|
1042
1042
|
return { options: e, selectedIndex: 0 };
|
|
1043
|
-
let a = t === void 0 ? 0 : e.findIndex((
|
|
1043
|
+
let a = t === void 0 ? 0 : e.findIndex((r) => Object.is(r.value, t));
|
|
1044
1044
|
if (a < 0 && (a = 0), e[a]?.disabled) {
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1045
|
+
const r = ht(e, a, "right");
|
|
1046
|
+
r !== void 0 && (a = r);
|
|
1047
1047
|
}
|
|
1048
1048
|
return { options: e, selectedIndex: a };
|
|
1049
1049
|
}
|
|
1050
|
-
function
|
|
1051
|
-
const a =
|
|
1050
|
+
function J(e, t) {
|
|
1051
|
+
const a = ht(e.options, e.selectedIndex, t);
|
|
1052
1052
|
return a === void 0 ? e : { ...e, selectedIndex: a };
|
|
1053
1053
|
}
|
|
1054
|
-
function
|
|
1054
|
+
function Y(e) {
|
|
1055
1055
|
return e.options[e.selectedIndex];
|
|
1056
1056
|
}
|
|
1057
|
-
function
|
|
1058
|
-
return Math.max(...e.map((t) =>
|
|
1057
|
+
function va(e) {
|
|
1058
|
+
return Math.max(...e.map((t) => X(t.label)), 1);
|
|
1059
1059
|
}
|
|
1060
|
-
function
|
|
1061
|
-
const o = `${e.disabled ? "x" : t ? ">" : " "} ${
|
|
1060
|
+
function ha(e, t, a, r) {
|
|
1061
|
+
const o = `${e.disabled ? "x" : t ? ">" : " "} ${De(e.label, r)}`;
|
|
1062
1062
|
return e.disabled ? v.dim(`[${o}]`) : t && a ? v.black.bgGreen(`[${o}]`) : t ? v.green(`[${o}]`) : a ? v.green(`[${o}]`) : v.dim(`[${o}]`);
|
|
1063
1063
|
}
|
|
1064
|
-
function
|
|
1065
|
-
const a =
|
|
1066
|
-
return e.options.map((
|
|
1064
|
+
function Q(e, t = !0) {
|
|
1065
|
+
const a = va(e.options);
|
|
1066
|
+
return e.options.map((r, n) => ha(r, n === e.selectedIndex, t, a)).join(" ");
|
|
1067
1067
|
}
|
|
1068
|
-
function
|
|
1068
|
+
function N(e) {
|
|
1069
1069
|
return v.black.bgWhite(` ${e} `);
|
|
1070
1070
|
}
|
|
1071
|
-
async function
|
|
1072
|
-
const t =
|
|
1071
|
+
async function fa(e) {
|
|
1072
|
+
const t = F(e.options, e.initialValue);
|
|
1073
1073
|
if (e.options.length === 0)
|
|
1074
1074
|
return null;
|
|
1075
|
-
if (!
|
|
1076
|
-
return
|
|
1075
|
+
if (!Ne())
|
|
1076
|
+
return Y(t)?.value ?? null;
|
|
1077
1077
|
const a = process.stdin;
|
|
1078
|
-
let
|
|
1079
|
-
return
|
|
1078
|
+
let r = t;
|
|
1079
|
+
return Se.emitKeypressEvents(a), a.setRawMode(!0), a.resume(), new Promise((n) => {
|
|
1080
1080
|
const o = () => {
|
|
1081
1081
|
const l = [e.title];
|
|
1082
|
-
e.description && l.push(v.dim(e.description)), l.push("",
|
|
1083
|
-
const d =
|
|
1082
|
+
e.description && l.push(v.dim(e.description)), l.push("", Q(r));
|
|
1083
|
+
const d = Te({
|
|
1084
1084
|
contentLines: l,
|
|
1085
1085
|
hintLine: e.hint,
|
|
1086
1086
|
statusLine: "",
|
|
@@ -1097,15 +1097,15 @@ async function ha(e) {
|
|
|
1097
1097
|
return;
|
|
1098
1098
|
}
|
|
1099
1099
|
if (d.name === "left") {
|
|
1100
|
-
|
|
1100
|
+
r = J(r, "left"), o();
|
|
1101
1101
|
return;
|
|
1102
1102
|
}
|
|
1103
1103
|
if (d.name === "right") {
|
|
1104
|
-
|
|
1104
|
+
r = J(r, "right"), o();
|
|
1105
1105
|
return;
|
|
1106
1106
|
}
|
|
1107
1107
|
if (d.name === "return" || d.name === "enter") {
|
|
1108
|
-
const m =
|
|
1108
|
+
const m = Y(r);
|
|
1109
1109
|
if (!m || m.disabled)
|
|
1110
1110
|
return;
|
|
1111
1111
|
s(m.value);
|
|
@@ -1114,8 +1114,8 @@ async function ha(e) {
|
|
|
1114
1114
|
a.on("keypress", c), o();
|
|
1115
1115
|
});
|
|
1116
1116
|
}
|
|
1117
|
-
const
|
|
1118
|
-
function
|
|
1117
|
+
const ga = ["updateCheck", "vaultItemSeparator", "style", "language", "noCommandAction"];
|
|
1118
|
+
function pa(e) {
|
|
1119
1119
|
return {
|
|
1120
1120
|
updateCheck: e.updateCheck,
|
|
1121
1121
|
vaultItemSeparator: e.vaultItemSeparator,
|
|
@@ -1124,26 +1124,26 @@ function ga(e) {
|
|
|
1124
1124
|
noCommandAction: e.noCommandAction
|
|
1125
1125
|
};
|
|
1126
1126
|
}
|
|
1127
|
-
function
|
|
1128
|
-
return
|
|
1127
|
+
function ft(e, t) {
|
|
1128
|
+
return ga.every((a) => e[a] === t[a]);
|
|
1129
1129
|
}
|
|
1130
|
-
function
|
|
1130
|
+
function _a(e) {
|
|
1131
1131
|
if (!e.vaultItemSeparator.trim())
|
|
1132
1132
|
return "command.config.error.vault_item_sep_empty";
|
|
1133
1133
|
}
|
|
1134
|
-
function
|
|
1134
|
+
function wa() {
|
|
1135
1135
|
return typeof process.stdin.setRawMode == "function";
|
|
1136
1136
|
}
|
|
1137
|
-
function
|
|
1137
|
+
function Ia(e) {
|
|
1138
1138
|
return [
|
|
1139
1139
|
{
|
|
1140
1140
|
kind: "select",
|
|
1141
1141
|
key: "updateCheck",
|
|
1142
|
-
label:
|
|
1143
|
-
state:
|
|
1142
|
+
label: i("command.config.field.update_check"),
|
|
1143
|
+
state: F(
|
|
1144
1144
|
[
|
|
1145
|
-
{ value: "on", label:
|
|
1146
|
-
{ value: "off", label:
|
|
1145
|
+
{ value: "on", label: i("common.state.on") },
|
|
1146
|
+
{ value: "off", label: i("common.state.off") }
|
|
1147
1147
|
],
|
|
1148
1148
|
e.updateCheck
|
|
1149
1149
|
)
|
|
@@ -1151,17 +1151,17 @@ function wa(e) {
|
|
|
1151
1151
|
{
|
|
1152
1152
|
kind: "input",
|
|
1153
1153
|
key: "vaultItemSeparator",
|
|
1154
|
-
label:
|
|
1155
|
-
state:
|
|
1154
|
+
label: i("command.config.field.vault_item_sep"),
|
|
1155
|
+
state: mt(e.vaultItemSeparator)
|
|
1156
1156
|
},
|
|
1157
1157
|
{
|
|
1158
1158
|
kind: "select",
|
|
1159
1159
|
key: "style",
|
|
1160
|
-
label:
|
|
1161
|
-
state:
|
|
1160
|
+
label: i("command.config.field.style"),
|
|
1161
|
+
state: F(
|
|
1162
1162
|
[
|
|
1163
|
-
{ value: "on", label:
|
|
1164
|
-
{ value: "off", label:
|
|
1163
|
+
{ value: "on", label: i("common.state.on") },
|
|
1164
|
+
{ value: "off", label: i("common.state.off") }
|
|
1165
1165
|
],
|
|
1166
1166
|
e.style
|
|
1167
1167
|
)
|
|
@@ -1169,8 +1169,8 @@ function wa(e) {
|
|
|
1169
1169
|
{
|
|
1170
1170
|
kind: "select",
|
|
1171
1171
|
key: "language",
|
|
1172
|
-
label:
|
|
1173
|
-
state:
|
|
1172
|
+
label: i("command.config.field.language"),
|
|
1173
|
+
state: F(
|
|
1174
1174
|
[
|
|
1175
1175
|
{ value: "zh", label: "zh" },
|
|
1176
1176
|
{ value: "en", label: "en" }
|
|
@@ -1181,11 +1181,11 @@ function wa(e) {
|
|
|
1181
1181
|
{
|
|
1182
1182
|
kind: "select",
|
|
1183
1183
|
key: "noCommandAction",
|
|
1184
|
-
label:
|
|
1185
|
-
state:
|
|
1184
|
+
label: i("command.config.field.no_command_action"),
|
|
1185
|
+
state: F(
|
|
1186
1186
|
[
|
|
1187
|
-
{ value: "list", label:
|
|
1188
|
-
{ value: "help", label:
|
|
1187
|
+
{ value: "list", label: i("common.action.list") },
|
|
1188
|
+
{ value: "help", label: i("common.action.help") },
|
|
1189
1189
|
{ value: "unknown", label: "unknown" }
|
|
1190
1190
|
],
|
|
1191
1191
|
e.noCommandAction
|
|
@@ -1193,27 +1193,27 @@ function wa(e) {
|
|
|
1193
1193
|
}
|
|
1194
1194
|
];
|
|
1195
1195
|
}
|
|
1196
|
-
function
|
|
1196
|
+
function ze(e, t, a) {
|
|
1197
1197
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1198
1198
|
}
|
|
1199
|
-
function
|
|
1199
|
+
function gt(e, t) {
|
|
1200
1200
|
const a = { ...t };
|
|
1201
|
-
for (const
|
|
1202
|
-
if (
|
|
1203
|
-
a.vaultItemSeparator =
|
|
1201
|
+
for (const r of e) {
|
|
1202
|
+
if (r.kind === "input") {
|
|
1203
|
+
a.vaultItemSeparator = r.state.value;
|
|
1204
1204
|
continue;
|
|
1205
1205
|
}
|
|
1206
|
-
const n =
|
|
1206
|
+
const n = Y(r.state)?.value;
|
|
1207
1207
|
if (n) {
|
|
1208
|
-
if (
|
|
1208
|
+
if (r.key === "updateCheck") {
|
|
1209
1209
|
a.updateCheck = n;
|
|
1210
1210
|
continue;
|
|
1211
1211
|
}
|
|
1212
|
-
if (
|
|
1212
|
+
if (r.key === "style") {
|
|
1213
1213
|
a.style = n;
|
|
1214
1214
|
continue;
|
|
1215
1215
|
}
|
|
1216
|
-
if (
|
|
1216
|
+
if (r.key === "language") {
|
|
1217
1217
|
a.language = n;
|
|
1218
1218
|
continue;
|
|
1219
1219
|
}
|
|
@@ -1222,52 +1222,52 @@ function ht(e, t) {
|
|
|
1222
1222
|
}
|
|
1223
1223
|
return a;
|
|
1224
1224
|
}
|
|
1225
|
-
function
|
|
1226
|
-
return Math.max(...e.map((t) =>
|
|
1227
|
-
}
|
|
1228
|
-
function
|
|
1229
|
-
const o =
|
|
1230
|
-
upDown:
|
|
1231
|
-
leftRight:
|
|
1232
|
-
type:
|
|
1233
|
-
enter:
|
|
1234
|
-
cancel:
|
|
1225
|
+
function ya(e) {
|
|
1226
|
+
return Math.max(...e.map((t) => X(t.label)), 1);
|
|
1227
|
+
}
|
|
1228
|
+
function U(e, t, a, r, n) {
|
|
1229
|
+
const o = gt(e, a), s = !ft(o, a), c = ya(e), l = e.length, d = t === l, m = i("command.config.hint", {
|
|
1230
|
+
upDown: N(i("command.config.key.up_down")),
|
|
1231
|
+
leftRight: N(i("command.config.key.left_right")),
|
|
1232
|
+
type: N(i("command.config.key.type")),
|
|
1233
|
+
enter: N(i("command.config.key.enter")),
|
|
1234
|
+
cancel: N(i("command.config.key.cancel"))
|
|
1235
1235
|
}), u = [];
|
|
1236
|
-
u.push(v.bold(
|
|
1237
|
-
for (let
|
|
1238
|
-
const
|
|
1239
|
-
if (!
|
|
1236
|
+
u.push(v.bold(i("command.config.title"))), u.push("");
|
|
1237
|
+
for (let R = 0; R < e.length; R += 1) {
|
|
1238
|
+
const k = e[R];
|
|
1239
|
+
if (!k)
|
|
1240
1240
|
continue;
|
|
1241
|
-
const
|
|
1242
|
-
u.push(`${
|
|
1241
|
+
const S = R === t, M = S ? v.cyan(">") : " ", E = De(k.label, c), D = S ? v.bold(E) : E, L = k.kind === "select" ? Q(k.state, S) : vt(k.state, S, i("command.config.input.placeholder"));
|
|
1242
|
+
u.push(`${M} ${D} ${L}`);
|
|
1243
1243
|
}
|
|
1244
|
-
u.push(""), u.push(`${
|
|
1245
|
-
const
|
|
1244
|
+
u.push(""), u.push(`${i("command.config.action_prefix")} ${Q(r, d)}`), u.push("");
|
|
1245
|
+
const g = n ? v.yellow(n) : v.dim(i(s ? "command.config.state.dirty" : "command.config.state.clean")), p = Te({
|
|
1246
1246
|
contentLines: u,
|
|
1247
1247
|
hintLine: m,
|
|
1248
|
-
statusLine:
|
|
1248
|
+
statusLine: g,
|
|
1249
1249
|
rows: process.stdout.rows
|
|
1250
1250
|
});
|
|
1251
|
-
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(
|
|
1251
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(p.join(`
|
|
1252
1252
|
`));
|
|
1253
1253
|
}
|
|
1254
|
-
async function
|
|
1255
|
-
if (!
|
|
1256
|
-
throw new Error(
|
|
1257
|
-
const t = process.stdin, a =
|
|
1258
|
-
let
|
|
1259
|
-
{ value: "save", label:
|
|
1260
|
-
{ value: "cancel", label:
|
|
1261
|
-
{ value: "reset-default", label:
|
|
1254
|
+
async function ba(e) {
|
|
1255
|
+
if (!wa())
|
|
1256
|
+
throw new Error(i("command.config.error.no_tty"));
|
|
1257
|
+
const t = process.stdin, a = Ia(e);
|
|
1258
|
+
let r = F([
|
|
1259
|
+
{ value: "save", label: i("command.config.action.save") },
|
|
1260
|
+
{ value: "cancel", label: i("command.config.action.cancel") },
|
|
1261
|
+
{ value: "reset-default", label: i("command.config.action.reset_default") }
|
|
1262
1262
|
]), n = 0, o = "";
|
|
1263
|
-
return
|
|
1263
|
+
return Se.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((s) => {
|
|
1264
1264
|
const c = (m) => {
|
|
1265
1265
|
t.off("keypress", d), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1266
1266
|
`), s(m);
|
|
1267
1267
|
}, l = () => {
|
|
1268
|
-
const m =
|
|
1268
|
+
const m = gt(a, e), u = _a(m);
|
|
1269
1269
|
if (u) {
|
|
1270
|
-
o =
|
|
1270
|
+
o = i(u), U(a, n, e, r, o);
|
|
1271
1271
|
return;
|
|
1272
1272
|
}
|
|
1273
1273
|
c({ action: "save", values: m });
|
|
@@ -1281,11 +1281,11 @@ async function ya(e) {
|
|
|
1281
1281
|
return;
|
|
1282
1282
|
}
|
|
1283
1283
|
if (u.name === "up") {
|
|
1284
|
-
n =
|
|
1284
|
+
n = ze(n, "up", a.length + 1), o = "", U(a, n, e, r, o);
|
|
1285
1285
|
return;
|
|
1286
1286
|
}
|
|
1287
1287
|
if (u.name === "down") {
|
|
1288
|
-
n =
|
|
1288
|
+
n = ze(n, "down", a.length + 1), o = "", U(a, n, e, r, o);
|
|
1289
1289
|
return;
|
|
1290
1290
|
}
|
|
1291
1291
|
if (n === a.length) {
|
|
@@ -1294,16 +1294,16 @@ async function ya(e) {
|
|
|
1294
1294
|
return;
|
|
1295
1295
|
}
|
|
1296
1296
|
if (u.name === "left" || u.name === "right") {
|
|
1297
|
-
|
|
1297
|
+
r = J(r, u.name), o = "", U(a, n, e, r, o);
|
|
1298
1298
|
return;
|
|
1299
1299
|
}
|
|
1300
1300
|
if (u.name === "return" || u.name === "enter") {
|
|
1301
|
-
const
|
|
1302
|
-
if (
|
|
1301
|
+
const p = Y(r)?.value ?? "save";
|
|
1302
|
+
if (p === "cancel") {
|
|
1303
1303
|
c({ action: "cancel" });
|
|
1304
1304
|
return;
|
|
1305
1305
|
}
|
|
1306
|
-
if (
|
|
1306
|
+
if (p === "reset-default") {
|
|
1307
1307
|
c({ action: "reset-default" });
|
|
1308
1308
|
return;
|
|
1309
1309
|
}
|
|
@@ -1311,172 +1311,172 @@ async function ya(e) {
|
|
|
1311
1311
|
}
|
|
1312
1312
|
return;
|
|
1313
1313
|
}
|
|
1314
|
-
const
|
|
1315
|
-
if (!
|
|
1314
|
+
const g = a[n];
|
|
1315
|
+
if (!g) {
|
|
1316
1316
|
c({ action: "cancel" });
|
|
1317
1317
|
return;
|
|
1318
1318
|
}
|
|
1319
|
-
if (u.name === "q" &&
|
|
1319
|
+
if (u.name === "q" && g.kind !== "input") {
|
|
1320
1320
|
c({ action: "cancel" });
|
|
1321
1321
|
return;
|
|
1322
1322
|
}
|
|
1323
1323
|
if (u.name === "left" || u.name === "right") {
|
|
1324
|
-
|
|
1324
|
+
g.kind === "select" ? g.state = J(g.state, u.name) : g.state = fe(g.state, m, u).state, o = "", U(a, n, e, r, o);
|
|
1325
1325
|
return;
|
|
1326
1326
|
}
|
|
1327
|
-
if (
|
|
1328
|
-
const
|
|
1329
|
-
if (
|
|
1327
|
+
if (g.kind === "input") {
|
|
1328
|
+
const p = fe(g.state, m, u);
|
|
1329
|
+
if (g.state = p.state, p.action === "cancel") {
|
|
1330
1330
|
c({ action: "cancel" });
|
|
1331
1331
|
return;
|
|
1332
1332
|
}
|
|
1333
|
-
if (
|
|
1333
|
+
if (p.action === "submit") {
|
|
1334
1334
|
l();
|
|
1335
1335
|
return;
|
|
1336
1336
|
}
|
|
1337
|
-
o = "",
|
|
1337
|
+
o = "", U(a, n, e, r, o);
|
|
1338
1338
|
return;
|
|
1339
1339
|
}
|
|
1340
1340
|
(u.name === "return" || u.name === "enter") && l();
|
|
1341
1341
|
};
|
|
1342
|
-
t.on("keypress", d),
|
|
1342
|
+
t.on("keypress", d), U(a, n, e, r, o);
|
|
1343
1343
|
});
|
|
1344
1344
|
}
|
|
1345
|
-
async function
|
|
1346
|
-
const t = await e.configService.getConfig(), a =
|
|
1347
|
-
if (
|
|
1348
|
-
|
|
1345
|
+
async function ka(e) {
|
|
1346
|
+
const t = await e.configService.getConfig(), a = pa(t), r = await ba(a);
|
|
1347
|
+
if (r.action === "cancel") {
|
|
1348
|
+
A(i("command.config.cancelled"));
|
|
1349
1349
|
return;
|
|
1350
1350
|
}
|
|
1351
|
-
if (
|
|
1352
|
-
await e.context.saveConfig({ ...
|
|
1351
|
+
if (r.action === "reset-default") {
|
|
1352
|
+
await e.context.saveConfig({ ...f.Config }), he(f.Config), T(i("command.config.reset_default.saved")), await e.auditLogger.log(
|
|
1353
1353
|
"INFO",
|
|
1354
1354
|
{ main: "config", sub: "reset-default", source: "u" },
|
|
1355
|
-
|
|
1356
|
-
), await
|
|
1355
|
+
i("command.config.audit.reset_default")
|
|
1356
|
+
), await O(e);
|
|
1357
1357
|
return;
|
|
1358
1358
|
}
|
|
1359
|
-
if (
|
|
1360
|
-
|
|
1359
|
+
if (ft(a, r.values)) {
|
|
1360
|
+
A(i("command.config.no_changes"));
|
|
1361
1361
|
return;
|
|
1362
1362
|
}
|
|
1363
1363
|
const n = {
|
|
1364
1364
|
...t,
|
|
1365
|
-
...
|
|
1365
|
+
...r.values
|
|
1366
1366
|
};
|
|
1367
|
-
await e.context.saveConfig(n),
|
|
1367
|
+
await e.context.saveConfig(n), he(n), T(i("command.config.saved")), await e.auditLogger.log(
|
|
1368
1368
|
"INFO",
|
|
1369
1369
|
{ main: "config", sub: "edit", source: "u" },
|
|
1370
|
-
|
|
1371
|
-
), await
|
|
1370
|
+
i("command.config.audit.saved")
|
|
1371
|
+
), await O(e);
|
|
1372
1372
|
}
|
|
1373
1373
|
function Ca(e, t) {
|
|
1374
|
-
e.command("config").description(
|
|
1375
|
-
() =>
|
|
1376
|
-
await
|
|
1374
|
+
e.command("config").description(i("command.config.description")).action(
|
|
1375
|
+
() => P(async () => {
|
|
1376
|
+
await ka(t);
|
|
1377
1377
|
})
|
|
1378
1378
|
);
|
|
1379
1379
|
}
|
|
1380
|
-
const
|
|
1381
|
-
function
|
|
1380
|
+
const Ea = "__ARCHIVER_CD__:";
|
|
1381
|
+
function xa(e, t) {
|
|
1382
1382
|
if (e.includes(`
|
|
1383
1383
|
`) || e.includes("\r"))
|
|
1384
1384
|
throw new Error(
|
|
1385
|
-
|
|
1385
|
+
i("util.cd.error.newline_not_supported", {
|
|
1386
1386
|
label: t
|
|
1387
1387
|
})
|
|
1388
1388
|
);
|
|
1389
1389
|
}
|
|
1390
|
-
function
|
|
1391
|
-
return
|
|
1390
|
+
function Aa(e) {
|
|
1391
|
+
return xa(e, i("util.cd.label.archive_slot_path")), `${Ea}${e}`;
|
|
1392
1392
|
}
|
|
1393
|
-
async function
|
|
1394
|
-
console.log(
|
|
1393
|
+
async function Ra(e) {
|
|
1394
|
+
console.log(Aa(e));
|
|
1395
1395
|
}
|
|
1396
|
-
const
|
|
1397
|
-
function
|
|
1398
|
-
return
|
|
1396
|
+
const ae = ["status", "vault", "query", "entries", "action"];
|
|
1397
|
+
function We(e) {
|
|
1398
|
+
return i(e === "enter" ? "command.list.interactive.action.enter" : "command.list.interactive.action.restore");
|
|
1399
1399
|
}
|
|
1400
|
-
function
|
|
1401
|
-
return
|
|
1400
|
+
function de(e) {
|
|
1401
|
+
return i(e === "archived" ? "command.list.interactive.filter.status.archived" : e === "restored" ? "command.list.interactive.filter.status.restored" : "command.list.interactive.filter.status.all");
|
|
1402
1402
|
}
|
|
1403
|
-
function
|
|
1404
|
-
return
|
|
1403
|
+
function pt(e) {
|
|
1404
|
+
return F(
|
|
1405
1405
|
[
|
|
1406
|
-
{ value: "all", label:
|
|
1407
|
-
{ value: "archived", label:
|
|
1408
|
-
{ value: "restored", label:
|
|
1406
|
+
{ value: "all", label: de("all") },
|
|
1407
|
+
{ value: "archived", label: de("archived") },
|
|
1408
|
+
{ value: "restored", label: de("restored") }
|
|
1409
1409
|
],
|
|
1410
1410
|
e
|
|
1411
1411
|
);
|
|
1412
1412
|
}
|
|
1413
|
-
function
|
|
1414
|
-
const t = [{ value: "all", label:
|
|
1415
|
-
for (const n of
|
|
1413
|
+
function Va(e) {
|
|
1414
|
+
const t = [{ value: "all", label: i("command.list.interactive.filter.vault.all") }], a = /* @__PURE__ */ new Set(), r = [...e].sort((n, o) => n.vaultId - o.vaultId);
|
|
1415
|
+
for (const n of r)
|
|
1416
1416
|
a.has(n.vaultId) || (a.add(n.vaultId), t.push({
|
|
1417
1417
|
value: n.vaultId,
|
|
1418
|
-
label: n.vaultId === 0 ?
|
|
1418
|
+
label: n.vaultId === 0 ? i("command.list.interactive.filter.vault.default") : n.vaultName
|
|
1419
1419
|
}));
|
|
1420
1420
|
return t;
|
|
1421
1421
|
}
|
|
1422
|
-
function
|
|
1423
|
-
return
|
|
1422
|
+
function _t(e, t) {
|
|
1423
|
+
return F(e, t);
|
|
1424
1424
|
}
|
|
1425
|
-
function
|
|
1426
|
-
return e.find((a) => a.value === t)?.label ??
|
|
1425
|
+
function Sa(e, t) {
|
|
1426
|
+
return e.find((a) => a.value === t)?.label ?? i("command.list.interactive.filter.vault.all");
|
|
1427
1427
|
}
|
|
1428
|
-
function
|
|
1429
|
-
return
|
|
1428
|
+
function Pe(e, t) {
|
|
1429
|
+
return F(
|
|
1430
1430
|
[
|
|
1431
|
-
{ value: "enter", label:
|
|
1432
|
-
{ value: "restore", label:
|
|
1431
|
+
{ value: "enter", label: We("enter"), disabled: !Re(e, "enter") },
|
|
1432
|
+
{ value: "restore", label: We("restore"), disabled: !Re(e, "restore") }
|
|
1433
1433
|
],
|
|
1434
1434
|
t
|
|
1435
1435
|
);
|
|
1436
1436
|
}
|
|
1437
|
-
function
|
|
1438
|
-
return
|
|
1437
|
+
function be(e, t) {
|
|
1438
|
+
return Y(Pe(e, t))?.value ?? t;
|
|
1439
1439
|
}
|
|
1440
|
-
function
|
|
1441
|
-
const
|
|
1442
|
-
return
|
|
1440
|
+
function La(e, t, a) {
|
|
1441
|
+
const r = Pe(e, t), n = J(r, a);
|
|
1442
|
+
return Y(n)?.value ?? t;
|
|
1443
1443
|
}
|
|
1444
|
-
function
|
|
1445
|
-
const a = t === "left" ? -1 : 1,
|
|
1446
|
-
return
|
|
1444
|
+
function $a(e, t) {
|
|
1445
|
+
const a = t === "left" ? -1 : 1, r = ae.indexOf(e);
|
|
1446
|
+
return r === -1 ? ae[0] : ae[(r + a + ae.length) % ae.length] ?? e;
|
|
1447
1447
|
}
|
|
1448
|
-
function
|
|
1448
|
+
function Ta(e, t, a) {
|
|
1449
1449
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1450
1450
|
}
|
|
1451
|
-
function
|
|
1451
|
+
function Na(e, t) {
|
|
1452
1452
|
if (!t)
|
|
1453
1453
|
return !0;
|
|
1454
1454
|
let a = 0;
|
|
1455
|
-
const
|
|
1456
|
-
for (const o of
|
|
1455
|
+
const r = e.toLowerCase(), n = t.toLowerCase();
|
|
1456
|
+
for (const o of r)
|
|
1457
1457
|
if (o === n[a] && (a += 1, a >= n.length))
|
|
1458
1458
|
return !0;
|
|
1459
1459
|
return !1;
|
|
1460
1460
|
}
|
|
1461
|
-
function
|
|
1462
|
-
const n =
|
|
1463
|
-
return e.filter((o) => t === "archived" && o.status !== C.Archived || t === "restored" && o.status !== C.Restored || a !== "all" && o.vaultId !== a ? !1 :
|
|
1461
|
+
function Je(e, t, a, r) {
|
|
1462
|
+
const n = r.trim();
|
|
1463
|
+
return e.filter((o) => t === "archived" && o.status !== C.Archived || t === "restored" && o.status !== C.Restored || a !== "all" && o.vaultId !== a ? !1 : Na(o.title, n));
|
|
1464
1464
|
}
|
|
1465
|
-
function
|
|
1465
|
+
function Ge(e, t, a) {
|
|
1466
1466
|
if (e.length === 0)
|
|
1467
1467
|
return 0;
|
|
1468
1468
|
if (a !== void 0) {
|
|
1469
|
-
const
|
|
1470
|
-
if (
|
|
1471
|
-
return
|
|
1469
|
+
const r = e.findIndex((n) => n.id === a);
|
|
1470
|
+
if (r >= 0)
|
|
1471
|
+
return r;
|
|
1472
1472
|
}
|
|
1473
1473
|
return Math.min(t, e.length - 1);
|
|
1474
1474
|
}
|
|
1475
|
-
function
|
|
1475
|
+
function Da(e) {
|
|
1476
1476
|
const {
|
|
1477
1477
|
entries: t,
|
|
1478
1478
|
filteredEntries: a,
|
|
1479
|
-
selectedIndex:
|
|
1479
|
+
selectedIndex: r,
|
|
1480
1480
|
statusFilter: n,
|
|
1481
1481
|
vaultFilter: o,
|
|
1482
1482
|
vaultOptions: s,
|
|
@@ -1484,213 +1484,264 @@ function Na(e) {
|
|
|
1484
1484
|
focus: l,
|
|
1485
1485
|
action: d,
|
|
1486
1486
|
note: m
|
|
1487
|
-
} = e, u = a[
|
|
1488
|
-
status:
|
|
1489
|
-
vault:
|
|
1490
|
-
query:
|
|
1491
|
-
},
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
),
|
|
1496
|
-
const
|
|
1497
|
-
return
|
|
1498
|
-
},
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1487
|
+
} = e, u = a[r], g = process.stdout.rows ?? 24, p = pt(n), R = _t(s, o), k = Pe(u, d), S = {
|
|
1488
|
+
status: i("command.list.interactive.filter.status.label"),
|
|
1489
|
+
vault: i("command.list.interactive.filter.vault.label"),
|
|
1490
|
+
query: i("command.list.interactive.filter.query.label")
|
|
1491
|
+
}, M = Math.max(
|
|
1492
|
+
X(S.status),
|
|
1493
|
+
X(S.vault),
|
|
1494
|
+
X(S.query)
|
|
1495
|
+
), E = (G, H, re) => {
|
|
1496
|
+
const ie = l === G, ne = ie ? v.cyan(">") : " ", ee = `${De(H, M)}: ${re}`;
|
|
1497
|
+
return ie ? `${ne} ${v.bold(ee)}` : `${ne} ${ee}`;
|
|
1498
|
+
}, D = [
|
|
1499
|
+
E("status", S.status, Q(p, l === "status")),
|
|
1500
|
+
E("vault", S.vault, Q(R, l === "vault")),
|
|
1501
|
+
E(
|
|
1502
1502
|
"query",
|
|
1503
|
-
|
|
1504
|
-
|
|
1503
|
+
S.query,
|
|
1504
|
+
vt(c, l === "query", i("command.list.interactive.filter.query.placeholder"))
|
|
1505
1505
|
),
|
|
1506
1506
|
""
|
|
1507
|
-
],
|
|
1507
|
+
], V = Math.max(g - D.length - 2 - 2, 2), we = Math.max(Math.floor(V / 2), 1), xt = Math.floor(we / 2), At = Math.max(a.length - we, 0), Oe = Math.min(Math.max(r - xt, 0), At), Rt = Math.min(Oe + we, a.length), j = [...D];
|
|
1508
1508
|
if (a.length === 0)
|
|
1509
|
-
|
|
1509
|
+
j.push(v.dim(i("command.list.interactive.empty_filtered")));
|
|
1510
1510
|
else
|
|
1511
|
-
for (let
|
|
1512
|
-
const
|
|
1513
|
-
if (!
|
|
1511
|
+
for (let G = Oe; G < Rt; G += 1) {
|
|
1512
|
+
const H = a[G];
|
|
1513
|
+
if (!H)
|
|
1514
1514
|
continue;
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1515
|
+
const re = G === r, ie = re ? l === "entries" ? v.cyan(">") : v.green(">") : " ", ne = H.status === C.Archived ? v.green("A") : v.gray("R"), ee = `${ie} [${String(H.id).padStart(4, " ")}] ${ne} ${H.title}`, Fe = ` ${v.dim(H.path)}`;
|
|
1516
|
+
re ? (j.push(v.bold(ee)), j.push(v.cyan(Fe))) : (j.push(ee), j.push(Fe));
|
|
1517
1517
|
}
|
|
1518
|
-
|
|
1519
|
-
const
|
|
1520
|
-
tab:
|
|
1521
|
-
upDown:
|
|
1522
|
-
leftRight:
|
|
1523
|
-
type:
|
|
1524
|
-
enter:
|
|
1525
|
-
cancel:
|
|
1526
|
-
}),
|
|
1518
|
+
j.push(""), j.push(E("action", `${i("command.list.interactive.action_prefix")}:`, Q(k, l === "action")));
|
|
1519
|
+
const Vt = i("command.list.interactive.hint", {
|
|
1520
|
+
tab: N(i("command.list.interactive.key.tab")),
|
|
1521
|
+
upDown: N(i("command.list.interactive.key.up_down")),
|
|
1522
|
+
leftRight: N(i("command.list.interactive.key.left_right")),
|
|
1523
|
+
type: N(i("command.list.interactive.key.type")),
|
|
1524
|
+
enter: N(i("command.list.interactive.key.enter")),
|
|
1525
|
+
cancel: N(i("command.list.interactive.key.cancel"))
|
|
1526
|
+
}), St = c.value.trim() || i("command.list.interactive.summary.query_empty"), Lt = i("command.list.interactive.summary", {
|
|
1527
1527
|
matched: a.length,
|
|
1528
1528
|
total: t.length,
|
|
1529
|
-
status:
|
|
1530
|
-
vault:
|
|
1531
|
-
query:
|
|
1532
|
-
}),
|
|
1533
|
-
contentLines:
|
|
1534
|
-
hintLine:
|
|
1535
|
-
statusLine:
|
|
1536
|
-
rows:
|
|
1529
|
+
status: de(n),
|
|
1530
|
+
vault: Sa(s, o),
|
|
1531
|
+
query: St
|
|
1532
|
+
}), $t = m ? v.yellow(m) : v.dim(Lt), Tt = Te({
|
|
1533
|
+
contentLines: j,
|
|
1534
|
+
hintLine: Vt,
|
|
1535
|
+
statusLine: $t,
|
|
1536
|
+
rows: g
|
|
1537
1537
|
});
|
|
1538
|
-
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(
|
|
1538
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(Tt.join(`
|
|
1539
1539
|
`));
|
|
1540
1540
|
}
|
|
1541
|
-
function
|
|
1542
|
-
return
|
|
1541
|
+
function wt() {
|
|
1542
|
+
return Ne();
|
|
1543
1543
|
}
|
|
1544
|
-
function
|
|
1544
|
+
function Re(e, t) {
|
|
1545
1545
|
return e && (t === "enter" || t === "restore") ? e.status === C.Archived : !1;
|
|
1546
1546
|
}
|
|
1547
|
-
async function
|
|
1548
|
-
if (e.length === 0 || !
|
|
1547
|
+
async function Pa(e, t) {
|
|
1548
|
+
if (e.length === 0 || !wt())
|
|
1549
1549
|
return null;
|
|
1550
|
-
const
|
|
1551
|
-
let
|
|
1552
|
-
const
|
|
1553
|
-
const
|
|
1554
|
-
|
|
1555
|
-
},
|
|
1556
|
-
|
|
1557
|
-
entries:
|
|
1558
|
-
filteredEntries:
|
|
1559
|
-
selectedIndex:
|
|
1560
|
-
statusFilter:
|
|
1561
|
-
vaultFilter:
|
|
1562
|
-
vaultOptions:
|
|
1563
|
-
queryState:
|
|
1564
|
-
focus:
|
|
1565
|
-
action:
|
|
1566
|
-
note:
|
|
1550
|
+
const a = e.map((M) => ({ ...M })), r = process.stdin, n = Va(a);
|
|
1551
|
+
let o = "archived", s = "all", c = mt(""), l = "entries", d = Je(a, o, s, c.value), m = Ge(d, 0), u = be(d[m], "enter"), g = !1, p = "";
|
|
1552
|
+
const R = () => {
|
|
1553
|
+
const M = d[m]?.id;
|
|
1554
|
+
d = Je(a, o, s, c.value), m = Ge(d, m, M), u = be(d[m], u);
|
|
1555
|
+
}, k = () => {
|
|
1556
|
+
Da({
|
|
1557
|
+
entries: a,
|
|
1558
|
+
filteredEntries: d,
|
|
1559
|
+
selectedIndex: m,
|
|
1560
|
+
statusFilter: o,
|
|
1561
|
+
vaultFilter: s,
|
|
1562
|
+
vaultOptions: n,
|
|
1563
|
+
queryState: c,
|
|
1564
|
+
focus: l,
|
|
1565
|
+
action: u,
|
|
1566
|
+
note: p
|
|
1567
1567
|
});
|
|
1568
|
-
},
|
|
1569
|
-
const
|
|
1570
|
-
if (!
|
|
1571
|
-
|
|
1568
|
+
}, S = (M) => {
|
|
1569
|
+
const E = d[m];
|
|
1570
|
+
if (!E) {
|
|
1571
|
+
p = i("command.list.interactive.empty_filtered"), k();
|
|
1572
1572
|
return;
|
|
1573
1573
|
}
|
|
1574
|
-
const
|
|
1575
|
-
if (!
|
|
1576
|
-
|
|
1574
|
+
const D = be(E, u);
|
|
1575
|
+
if (!Re(E, D)) {
|
|
1576
|
+
p = i("command.list.interactive.note.restored_unavailable"), k();
|
|
1577
1577
|
return;
|
|
1578
1578
|
}
|
|
1579
|
-
|
|
1579
|
+
if (D === "restore") {
|
|
1580
|
+
g = !0, (async () => {
|
|
1581
|
+
try {
|
|
1582
|
+
const L = await t({ entry: E, action: D });
|
|
1583
|
+
if (L.ok) {
|
|
1584
|
+
const I = a.find((V) => V.id === E.id);
|
|
1585
|
+
I && (I.status = C.Restored);
|
|
1586
|
+
}
|
|
1587
|
+
p = L.message;
|
|
1588
|
+
} catch (L) {
|
|
1589
|
+
p = L.message;
|
|
1590
|
+
} finally {
|
|
1591
|
+
g = !1, R(), k();
|
|
1592
|
+
}
|
|
1593
|
+
})();
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
M({ entry: E, action: D });
|
|
1580
1597
|
};
|
|
1581
|
-
return
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
`),
|
|
1585
|
-
},
|
|
1586
|
-
if (
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
}
|
|
1590
|
-
if (p.name === "escape") {
|
|
1591
|
-
b(null);
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
if (p.name === "q" && s !== "query") {
|
|
1595
|
-
b(null);
|
|
1596
|
-
return;
|
|
1597
|
-
}
|
|
1598
|
-
if (p.name === "tab") {
|
|
1599
|
-
s = La(s, p.shift ? "left" : "right"), m = "", h();
|
|
1600
|
-
return;
|
|
1601
|
-
}
|
|
1602
|
-
if (p.name === "return" || p.name === "enter") {
|
|
1603
|
-
k(b);
|
|
1604
|
-
return;
|
|
1605
|
-
}
|
|
1606
|
-
if (s === "entries" && (p.name === "up" || p.name === "down")) {
|
|
1607
|
-
l = $a(l, p.name, c.length), m = "", h();
|
|
1608
|
-
return;
|
|
1609
|
-
}
|
|
1610
|
-
if (s === "status" && (p.name === "left" || p.name === "right")) {
|
|
1611
|
-
const A = B(ft(i), p.name);
|
|
1612
|
-
i = O(A)?.value ?? i, u(), m = "", h();
|
|
1613
|
-
return;
|
|
1614
|
-
}
|
|
1615
|
-
if (s === "vault" && (p.name === "left" || p.name === "right")) {
|
|
1616
|
-
const A = B(gt(a, n), p.name);
|
|
1617
|
-
n = O(A)?.value ?? n, u(), m = "", h();
|
|
1618
|
-
return;
|
|
1619
|
-
}
|
|
1620
|
-
if ((s === "action" || s === "entries") && (p.name === "left" || p.name === "right")) {
|
|
1621
|
-
d = Sa(c[l], d, p.name), m = "", h();
|
|
1622
|
-
return;
|
|
1623
|
-
}
|
|
1624
|
-
if (s === "query") {
|
|
1625
|
-
const A = me(o, D, p);
|
|
1626
|
-
if (o = A.state, A.action === "cancel") {
|
|
1627
|
-
b(null);
|
|
1598
|
+
return Se.emitKeypressEvents(r), r.setRawMode(!0), r.resume(), new Promise((M) => {
|
|
1599
|
+
const E = (L) => {
|
|
1600
|
+
r.off("keypress", D), r.setRawMode(!1), r.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1601
|
+
`), M(L);
|
|
1602
|
+
}, D = (L, I) => {
|
|
1603
|
+
if (!g) {
|
|
1604
|
+
if (I.ctrl && I.name === "c") {
|
|
1605
|
+
E(null);
|
|
1628
1606
|
return;
|
|
1629
1607
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1608
|
+
if (I.name === "escape") {
|
|
1609
|
+
E(null);
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
if (I.name === "q" && l !== "query") {
|
|
1613
|
+
E(null);
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
if (I.name === "tab") {
|
|
1617
|
+
l = $a(l, I.shift ? "left" : "right"), p = "", k();
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
if (I.name === "return" || I.name === "enter") {
|
|
1621
|
+
S(E);
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
if (l === "entries" && (I.name === "up" || I.name === "down")) {
|
|
1625
|
+
m = Ta(m, I.name, d.length), p = "", k();
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
1628
|
+
if (l === "status" && (I.name === "left" || I.name === "right")) {
|
|
1629
|
+
const V = J(pt(o), I.name);
|
|
1630
|
+
o = Y(V)?.value ?? o, R(), p = "", k();
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
if (l === "vault" && (I.name === "left" || I.name === "right")) {
|
|
1634
|
+
const V = J(_t(n, s), I.name);
|
|
1635
|
+
s = Y(V)?.value ?? s, R(), p = "", k();
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
if ((l === "action" || l === "entries") && (I.name === "left" || I.name === "right")) {
|
|
1639
|
+
u = La(d[m], u, I.name), p = "", k();
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
if (l === "query") {
|
|
1643
|
+
const V = fe(c, L, I);
|
|
1644
|
+
if (c = V.state, V.action === "cancel") {
|
|
1645
|
+
E(null);
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1648
|
+
R(), p = "", k();
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
if (L) {
|
|
1652
|
+
const V = fe(c, L, {});
|
|
1653
|
+
(V.state.value !== c.value || V.state.cursor !== c.cursor) && (l = "query", c = V.state, R(), p = "", k());
|
|
1654
|
+
}
|
|
1636
1655
|
}
|
|
1637
1656
|
};
|
|
1638
|
-
|
|
1657
|
+
r.on("keypress", D), k();
|
|
1639
1658
|
});
|
|
1640
1659
|
}
|
|
1641
|
-
function
|
|
1642
|
-
return e.vaultId ===
|
|
1660
|
+
function Me(e, t) {
|
|
1661
|
+
return e.vaultId === f.Vault.id ? e.item : `${e.vaultName}${t}${e.item}`;
|
|
1643
1662
|
}
|
|
1644
|
-
function
|
|
1663
|
+
function Ma(e) {
|
|
1645
1664
|
return String(e).padStart(4, "0");
|
|
1646
1665
|
}
|
|
1647
|
-
function
|
|
1666
|
+
function It(e) {
|
|
1648
1667
|
return e.status === C.Archived ? "A" : "R";
|
|
1649
1668
|
}
|
|
1650
|
-
function Ma(e, t) {
|
|
1651
|
-
const a = st(_t(e));
|
|
1652
|
-
return `[${Pa(e.id)}] ${a} ${Ne(e, t)}`;
|
|
1653
|
-
}
|
|
1654
1669
|
function Oa(e, t) {
|
|
1655
|
-
|
|
1656
|
-
`)
|
|
1670
|
+
const a = dt(It(e));
|
|
1671
|
+
return `[${Ma(e.id)}] ${a} ${Me(e, t)}`;
|
|
1657
1672
|
}
|
|
1658
1673
|
function Fa(e, t) {
|
|
1659
|
-
return e.map((a) =>
|
|
1674
|
+
return e.map((a) => Oa(a, t)).join(`
|
|
1660
1675
|
`);
|
|
1661
1676
|
}
|
|
1662
1677
|
function ja(e, t) {
|
|
1678
|
+
return e.map((a) => `${a.id} ${It(a)} ${Me(a, t)}`).join(`
|
|
1679
|
+
`);
|
|
1680
|
+
}
|
|
1681
|
+
function Ya(e, t) {
|
|
1663
1682
|
return e.map((a) => ({
|
|
1664
1683
|
id: a.id,
|
|
1665
1684
|
status: a.status,
|
|
1666
|
-
title:
|
|
1685
|
+
title: Me(a, t),
|
|
1667
1686
|
path: a.displayPath,
|
|
1668
1687
|
vaultId: a.vaultId,
|
|
1669
1688
|
vaultName: a.vaultName
|
|
1670
1689
|
}));
|
|
1671
1690
|
}
|
|
1672
|
-
async function
|
|
1691
|
+
async function Ha(e, t) {
|
|
1692
|
+
try {
|
|
1693
|
+
const a = await e.archiveService.restore([t.id]), r = a.ok[0];
|
|
1694
|
+
if (r)
|
|
1695
|
+
return {
|
|
1696
|
+
ok: !0,
|
|
1697
|
+
message: i("command.archive.result.restore.ok", {
|
|
1698
|
+
id: r.id ?? t.id,
|
|
1699
|
+
message: r.message
|
|
1700
|
+
})
|
|
1701
|
+
};
|
|
1702
|
+
const n = a.failed[0];
|
|
1703
|
+
return n ? {
|
|
1704
|
+
ok: !1,
|
|
1705
|
+
message: i("command.archive.result.restore.failed", {
|
|
1706
|
+
id: n.id ?? t.id,
|
|
1707
|
+
message: n.message
|
|
1708
|
+
})
|
|
1709
|
+
} : {
|
|
1710
|
+
ok: !1,
|
|
1711
|
+
message: i("command.archive.result.restore.failed", {
|
|
1712
|
+
id: t.id,
|
|
1713
|
+
message: "-"
|
|
1714
|
+
})
|
|
1715
|
+
};
|
|
1716
|
+
} catch (a) {
|
|
1717
|
+
return {
|
|
1718
|
+
ok: !1,
|
|
1719
|
+
message: a.message
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
async function qa(e, t) {
|
|
1673
1724
|
const a = t.entry.id;
|
|
1674
1725
|
if (t.action === "restore") {
|
|
1675
1726
|
const n = await e.archiveService.restore([a]);
|
|
1676
1727
|
for (const o of n.ok)
|
|
1677
|
-
|
|
1678
|
-
|
|
1728
|
+
T(
|
|
1729
|
+
i("command.archive.result.restore.ok", {
|
|
1679
1730
|
id: o.id,
|
|
1680
1731
|
message: o.message
|
|
1681
1732
|
})
|
|
1682
1733
|
);
|
|
1683
1734
|
for (const o of n.failed)
|
|
1684
|
-
|
|
1685
|
-
|
|
1735
|
+
K(
|
|
1736
|
+
i("command.archive.result.restore.failed", {
|
|
1686
1737
|
id: o.id ?? "-",
|
|
1687
1738
|
message: o.message
|
|
1688
1739
|
})
|
|
1689
1740
|
);
|
|
1690
|
-
|
|
1741
|
+
le("restore", n), await O(e);
|
|
1691
1742
|
return;
|
|
1692
1743
|
}
|
|
1693
|
-
const
|
|
1744
|
+
const r = await e.archiveService.resolveCdTarget(String(a));
|
|
1694
1745
|
await e.auditLogger.log(
|
|
1695
1746
|
"INFO",
|
|
1696
1747
|
{
|
|
@@ -1699,107 +1750,110 @@ async function Ya(e, t) {
|
|
|
1699
1750
|
args: [String(a)],
|
|
1700
1751
|
source: "u"
|
|
1701
1752
|
},
|
|
1702
|
-
|
|
1703
|
-
vaultId:
|
|
1704
|
-
archiveId:
|
|
1753
|
+
i("command.list.audit.open_slot", {
|
|
1754
|
+
vaultId: r.vault.id,
|
|
1755
|
+
archiveId: r.archiveId
|
|
1705
1756
|
}),
|
|
1706
|
-
{ aid:
|
|
1707
|
-
), await
|
|
1757
|
+
{ aid: r.archiveId, vid: r.vault.id }
|
|
1758
|
+
), await Ra(r.slotPath);
|
|
1708
1759
|
}
|
|
1709
|
-
function
|
|
1710
|
-
e.command("list").description(
|
|
1711
|
-
(a) =>
|
|
1712
|
-
const
|
|
1760
|
+
function Ua(e, t) {
|
|
1761
|
+
e.command("list").description(i("command.list.description")).option("-p, --plain", i("command.list.option.plain")).action(
|
|
1762
|
+
(a) => P(async () => {
|
|
1763
|
+
const r = await t.archiveService.listEntries({ all: !0 }), n = await t.archiveService.decorateEntries(r), o = await t.configService.getConfig();
|
|
1713
1764
|
if (n.length === 0) {
|
|
1714
1765
|
if (a.plain)
|
|
1715
1766
|
return;
|
|
1716
|
-
|
|
1767
|
+
A(i("command.list.empty"));
|
|
1717
1768
|
return;
|
|
1718
1769
|
}
|
|
1719
1770
|
if (a.plain) {
|
|
1720
|
-
console.log(
|
|
1771
|
+
console.log(ja(n, o.vaultItemSeparator));
|
|
1721
1772
|
return;
|
|
1722
1773
|
}
|
|
1723
|
-
if (!
|
|
1724
|
-
console.log(
|
|
1774
|
+
if (!wt()) {
|
|
1775
|
+
console.log(Fa(n, o.vaultItemSeparator));
|
|
1725
1776
|
return;
|
|
1726
1777
|
}
|
|
1727
|
-
const s = await
|
|
1778
|
+
const s = await Pa(
|
|
1779
|
+
Ya(n, o.vaultItemSeparator),
|
|
1780
|
+
async ({ entry: c }) => Ha(t, c)
|
|
1781
|
+
);
|
|
1728
1782
|
if (!s) {
|
|
1729
|
-
|
|
1783
|
+
A(i("command.list.cancelled"));
|
|
1730
1784
|
return;
|
|
1731
1785
|
}
|
|
1732
|
-
await
|
|
1786
|
+
await qa(t, s);
|
|
1733
1787
|
})
|
|
1734
1788
|
);
|
|
1735
1789
|
}
|
|
1736
|
-
function
|
|
1737
|
-
e.command("log").description(
|
|
1738
|
-
(a,
|
|
1739
|
-
if (
|
|
1740
|
-
if (!/^\d+$/.test(
|
|
1741
|
-
throw new Error(
|
|
1742
|
-
const c = Number(
|
|
1790
|
+
function Ba(e, t) {
|
|
1791
|
+
e.command("log").description(i("command.log.description")).argument("[range]", i("command.log.argument.range")).option("--id <id>", i("command.log.option.id")).action(
|
|
1792
|
+
(a, r) => P(async () => {
|
|
1793
|
+
if (r.id !== void 0) {
|
|
1794
|
+
if (!/^\d+$/.test(r.id))
|
|
1795
|
+
throw new Error(i("command.log.error.invalid_id", { id: r.id }));
|
|
1796
|
+
const c = Number(r.id), l = await t.logService.getLogById(c);
|
|
1743
1797
|
if (!l)
|
|
1744
|
-
throw new Error(
|
|
1745
|
-
|
|
1746
|
-
|
|
1798
|
+
throw new Error(i("command.log.error.not_found", { id: c }));
|
|
1799
|
+
A(
|
|
1800
|
+
i("command.log.detail.title", {
|
|
1747
1801
|
id: l.log.id
|
|
1748
1802
|
})
|
|
1749
1803
|
), console.log(
|
|
1750
|
-
|
|
1751
|
-
[
|
|
1804
|
+
oe(
|
|
1805
|
+
[i("command.log.detail.table.field"), i("command.log.detail.table.value")],
|
|
1752
1806
|
[
|
|
1753
|
-
[
|
|
1754
|
-
[
|
|
1755
|
-
[
|
|
1807
|
+
[i("command.log.detail.field.id"), String(l.log.id)],
|
|
1808
|
+
[i("command.log.detail.field.time"), l.log.operedAt],
|
|
1809
|
+
[i("command.log.detail.field.level"), Ue(l.log.level)],
|
|
1756
1810
|
[
|
|
1757
|
-
|
|
1811
|
+
i("command.log.detail.field.operation"),
|
|
1758
1812
|
`${l.log.oper.main}${l.log.oper.sub ? `/${l.log.oper.sub}` : ""}`
|
|
1759
1813
|
],
|
|
1760
|
-
[
|
|
1814
|
+
[i("command.log.detail.field.message"), l.log.message],
|
|
1761
1815
|
[
|
|
1762
|
-
|
|
1816
|
+
i("command.log.detail.field.archive_id"),
|
|
1763
1817
|
l.log.archiveIds !== void 0 ? String(l.log.archiveIds) : ""
|
|
1764
1818
|
],
|
|
1765
1819
|
[
|
|
1766
|
-
|
|
1820
|
+
i("command.log.detail.field.vault_id"),
|
|
1767
1821
|
l.log.vaultIds !== void 0 ? String(l.log.vaultIds) : ""
|
|
1768
1822
|
]
|
|
1769
1823
|
]
|
|
1770
1824
|
)
|
|
1771
|
-
), l.archive && (
|
|
1772
|
-
|
|
1825
|
+
), l.archive && (A(i("command.log.detail.linked_archive")), console.log(
|
|
1826
|
+
oe(
|
|
1773
1827
|
[
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1828
|
+
i("command.log.detail.archive.table.id"),
|
|
1829
|
+
i("command.log.detail.archive.table.status"),
|
|
1830
|
+
i("command.log.detail.archive.table.vault"),
|
|
1831
|
+
i("command.log.detail.archive.table.item"),
|
|
1832
|
+
i("command.log.detail.archive.table.dir")
|
|
1779
1833
|
],
|
|
1780
1834
|
[
|
|
1781
1835
|
[
|
|
1782
1836
|
String(l.archive.id),
|
|
1783
|
-
|
|
1837
|
+
dt(l.archive.status),
|
|
1784
1838
|
String(l.archive.vaultId),
|
|
1785
1839
|
l.archive.item,
|
|
1786
1840
|
l.archive.directory
|
|
1787
1841
|
]
|
|
1788
1842
|
]
|
|
1789
1843
|
)
|
|
1790
|
-
)), l.vault && (
|
|
1791
|
-
|
|
1844
|
+
)), l.vault && (A(i("command.log.detail.linked_vault")), console.log(
|
|
1845
|
+
oe(
|
|
1792
1846
|
[
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1847
|
+
i("command.log.detail.vault.table.id"),
|
|
1848
|
+
i("command.log.detail.vault.table.name"),
|
|
1849
|
+
i("command.log.detail.vault.table.status"),
|
|
1850
|
+
i("command.log.detail.vault.table.remark")
|
|
1797
1851
|
],
|
|
1798
1852
|
[
|
|
1799
1853
|
[
|
|
1800
1854
|
String(l.vault.id),
|
|
1801
1855
|
l.vault.name,
|
|
1802
|
-
|
|
1856
|
+
aa(l.vault.status),
|
|
1803
1857
|
l.vault.remark
|
|
1804
1858
|
]
|
|
1805
1859
|
]
|
|
@@ -1807,30 +1861,30 @@ function qa(e, t) {
|
|
|
1807
1861
|
));
|
|
1808
1862
|
return;
|
|
1809
1863
|
}
|
|
1810
|
-
const n =
|
|
1864
|
+
const n = ea(a), o = await t.logService.getLogs(n);
|
|
1811
1865
|
if (o.length === 0) {
|
|
1812
|
-
|
|
1866
|
+
A(i("command.log.empty"));
|
|
1813
1867
|
return;
|
|
1814
1868
|
}
|
|
1815
1869
|
const s = o.map((c) => [
|
|
1816
1870
|
String(c.id),
|
|
1817
1871
|
c.operedAt,
|
|
1818
|
-
|
|
1872
|
+
Ue(c.level),
|
|
1819
1873
|
`${c.oper.main}${c.oper.sub ? `/${c.oper.sub}` : ""}`,
|
|
1820
1874
|
c.message,
|
|
1821
1875
|
c.archiveIds !== void 0 ? String(c.archiveIds) : "",
|
|
1822
1876
|
c.vaultIds !== void 0 ? String(c.vaultIds) : ""
|
|
1823
1877
|
]);
|
|
1824
1878
|
console.log(
|
|
1825
|
-
|
|
1879
|
+
oe(
|
|
1826
1880
|
[
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1881
|
+
i("command.log.table.id"),
|
|
1882
|
+
i("command.log.table.time"),
|
|
1883
|
+
i("command.log.table.level"),
|
|
1884
|
+
i("command.log.table.op"),
|
|
1885
|
+
i("command.log.table.message"),
|
|
1886
|
+
i("command.log.table.aid"),
|
|
1887
|
+
i("command.log.table.vid")
|
|
1834
1888
|
],
|
|
1835
1889
|
s
|
|
1836
1890
|
)
|
|
@@ -1838,22 +1892,22 @@ function qa(e, t) {
|
|
|
1838
1892
|
})
|
|
1839
1893
|
);
|
|
1840
1894
|
}
|
|
1841
|
-
async function
|
|
1895
|
+
async function Z(e) {
|
|
1842
1896
|
await w.mkdir(e, { recursive: !0 });
|
|
1843
1897
|
}
|
|
1844
|
-
const x = (e) => w.access(e).then(() => !0).catch(() => !1),
|
|
1845
|
-
function
|
|
1846
|
-
const a =
|
|
1847
|
-
return a.length > 0 && !a.startsWith("..") && !
|
|
1898
|
+
const x = (e) => w.access(e).then(() => !0).catch(() => !1), Ke = (e) => w.realpath(e).catch(() => h.resolve(e)), za = (e, t) => h.normalize(e) === h.normalize(t);
|
|
1899
|
+
function yt(e, t) {
|
|
1900
|
+
const a = h.relative(h.resolve(e), h.resolve(t));
|
|
1901
|
+
return a.length > 0 && !a.startsWith("..") && !h.isAbsolute(a);
|
|
1848
1902
|
}
|
|
1849
|
-
function
|
|
1850
|
-
return
|
|
1903
|
+
function Wa(e, t) {
|
|
1904
|
+
return za(e, t) || yt(e, t);
|
|
1851
1905
|
}
|
|
1852
|
-
async function
|
|
1853
|
-
const t =
|
|
1854
|
-
await
|
|
1906
|
+
async function ue(e) {
|
|
1907
|
+
const t = h.dirname(e);
|
|
1908
|
+
await Z(t), await x(e) || await w.writeFile(e, "", "utf8");
|
|
1855
1909
|
}
|
|
1856
|
-
async function
|
|
1910
|
+
async function ge(e) {
|
|
1857
1911
|
try {
|
|
1858
1912
|
return await w.lstat(e);
|
|
1859
1913
|
} catch (t) {
|
|
@@ -1862,7 +1916,7 @@ async function ve(e) {
|
|
|
1862
1916
|
throw t;
|
|
1863
1917
|
}
|
|
1864
1918
|
}
|
|
1865
|
-
async function
|
|
1919
|
+
async function Ja(e) {
|
|
1866
1920
|
try {
|
|
1867
1921
|
return (await w.readdir(e, { withFileTypes: !0 })).filter((a) => a.isDirectory()).map((a) => a.name);
|
|
1868
1922
|
} catch (t) {
|
|
@@ -1871,16 +1925,16 @@ async function za(e) {
|
|
|
1871
1925
|
throw t;
|
|
1872
1926
|
}
|
|
1873
1927
|
}
|
|
1874
|
-
class
|
|
1928
|
+
class bt extends Error {
|
|
1875
1929
|
constructor(t) {
|
|
1876
1930
|
super(
|
|
1877
|
-
|
|
1931
|
+
i("service.vault.error.removed_exists", {
|
|
1878
1932
|
name: t
|
|
1879
1933
|
})
|
|
1880
1934
|
), this.name = "VaultRemovedExistsError";
|
|
1881
1935
|
}
|
|
1882
1936
|
}
|
|
1883
|
-
class
|
|
1937
|
+
class Ga {
|
|
1884
1938
|
constructor(t, a) {
|
|
1885
1939
|
this.context = t, this.configService = a;
|
|
1886
1940
|
}
|
|
@@ -1890,96 +1944,96 @@ class Wa {
|
|
|
1890
1944
|
async createVault(t) {
|
|
1891
1945
|
const a = t.name.trim();
|
|
1892
1946
|
if (!a)
|
|
1893
|
-
throw new Error(
|
|
1894
|
-
if (a ===
|
|
1947
|
+
throw new Error(i("service.vault.error.name_empty"));
|
|
1948
|
+
if (a === f.Vault.name)
|
|
1895
1949
|
throw new Error(
|
|
1896
|
-
|
|
1897
|
-
name:
|
|
1950
|
+
i("service.vault.error.name_reserved", {
|
|
1951
|
+
name: f.Vault.name
|
|
1898
1952
|
})
|
|
1899
1953
|
);
|
|
1900
|
-
const
|
|
1901
|
-
if (n?.status ===
|
|
1954
|
+
const r = await this.context.loadVaults(), n = r.find((c) => c.name === a);
|
|
1955
|
+
if (n?.status === $.Valid || n?.status === $.Protected)
|
|
1902
1956
|
throw new Error(
|
|
1903
|
-
|
|
1957
|
+
i("service.vault.error.exists", {
|
|
1904
1958
|
name: a
|
|
1905
1959
|
})
|
|
1906
1960
|
);
|
|
1907
1961
|
if (n?.status === "Removed") {
|
|
1908
1962
|
if (!t.recoverRemoved)
|
|
1909
|
-
throw new
|
|
1910
|
-
return n.status =
|
|
1963
|
+
throw new bt(a);
|
|
1964
|
+
return n.status = $.Valid, await this.context.ensureVaultDir(n.id), await this.context.saveVaults(r), t.activate && await this.configService.setCurrentVault(n.id), { vault: n, recovered: !0 };
|
|
1911
1965
|
}
|
|
1912
1966
|
const s = {
|
|
1913
1967
|
id: await this.context.nextAutoIncrement("vaultId"),
|
|
1914
1968
|
name: a,
|
|
1915
1969
|
remark: t.remark ?? "",
|
|
1916
|
-
createdAt:
|
|
1917
|
-
status:
|
|
1970
|
+
createdAt: $e(),
|
|
1971
|
+
status: $.Valid
|
|
1918
1972
|
};
|
|
1919
|
-
return
|
|
1973
|
+
return r.push(s), await this.context.saveVaults(r), await this.context.ensureVaultDir(s.id), t.activate && await this.configService.setCurrentVault(s.id), { vault: s, recovered: !1 };
|
|
1920
1974
|
}
|
|
1921
1975
|
async useVault(t) {
|
|
1922
1976
|
const a = await this.context.resolveVault(t, { includeRemoved: !1, fallbackCurrent: !1 });
|
|
1923
1977
|
if (!a)
|
|
1924
1978
|
throw new Error(
|
|
1925
|
-
|
|
1979
|
+
i("service.vault.error.not_found", {
|
|
1926
1980
|
reference: t
|
|
1927
1981
|
})
|
|
1928
1982
|
);
|
|
1929
1983
|
if (a.status === "Removed")
|
|
1930
1984
|
throw new Error(
|
|
1931
|
-
|
|
1985
|
+
i("service.vault.error.removed", {
|
|
1932
1986
|
name: a.name
|
|
1933
1987
|
})
|
|
1934
1988
|
);
|
|
1935
1989
|
return await this.configService.setCurrentVault(a.id), a;
|
|
1936
1990
|
}
|
|
1937
1991
|
async recoverVault(t) {
|
|
1938
|
-
const a = await this.context.loadVaults(),
|
|
1939
|
-
if (!
|
|
1992
|
+
const a = await this.context.loadVaults(), r = a.find((n) => n.name === t || String(n.id) === t);
|
|
1993
|
+
if (!r)
|
|
1940
1994
|
throw new Error(
|
|
1941
|
-
|
|
1995
|
+
i("service.vault.error.not_found", {
|
|
1942
1996
|
reference: t
|
|
1943
1997
|
})
|
|
1944
1998
|
);
|
|
1945
|
-
if (
|
|
1999
|
+
if (r.status !== "Removed")
|
|
1946
2000
|
throw new Error(
|
|
1947
|
-
|
|
1948
|
-
name:
|
|
2001
|
+
i("service.vault.error.not_removed", {
|
|
2002
|
+
name: r.name
|
|
1949
2003
|
})
|
|
1950
2004
|
);
|
|
1951
|
-
return
|
|
2005
|
+
return r.status = $.Valid, await this.context.ensureVaultDir(r.id), await this.context.saveVaults(a), r;
|
|
1952
2006
|
}
|
|
1953
2007
|
async renameVault(t, a) {
|
|
1954
|
-
const
|
|
1955
|
-
if (!
|
|
1956
|
-
throw new Error(
|
|
1957
|
-
if (
|
|
2008
|
+
const r = a.trim();
|
|
2009
|
+
if (!r)
|
|
2010
|
+
throw new Error(i("service.vault.error.new_name_empty"));
|
|
2011
|
+
if (r === f.Vault.name)
|
|
1958
2012
|
throw new Error(
|
|
1959
|
-
|
|
1960
|
-
name:
|
|
2013
|
+
i("service.vault.error.name_reserved", {
|
|
2014
|
+
name: f.Vault.name
|
|
1961
2015
|
})
|
|
1962
2016
|
);
|
|
1963
2017
|
const n = await this.context.loadVaults(), o = n.find((c) => c.name === t || String(c.id) === t);
|
|
1964
2018
|
if (!o)
|
|
1965
2019
|
throw new Error(
|
|
1966
|
-
|
|
2020
|
+
i("service.vault.error.not_found", {
|
|
1967
2021
|
reference: t
|
|
1968
2022
|
})
|
|
1969
2023
|
);
|
|
1970
2024
|
if (o.status !== "Valid")
|
|
1971
2025
|
throw new Error(
|
|
1972
|
-
|
|
2026
|
+
i("service.vault.error.not_valid_state", {
|
|
1973
2027
|
name: o.name
|
|
1974
2028
|
})
|
|
1975
2029
|
);
|
|
1976
|
-
if (n.find((c) => c.name ===
|
|
2030
|
+
if (n.find((c) => c.name === r && c.id !== o.id))
|
|
1977
2031
|
throw new Error(
|
|
1978
|
-
|
|
1979
|
-
name:
|
|
2032
|
+
i("service.vault.error.name_conflict", {
|
|
2033
|
+
name: r
|
|
1980
2034
|
})
|
|
1981
2035
|
);
|
|
1982
|
-
return o.name =
|
|
2036
|
+
return o.name = r, await this.context.saveVaults(n), o;
|
|
1983
2037
|
}
|
|
1984
2038
|
async removeVault(t) {
|
|
1985
2039
|
const a = await this.context.resolveVault(t, {
|
|
@@ -1988,48 +2042,48 @@ class Wa {
|
|
|
1988
2042
|
});
|
|
1989
2043
|
if (!a)
|
|
1990
2044
|
throw new Error(
|
|
1991
|
-
|
|
2045
|
+
i("service.vault.error.not_found", {
|
|
1992
2046
|
reference: t
|
|
1993
2047
|
})
|
|
1994
2048
|
);
|
|
1995
|
-
if (a.id ===
|
|
1996
|
-
throw new Error(
|
|
1997
|
-
if (a.status ===
|
|
2049
|
+
if (a.id === f.Vault.id || a.status === $.Protected)
|
|
2050
|
+
throw new Error(i("service.vault.error.default_cannot_remove"));
|
|
2051
|
+
if (a.status === $.Removed)
|
|
1998
2052
|
throw new Error(
|
|
1999
|
-
|
|
2053
|
+
i("service.vault.error.already_removed", {
|
|
2000
2054
|
name: a.name
|
|
2001
2055
|
})
|
|
2002
2056
|
);
|
|
2003
|
-
const
|
|
2004
|
-
await this.context.ensureVaultDir(
|
|
2057
|
+
const r = await this.context.loadListEntries(), n = r.filter((d) => d.vaultId === a.id && d.status === C.Archived);
|
|
2058
|
+
await this.context.ensureVaultDir(f.Vault.id), await this.validateMoveToDefault(n);
|
|
2005
2059
|
const o = [];
|
|
2006
2060
|
for (const d of n) {
|
|
2007
|
-
const m = this.context.archivePath(a.id, d.id), u = this.context.archivePath(
|
|
2008
|
-
await w.rename(m, u), d.vaultId =
|
|
2061
|
+
const m = this.context.archivePath(a.id, d.id), u = this.context.archivePath(f.Vault.id, d.id);
|
|
2062
|
+
await w.rename(m, u), d.vaultId = f.Vault.id, o.push(d.id);
|
|
2009
2063
|
}
|
|
2010
2064
|
const s = await this.context.loadVaults(), c = s.find((d) => d.id === a.id);
|
|
2011
2065
|
if (!c)
|
|
2012
2066
|
throw new Error(
|
|
2013
|
-
|
|
2067
|
+
i("service.vault.error.not_found_while_saving", {
|
|
2014
2068
|
id: a.id
|
|
2015
2069
|
})
|
|
2016
2070
|
);
|
|
2017
|
-
c.status =
|
|
2071
|
+
c.status = $.Removed, await this.context.saveListEntries(r), await this.context.saveVaults(s);
|
|
2018
2072
|
const l = await this.context.loadConfig();
|
|
2019
|
-
return l.currentVaultId === a.id && (l.currentVaultId =
|
|
2073
|
+
return l.currentVaultId === a.id && (l.currentVaultId = f.Vault.id, await this.context.saveConfig(l)), { vault: c, movedArchiveIds: o };
|
|
2020
2074
|
}
|
|
2021
2075
|
async validateMoveToDefault(t) {
|
|
2022
2076
|
for (const a of t) {
|
|
2023
|
-
const
|
|
2024
|
-
if (!await x(
|
|
2077
|
+
const r = this.context.archivePath(a.vaultId, a.id), n = this.context.archivePath(f.Vault.id, a.id);
|
|
2078
|
+
if (!await x(r))
|
|
2025
2079
|
throw new Error(
|
|
2026
|
-
|
|
2027
|
-
path:
|
|
2080
|
+
i("service.vault.error.archived_object_missing", {
|
|
2081
|
+
path: r
|
|
2028
2082
|
})
|
|
2029
2083
|
);
|
|
2030
2084
|
if (await x(n))
|
|
2031
2085
|
throw new Error(
|
|
2032
|
-
|
|
2086
|
+
i("service.vault.error.default_contains_archive_id", {
|
|
2033
2087
|
id: a.id
|
|
2034
2088
|
})
|
|
2035
2089
|
);
|
|
@@ -2047,61 +2101,61 @@ class Wa {
|
|
|
2047
2101
|
return await x(a) ? (await w.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, s) => o - s) : [];
|
|
2048
2102
|
}
|
|
2049
2103
|
getVaultDisplay(t) {
|
|
2050
|
-
return t.id ===
|
|
2104
|
+
return t.id === f.Vault.id ? `${t.name}(${t.id})` : `${t.name}(${t.id})`;
|
|
2051
2105
|
}
|
|
2052
2106
|
vaultRoot(t) {
|
|
2053
|
-
return
|
|
2107
|
+
return h.join(_.Dir.vaults, String(t.id));
|
|
2054
2108
|
}
|
|
2055
2109
|
}
|
|
2056
|
-
async function
|
|
2057
|
-
const t =
|
|
2110
|
+
async function kt(e) {
|
|
2111
|
+
const t = jt.createInterface({ input: Ht, output: Yt });
|
|
2058
2112
|
try {
|
|
2059
2113
|
return (await t.question(e)).trim();
|
|
2060
2114
|
} finally {
|
|
2061
2115
|
t.close();
|
|
2062
2116
|
}
|
|
2063
2117
|
}
|
|
2064
|
-
async function
|
|
2065
|
-
const a = (await
|
|
2118
|
+
async function Xe(e, t = !0) {
|
|
2119
|
+
const a = (await kt(e)).toLowerCase();
|
|
2066
2120
|
return a ? ["y", "yes"].includes(a) : !t;
|
|
2067
2121
|
}
|
|
2068
|
-
function
|
|
2069
|
-
const a = e.command("vault").description(
|
|
2070
|
-
a.command("use").description(
|
|
2071
|
-
(
|
|
2072
|
-
const n = await t.vaultService.useVault(
|
|
2073
|
-
|
|
2074
|
-
|
|
2122
|
+
function Ka(e, t) {
|
|
2123
|
+
const a = e.command("vault").description(i("command.vault.description"));
|
|
2124
|
+
a.command("use").description(i("command.vault.use.description")).argument("<name-or-id>", i("command.vault.use.argument")).action(
|
|
2125
|
+
(r) => P(async () => {
|
|
2126
|
+
const n = await t.vaultService.useVault(r);
|
|
2127
|
+
T(
|
|
2128
|
+
i("command.vault.use.updated", {
|
|
2075
2129
|
name: n.name,
|
|
2076
2130
|
id: n.id
|
|
2077
2131
|
})
|
|
2078
2132
|
), await t.auditLogger.log(
|
|
2079
2133
|
"INFO",
|
|
2080
|
-
{ main: "vault", sub: "use", args: [
|
|
2081
|
-
|
|
2134
|
+
{ main: "vault", sub: "use", args: [r], source: "u" },
|
|
2135
|
+
i("command.vault.use.audit", {
|
|
2082
2136
|
name: n.name,
|
|
2083
2137
|
id: n.id
|
|
2084
2138
|
}),
|
|
2085
2139
|
{ vid: n.id }
|
|
2086
|
-
), await
|
|
2140
|
+
), await O(t);
|
|
2087
2141
|
})
|
|
2088
|
-
), a.command("create").description(
|
|
2089
|
-
(
|
|
2142
|
+
), a.command("create").description(i("command.vault.create.description")).argument("<name>", i("command.vault.create.argument")).option("-r, --remark <remark>", i("command.vault.create.option.remark")).option("-a, --activate", i("command.vault.create.option.activate")).action(
|
|
2143
|
+
(r, n) => P(async () => {
|
|
2090
2144
|
let o = !1;
|
|
2091
2145
|
const s = async (c) => {
|
|
2092
2146
|
const l = await t.vaultService.createVault({
|
|
2093
|
-
name:
|
|
2147
|
+
name: r,
|
|
2094
2148
|
remark: n.remark,
|
|
2095
2149
|
activate: n.activate,
|
|
2096
2150
|
recoverRemoved: c
|
|
2097
2151
|
});
|
|
2098
|
-
o = l.recovered,
|
|
2099
|
-
|
|
2152
|
+
o = l.recovered, T(
|
|
2153
|
+
i(o ? "command.vault.create.recovered" : "command.vault.create.created", {
|
|
2100
2154
|
name: l.vault.name,
|
|
2101
2155
|
id: l.vault.id
|
|
2102
2156
|
})
|
|
2103
|
-
), n.activate &&
|
|
2104
|
-
|
|
2157
|
+
), n.activate && T(
|
|
2158
|
+
i("command.vault.create.activated", {
|
|
2105
2159
|
name: l.vault.name,
|
|
2106
2160
|
id: l.vault.id
|
|
2107
2161
|
})
|
|
@@ -2110,13 +2164,13 @@ function Ja(e, t) {
|
|
|
2110
2164
|
{
|
|
2111
2165
|
main: "vault",
|
|
2112
2166
|
sub: o ? "recover" : "create",
|
|
2113
|
-
args: [
|
|
2167
|
+
args: [r],
|
|
2114
2168
|
opts: {
|
|
2115
2169
|
activate: !!n.activate
|
|
2116
2170
|
},
|
|
2117
2171
|
source: "u"
|
|
2118
2172
|
},
|
|
2119
|
-
|
|
2173
|
+
i(o ? "command.vault.create.recovered" : "command.vault.create.created", {
|
|
2120
2174
|
name: l.vault.name,
|
|
2121
2175
|
id: l.vault.id
|
|
2122
2176
|
}),
|
|
@@ -2126,71 +2180,71 @@ function Ja(e, t) {
|
|
|
2126
2180
|
try {
|
|
2127
2181
|
await s(!1);
|
|
2128
2182
|
} catch (c) {
|
|
2129
|
-
if (c instanceof
|
|
2130
|
-
if (!await
|
|
2131
|
-
|
|
2132
|
-
name:
|
|
2183
|
+
if (c instanceof bt) {
|
|
2184
|
+
if (!await Xe(
|
|
2185
|
+
i("command.vault.create.confirm_recover", {
|
|
2186
|
+
name: r
|
|
2133
2187
|
})
|
|
2134
2188
|
)) {
|
|
2135
|
-
|
|
2189
|
+
ye(i("command.vault.operation.cancelled"));
|
|
2136
2190
|
return;
|
|
2137
2191
|
}
|
|
2138
2192
|
await s(!0);
|
|
2139
2193
|
} else
|
|
2140
2194
|
throw c;
|
|
2141
2195
|
}
|
|
2142
|
-
await
|
|
2196
|
+
await O(t);
|
|
2143
2197
|
})
|
|
2144
|
-
), a.command("remove").description(
|
|
2145
|
-
(
|
|
2146
|
-
if (!await
|
|
2147
|
-
|
|
2148
|
-
nameOrId:
|
|
2198
|
+
), a.command("remove").description(i("command.vault.remove.description")).argument("<name-or-id>", i("command.vault.remove.argument")).action(
|
|
2199
|
+
(r) => P(async () => {
|
|
2200
|
+
if (!await Xe(
|
|
2201
|
+
i("command.vault.remove.confirm", {
|
|
2202
|
+
nameOrId: r
|
|
2149
2203
|
})
|
|
2150
2204
|
)) {
|
|
2151
|
-
|
|
2205
|
+
ye(i("command.vault.operation.cancelled"));
|
|
2152
2206
|
return;
|
|
2153
2207
|
}
|
|
2154
2208
|
const o = Math.random().toString(36).slice(2, 8).toUpperCase();
|
|
2155
|
-
if (await
|
|
2156
|
-
|
|
2209
|
+
if (await kt(
|
|
2210
|
+
i("command.vault.remove.verify_prompt", {
|
|
2157
2211
|
verifyCode: o
|
|
2158
2212
|
})
|
|
2159
2213
|
) !== o) {
|
|
2160
|
-
|
|
2214
|
+
ye(i("command.vault.remove.verify_mismatch"));
|
|
2161
2215
|
return;
|
|
2162
2216
|
}
|
|
2163
|
-
const c = await t.vaultService.removeVault(
|
|
2164
|
-
|
|
2165
|
-
|
|
2217
|
+
const c = await t.vaultService.removeVault(r);
|
|
2218
|
+
T(
|
|
2219
|
+
i("command.vault.remove.done", {
|
|
2166
2220
|
name: c.vault.name,
|
|
2167
2221
|
id: c.vault.id
|
|
2168
2222
|
})
|
|
2169
|
-
), c.movedArchiveIds.length > 0 &&
|
|
2170
|
-
|
|
2223
|
+
), c.movedArchiveIds.length > 0 && A(
|
|
2224
|
+
i("command.vault.remove.moved_to_default", {
|
|
2171
2225
|
count: c.movedArchiveIds.length,
|
|
2172
|
-
name:
|
|
2226
|
+
name: f.Vault.name
|
|
2173
2227
|
})
|
|
2174
2228
|
), await t.auditLogger.log(
|
|
2175
2229
|
"WARN",
|
|
2176
2230
|
{
|
|
2177
2231
|
main: "vault",
|
|
2178
2232
|
sub: "remove",
|
|
2179
|
-
args: [
|
|
2233
|
+
args: [r],
|
|
2180
2234
|
source: "u"
|
|
2181
2235
|
},
|
|
2182
|
-
|
|
2236
|
+
i("command.vault.remove.done", {
|
|
2183
2237
|
name: c.vault.name,
|
|
2184
2238
|
id: c.vault.id
|
|
2185
2239
|
}),
|
|
2186
2240
|
{ vid: c.vault.id }
|
|
2187
|
-
), await
|
|
2241
|
+
), await O(t);
|
|
2188
2242
|
})
|
|
2189
|
-
), a.command("recover").description(
|
|
2190
|
-
(
|
|
2191
|
-
const n = await t.vaultService.recoverVault(
|
|
2192
|
-
|
|
2193
|
-
|
|
2243
|
+
), a.command("recover").description(i("command.vault.recover.description")).argument("<name-or-id>", i("command.vault.recover.argument")).action(
|
|
2244
|
+
(r) => P(async () => {
|
|
2245
|
+
const n = await t.vaultService.recoverVault(r);
|
|
2246
|
+
T(
|
|
2247
|
+
i("command.vault.recover.done", {
|
|
2194
2248
|
name: n.name,
|
|
2195
2249
|
id: n.id
|
|
2196
2250
|
})
|
|
@@ -2199,21 +2253,21 @@ function Ja(e, t) {
|
|
|
2199
2253
|
{
|
|
2200
2254
|
main: "vault",
|
|
2201
2255
|
sub: "recover",
|
|
2202
|
-
args: [
|
|
2256
|
+
args: [r],
|
|
2203
2257
|
source: "u"
|
|
2204
2258
|
},
|
|
2205
|
-
|
|
2259
|
+
i("command.vault.recover.done", {
|
|
2206
2260
|
name: n.name,
|
|
2207
2261
|
id: n.id
|
|
2208
2262
|
}),
|
|
2209
2263
|
{ vid: n.id }
|
|
2210
|
-
), await
|
|
2264
|
+
), await O(t);
|
|
2211
2265
|
})
|
|
2212
|
-
), a.command("rename").description(
|
|
2213
|
-
(
|
|
2214
|
-
const o = await t.vaultService.renameVault(
|
|
2215
|
-
|
|
2216
|
-
|
|
2266
|
+
), a.command("rename").description(i("command.vault.rename.description")).argument("<old>", i("command.vault.rename.argument.old")).argument("<new>", i("command.vault.rename.argument.new")).action(
|
|
2267
|
+
(r, n) => P(async () => {
|
|
2268
|
+
const o = await t.vaultService.renameVault(r, n);
|
|
2269
|
+
T(
|
|
2270
|
+
i("command.vault.rename.done", {
|
|
2217
2271
|
name: o.name,
|
|
2218
2272
|
id: o.id
|
|
2219
2273
|
})
|
|
@@ -2222,21 +2276,21 @@ function Ja(e, t) {
|
|
|
2222
2276
|
{
|
|
2223
2277
|
main: "vault",
|
|
2224
2278
|
sub: "rename",
|
|
2225
|
-
args: [
|
|
2279
|
+
args: [r, n],
|
|
2226
2280
|
source: "u"
|
|
2227
2281
|
},
|
|
2228
|
-
|
|
2282
|
+
i("command.vault.rename.done", {
|
|
2229
2283
|
name: o.name,
|
|
2230
2284
|
id: o.id
|
|
2231
2285
|
}),
|
|
2232
2286
|
{ vid: o.id }
|
|
2233
|
-
), await
|
|
2287
|
+
), await O(t);
|
|
2234
2288
|
})
|
|
2235
|
-
), a.command("list").description(
|
|
2236
|
-
(
|
|
2237
|
-
const n = await t.vaultService.listVaults(!!
|
|
2289
|
+
), a.command("list").description(i("command.vault.list.description")).option("-a, --all", i("command.vault.list.option.all")).action(
|
|
2290
|
+
(r) => P(async () => {
|
|
2291
|
+
const n = await t.vaultService.listVaults(!!r.all);
|
|
2238
2292
|
if (n.length === 0) {
|
|
2239
|
-
|
|
2293
|
+
A(i("command.vault.list.empty"));
|
|
2240
2294
|
return;
|
|
2241
2295
|
}
|
|
2242
2296
|
const o = n.map((s) => `${String(s.id).padStart(3, " ")} ${s.name}`).join(`
|
|
@@ -2245,11 +2299,11 @@ function Ja(e, t) {
|
|
|
2245
2299
|
})
|
|
2246
2300
|
);
|
|
2247
2301
|
}
|
|
2248
|
-
function
|
|
2249
|
-
const t = new
|
|
2250
|
-
return t.name(
|
|
2302
|
+
function Xa(e) {
|
|
2303
|
+
const t = new Ft();
|
|
2304
|
+
return t.name(Qt).description(i("app.description")).version(e.version), ia(t, e), Ka(t, e), Ua(t, e), Ba(t, e), Ca(t, e), t;
|
|
2251
2305
|
}
|
|
2252
|
-
const
|
|
2306
|
+
const Qe = {
|
|
2253
2307
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2254
2308
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2255
2309
|
functionPattern: /(^|\n)\s*(function\s+)?arv\s*(\(\))?\s*\{/m,
|
|
@@ -2279,7 +2333,7 @@ const Ke = {
|
|
|
2279
2333
|
fi
|
|
2280
2334
|
return $status
|
|
2281
2335
|
}`
|
|
2282
|
-
},
|
|
2336
|
+
}, Qa = {
|
|
2283
2337
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2284
2338
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2285
2339
|
functionPattern: /(^|\n)\s*function\s+arv\b/m,
|
|
@@ -2314,7 +2368,7 @@ const Ke = {
|
|
|
2314
2368
|
rm -f $target_tmp
|
|
2315
2369
|
return $status
|
|
2316
2370
|
end`
|
|
2317
|
-
},
|
|
2371
|
+
}, Za = {
|
|
2318
2372
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2319
2373
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2320
2374
|
functionPattern: /(^|\r?\n)\s*function\s+arv\b/im,
|
|
@@ -2361,8 +2415,8 @@ end`
|
|
|
2361
2415
|
$global:LASTEXITCODE = $status
|
|
2362
2416
|
}`
|
|
2363
2417
|
};
|
|
2364
|
-
function
|
|
2365
|
-
const t =
|
|
2418
|
+
function er(e) {
|
|
2419
|
+
const t = h.basename(e).toLowerCase();
|
|
2366
2420
|
if (t.includes("bash"))
|
|
2367
2421
|
return "bash";
|
|
2368
2422
|
if (t.includes("zsh"))
|
|
@@ -2372,147 +2426,147 @@ function Qa(e) {
|
|
|
2372
2426
|
if (t.includes("pwsh") || t.includes("powershell"))
|
|
2373
2427
|
return "powershell";
|
|
2374
2428
|
}
|
|
2375
|
-
function
|
|
2429
|
+
function Ze(e) {
|
|
2376
2430
|
return e.endsWith(`
|
|
2377
2431
|
`) ? e : `${e}
|
|
2378
2432
|
`;
|
|
2379
2433
|
}
|
|
2380
|
-
function
|
|
2434
|
+
function Ct(e) {
|
|
2381
2435
|
return `${e.startMarker}
|
|
2382
2436
|
${e.body}
|
|
2383
2437
|
${e.endMarker}`;
|
|
2384
2438
|
}
|
|
2385
|
-
function
|
|
2439
|
+
function tr(e, t) {
|
|
2386
2440
|
const a = e.indexOf(t.startMarker);
|
|
2387
2441
|
if (a === -1)
|
|
2388
2442
|
return;
|
|
2389
|
-
const
|
|
2390
|
-
if (!(
|
|
2443
|
+
const r = e.indexOf(t.endMarker, a + t.startMarker.length);
|
|
2444
|
+
if (!(r === -1 || r <= a))
|
|
2391
2445
|
return {
|
|
2392
2446
|
start: a,
|
|
2393
|
-
end:
|
|
2447
|
+
end: r + t.endMarker.length
|
|
2394
2448
|
};
|
|
2395
2449
|
}
|
|
2396
|
-
function
|
|
2397
|
-
const a =
|
|
2450
|
+
function ar(e, t) {
|
|
2451
|
+
const a = Ct(t);
|
|
2398
2452
|
if (e.trim().length === 0)
|
|
2399
2453
|
return `${a}
|
|
2400
2454
|
`;
|
|
2401
|
-
const
|
|
2455
|
+
const r = e.endsWith(`
|
|
2402
2456
|
`) ? `
|
|
2403
2457
|
` : `
|
|
2404
2458
|
|
|
2405
2459
|
`;
|
|
2406
|
-
return `${e}${
|
|
2460
|
+
return `${e}${r}${a}
|
|
2407
2461
|
`;
|
|
2408
2462
|
}
|
|
2409
|
-
async function
|
|
2463
|
+
async function rr(e, t) {
|
|
2410
2464
|
for (const a of t) {
|
|
2411
|
-
const
|
|
2412
|
-
if (await x(
|
|
2413
|
-
return
|
|
2465
|
+
const r = h.join(e, a);
|
|
2466
|
+
if (await x(r))
|
|
2467
|
+
return r;
|
|
2414
2468
|
}
|
|
2415
|
-
return
|
|
2469
|
+
return h.join(e, t[0] ?? ".bashrc");
|
|
2416
2470
|
}
|
|
2417
|
-
async function
|
|
2418
|
-
await
|
|
2419
|
-
const a = await w.readFile(e, "utf8"),
|
|
2420
|
-
if (
|
|
2421
|
-
const o = a.slice(
|
|
2471
|
+
async function ce(e, t) {
|
|
2472
|
+
await ue(e);
|
|
2473
|
+
const a = await w.readFile(e, "utf8"), r = tr(a, t);
|
|
2474
|
+
if (r) {
|
|
2475
|
+
const o = a.slice(r.start, r.end), s = Ct(t);
|
|
2422
2476
|
if (o === s)
|
|
2423
2477
|
return !1;
|
|
2424
|
-
const c = `${a.slice(0,
|
|
2425
|
-
return await w.writeFile(e,
|
|
2478
|
+
const c = `${a.slice(0, r.start)}${s}${a.slice(r.end)}`;
|
|
2479
|
+
return await w.writeFile(e, Ze(c), "utf8"), !0;
|
|
2426
2480
|
}
|
|
2427
2481
|
if (t.functionPattern.test(a))
|
|
2428
2482
|
return !1;
|
|
2429
|
-
const n =
|
|
2483
|
+
const n = Ze(ar(a, t));
|
|
2430
2484
|
return await w.writeFile(e, n, "utf8"), !0;
|
|
2431
2485
|
}
|
|
2432
|
-
function
|
|
2433
|
-
const a =
|
|
2434
|
-
if (
|
|
2486
|
+
function ir(e, t) {
|
|
2487
|
+
const a = h.resolve(t), r = h.resolve(e);
|
|
2488
|
+
if (r === a)
|
|
2435
2489
|
return "~";
|
|
2436
|
-
const n = `${a}${
|
|
2437
|
-
return
|
|
2490
|
+
const n = `${a}${h.sep}`;
|
|
2491
|
+
return r.startsWith(n) ? `~${r.slice(a.length)}` : e;
|
|
2438
2492
|
}
|
|
2439
|
-
function
|
|
2493
|
+
function nr(e) {
|
|
2440
2494
|
return `'${e.replaceAll("'", "'\\''")}'`;
|
|
2441
2495
|
}
|
|
2442
|
-
function
|
|
2496
|
+
function or(e) {
|
|
2443
2497
|
return `'${e.replaceAll("'", "''")}'`;
|
|
2444
2498
|
}
|
|
2445
|
-
async function
|
|
2499
|
+
async function cr(e) {
|
|
2446
2500
|
if (process.platform === "win32") {
|
|
2447
2501
|
const t = [
|
|
2448
|
-
|
|
2449
|
-
|
|
2502
|
+
h.join(e, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1"),
|
|
2503
|
+
h.join(e, "Documents", "WindowsPowerShell", "Microsoft.PowerShell_profile.ps1")
|
|
2450
2504
|
];
|
|
2451
2505
|
for (const a of t)
|
|
2452
2506
|
if (await x(a))
|
|
2453
2507
|
return a;
|
|
2454
2508
|
return t[0];
|
|
2455
2509
|
}
|
|
2456
|
-
return
|
|
2510
|
+
return h.join(e, ".config", "powershell", "Microsoft.PowerShell_profile.ps1");
|
|
2457
2511
|
}
|
|
2458
|
-
function
|
|
2459
|
-
const n =
|
|
2512
|
+
function se(e, t, a, r) {
|
|
2513
|
+
const n = ir(t, a);
|
|
2460
2514
|
return e === "powershell" ? {
|
|
2461
|
-
installed:
|
|
2515
|
+
installed: r,
|
|
2462
2516
|
shell: e,
|
|
2463
2517
|
profilePath: n,
|
|
2464
|
-
reloadCommand: `. ${
|
|
2518
|
+
reloadCommand: `. ${or(t)}`
|
|
2465
2519
|
} : {
|
|
2466
|
-
installed:
|
|
2520
|
+
installed: r,
|
|
2467
2521
|
shell: e,
|
|
2468
2522
|
profilePath: n,
|
|
2469
|
-
reloadCommand: `source ${
|
|
2523
|
+
reloadCommand: `source ${nr(t)}`
|
|
2470
2524
|
};
|
|
2471
2525
|
}
|
|
2472
|
-
async function
|
|
2526
|
+
async function sr(e = {}) {
|
|
2473
2527
|
const t = e.env ?? process.env;
|
|
2474
2528
|
if (t.ARCHIVER_DISABLE_SHELL_INIT === "1")
|
|
2475
2529
|
return { installed: !1 };
|
|
2476
2530
|
if (!(e.stdinIsTTY ?? !!process.stdin.isTTY))
|
|
2477
2531
|
return { installed: !1 };
|
|
2478
|
-
const
|
|
2479
|
-
if (!
|
|
2532
|
+
const r = e.homeDir ?? t.HOME ?? t.USERPROFILE ?? ct.homedir();
|
|
2533
|
+
if (!r)
|
|
2480
2534
|
return { installed: !1 };
|
|
2481
|
-
const n = e.shellPath ?? t.SHELL ?? "", o =
|
|
2535
|
+
const n = e.shellPath ?? t.SHELL ?? "", o = er(n);
|
|
2482
2536
|
if (!o)
|
|
2483
2537
|
return { installed: !1 };
|
|
2484
2538
|
try {
|
|
2485
2539
|
if (o === "bash") {
|
|
2486
|
-
const l = await
|
|
2487
|
-
return
|
|
2540
|
+
const l = await rr(r, [".bashrc", ".bash_profile", ".profile"]), d = await ce(l, Qe);
|
|
2541
|
+
return se(o, l, r, d);
|
|
2488
2542
|
}
|
|
2489
2543
|
if (o === "zsh") {
|
|
2490
|
-
const l =
|
|
2491
|
-
return
|
|
2544
|
+
const l = h.join(r, ".zshrc"), d = await ce(l, Qe);
|
|
2545
|
+
return se(o, l, r, d);
|
|
2492
2546
|
}
|
|
2493
2547
|
if (o === "fish") {
|
|
2494
|
-
const l =
|
|
2495
|
-
await
|
|
2496
|
-
const d = await
|
|
2497
|
-
return
|
|
2548
|
+
const l = h.join(r, ".config", "fish", "functions", "arv.fish");
|
|
2549
|
+
await Z(h.dirname(l));
|
|
2550
|
+
const d = await ce(l, Qa);
|
|
2551
|
+
return se(o, l, r, d);
|
|
2498
2552
|
}
|
|
2499
|
-
const s = await
|
|
2500
|
-
await
|
|
2501
|
-
const c = await
|
|
2502
|
-
return
|
|
2553
|
+
const s = await cr(r);
|
|
2554
|
+
await Z(h.dirname(s));
|
|
2555
|
+
const c = await ce(s, Za);
|
|
2556
|
+
return se(o, s, r, c);
|
|
2503
2557
|
} catch {
|
|
2504
2558
|
return { installed: !1 };
|
|
2505
2559
|
}
|
|
2506
2560
|
}
|
|
2507
|
-
async function
|
|
2561
|
+
async function pe(e) {
|
|
2508
2562
|
try {
|
|
2509
2563
|
const t = await w.readFile(e, "utf8");
|
|
2510
|
-
return t.trim() ? t.split(/\r?\n/).map((
|
|
2564
|
+
return t.trim() ? t.split(/\r?\n/).map((r) => r.trim()).filter((r) => r.length > 0).map((r, n) => {
|
|
2511
2565
|
try {
|
|
2512
|
-
return JSON.parse(
|
|
2566
|
+
return JSON.parse(r);
|
|
2513
2567
|
} catch {
|
|
2514
2568
|
throw new Error(
|
|
2515
|
-
|
|
2569
|
+
i("util.json.error.invalid_jsonl_line", {
|
|
2516
2570
|
line: n + 1,
|
|
2517
2571
|
filePath: e
|
|
2518
2572
|
})
|
|
@@ -2525,35 +2579,35 @@ async function he(e) {
|
|
|
2525
2579
|
throw t;
|
|
2526
2580
|
}
|
|
2527
2581
|
}
|
|
2528
|
-
async function
|
|
2529
|
-
const a = t.map((
|
|
2582
|
+
async function et(e, t) {
|
|
2583
|
+
const a = t.map((r) => JSON.stringify(r)).join(`
|
|
2530
2584
|
`);
|
|
2531
2585
|
await w.writeFile(e, a.length > 0 ? `${a}
|
|
2532
2586
|
` : "", "utf8");
|
|
2533
2587
|
}
|
|
2534
|
-
async function
|
|
2588
|
+
async function Et(e, t) {
|
|
2535
2589
|
await w.appendFile(e, `${JSON.stringify(t)}
|
|
2536
2590
|
`, "utf8");
|
|
2537
2591
|
}
|
|
2538
|
-
function
|
|
2592
|
+
function tt(e) {
|
|
2539
2593
|
return {
|
|
2540
|
-
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId :
|
|
2594
|
+
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId : f.Config.currentVaultId,
|
|
2541
2595
|
updateCheck: e.updateCheck === "off" ? "off" : "on",
|
|
2542
2596
|
lastUpdateCheck: typeof e.lastUpdateCheck == "string" ? e.lastUpdateCheck : "",
|
|
2543
|
-
vaultItemSeparator: typeof e.vaultItemSeparator == "string" && e.vaultItemSeparator.length > 0 ? e.vaultItemSeparator :
|
|
2597
|
+
vaultItemSeparator: typeof e.vaultItemSeparator == "string" && e.vaultItemSeparator.length > 0 ? e.vaultItemSeparator : f.Config.vaultItemSeparator,
|
|
2544
2598
|
style: e.style === "off" ? "off" : "on",
|
|
2545
2599
|
language: e.language === "en" ? "en" : "zh",
|
|
2546
2600
|
noCommandAction: e.noCommandAction === "help" || e.noCommandAction === "list" ? e.noCommandAction : "unknown"
|
|
2547
2601
|
};
|
|
2548
2602
|
}
|
|
2549
|
-
function
|
|
2603
|
+
function at(e) {
|
|
2550
2604
|
return {
|
|
2551
2605
|
logId: Number.isInteger(e.logId) && e.logId >= 0 ? e.logId : 0,
|
|
2552
2606
|
vaultId: Number.isInteger(e.vaultId) && e.vaultId >= 0 ? e.vaultId : 0,
|
|
2553
2607
|
archiveId: Number.isInteger(e.archiveId) && e.archiveId >= 0 ? e.archiveId : 0
|
|
2554
2608
|
};
|
|
2555
2609
|
}
|
|
2556
|
-
function
|
|
2610
|
+
function rt(e) {
|
|
2557
2611
|
const t = e.isDirectory === 1 ? 1 : 0, a = e.status === C.Restored ? C.Restored : C.Archived;
|
|
2558
2612
|
return {
|
|
2559
2613
|
archivedAt: String(e.archivedAt ?? ""),
|
|
@@ -2567,8 +2621,8 @@ function tt(e) {
|
|
|
2567
2621
|
remark: String(e.remark ?? "")
|
|
2568
2622
|
};
|
|
2569
2623
|
}
|
|
2570
|
-
function
|
|
2571
|
-
const t =
|
|
2624
|
+
function it(e) {
|
|
2625
|
+
const t = $[e.status] ?? $.Valid;
|
|
2572
2626
|
return {
|
|
2573
2627
|
id: e.id,
|
|
2574
2628
|
name: e.name ?? "",
|
|
@@ -2577,35 +2631,35 @@ function at(e) {
|
|
|
2577
2631
|
status: t
|
|
2578
2632
|
};
|
|
2579
2633
|
}
|
|
2580
|
-
class
|
|
2634
|
+
class lr {
|
|
2581
2635
|
configCache;
|
|
2582
2636
|
autoIncrCache;
|
|
2583
2637
|
listCache;
|
|
2584
2638
|
vaultCache;
|
|
2585
2639
|
async init() {
|
|
2586
2640
|
for (const a of Object.values(_.Dir))
|
|
2587
|
-
await
|
|
2588
|
-
await
|
|
2641
|
+
await Z(a);
|
|
2642
|
+
await Z(this.vaultDir(f.Vault.id)), await Ye(_.File.config, Ce), await Ye(_.File.autoIncr, Ee), await ue(_.File.list), await ue(_.File.vaults), await ue(_.File.log);
|
|
2589
2643
|
const t = await this.loadConfig();
|
|
2590
|
-
t.currentVaultId === 0 || await x(this.vaultDir(t.currentVaultId)) || (t.currentVaultId =
|
|
2644
|
+
t.currentVaultId === 0 || await x(this.vaultDir(t.currentVaultId)) || (t.currentVaultId = f.Vault.id, await this.saveConfig(t));
|
|
2591
2645
|
}
|
|
2592
2646
|
async loadConfig(t = !1) {
|
|
2593
2647
|
if (this.configCache && !t)
|
|
2594
2648
|
return this.configCache;
|
|
2595
|
-
const a = await
|
|
2596
|
-
return
|
|
2649
|
+
const a = await Ae(_.File.config, f.Config), r = tt({ ...f.Config, ...a });
|
|
2650
|
+
return me(r.language), this.configCache = r, r;
|
|
2597
2651
|
}
|
|
2598
2652
|
async saveConfig(t) {
|
|
2599
|
-
this.configCache =
|
|
2653
|
+
this.configCache = tt(t), me(this.configCache.language), await He(_.File.config, this.configCache, Ce);
|
|
2600
2654
|
}
|
|
2601
2655
|
async loadAutoIncr(t = !1) {
|
|
2602
2656
|
if (this.autoIncrCache && !t)
|
|
2603
2657
|
return this.autoIncrCache;
|
|
2604
|
-
const a = await
|
|
2605
|
-
return this.autoIncrCache =
|
|
2658
|
+
const a = await Ae(_.File.autoIncr, f.AutoIncr), r = at({ ...f.AutoIncr, ...a });
|
|
2659
|
+
return this.autoIncrCache = r, r;
|
|
2606
2660
|
}
|
|
2607
2661
|
async saveAutoIncr(t) {
|
|
2608
|
-
this.autoIncrCache =
|
|
2662
|
+
this.autoIncrCache = at(t), await He(_.File.autoIncr, this.autoIncrCache, Ee);
|
|
2609
2663
|
}
|
|
2610
2664
|
async nextAutoIncrement(t) {
|
|
2611
2665
|
const a = await this.loadAutoIncr();
|
|
@@ -2614,38 +2668,38 @@ class ci {
|
|
|
2614
2668
|
async loadListEntries(t = !1) {
|
|
2615
2669
|
if (this.listCache && !t)
|
|
2616
2670
|
return this.listCache;
|
|
2617
|
-
const a = await
|
|
2618
|
-
return this.listCache = a.map((
|
|
2671
|
+
const a = await pe(_.File.list);
|
|
2672
|
+
return this.listCache = a.map((r) => rt(r)).filter((r) => Number.isInteger(r.id) && r.id > 0), this.listCache.sort((r, n) => r.id - n.id), this.listCache;
|
|
2619
2673
|
}
|
|
2620
2674
|
async saveListEntries(t) {
|
|
2621
|
-
this.listCache = [...t].sort((a,
|
|
2675
|
+
this.listCache = [...t].sort((a, r) => a.id - r.id), await et(_.File.list, this.listCache);
|
|
2622
2676
|
}
|
|
2623
2677
|
async appendListEntry(t) {
|
|
2624
|
-
const a =
|
|
2625
|
-
this.listCache || (this.listCache = await this.loadListEntries()), this.listCache.push(a), this.listCache.sort((
|
|
2678
|
+
const a = rt(t);
|
|
2679
|
+
this.listCache || (this.listCache = await this.loadListEntries()), this.listCache.push(a), this.listCache.sort((r, n) => r.id - n.id), await Et(_.File.list, a);
|
|
2626
2680
|
}
|
|
2627
2681
|
async loadVaults(t = !1) {
|
|
2628
2682
|
if (this.vaultCache && !t)
|
|
2629
2683
|
return this.vaultCache;
|
|
2630
|
-
const a = await
|
|
2631
|
-
return this.vaultCache = a.map((
|
|
2684
|
+
const a = await pe(_.File.vaults);
|
|
2685
|
+
return this.vaultCache = a.map((r) => it(r)).filter((r) => Number.isInteger(r.id) && r.id > 0).sort((r, n) => r.id - n.id), this.vaultCache;
|
|
2632
2686
|
}
|
|
2633
2687
|
async saveVaults(t) {
|
|
2634
|
-
const a = t.map((
|
|
2635
|
-
this.vaultCache = a, await
|
|
2688
|
+
const a = t.map((r) => it(r)).filter((r) => r.id > 0).sort((r, n) => r.id - n.id);
|
|
2689
|
+
this.vaultCache = a, await et(_.File.vaults, a);
|
|
2636
2690
|
}
|
|
2637
2691
|
async getVaults(t) {
|
|
2638
|
-
const a = t?.includeRemoved ?? !1,
|
|
2639
|
-
return
|
|
2692
|
+
const a = t?.includeRemoved ?? !1, r = t?.withDefault ?? !0, n = await this.loadVaults(), o = a ? n : n.filter((s) => s.status === "Valid");
|
|
2693
|
+
return r ? [
|
|
2640
2694
|
{
|
|
2641
|
-
...
|
|
2642
|
-
remark:
|
|
2695
|
+
...f.Vault,
|
|
2696
|
+
remark: i("defaults.vault.remark")
|
|
2643
2697
|
},
|
|
2644
2698
|
...o
|
|
2645
2699
|
] : o;
|
|
2646
2700
|
}
|
|
2647
2701
|
async resolveVault(t, a) {
|
|
2648
|
-
const
|
|
2702
|
+
const r = a?.includeRemoved ?? !1, n = a?.fallbackCurrent ?? !0, o = await this.getVaults({ includeRemoved: !0, withDefault: !0 });
|
|
2649
2703
|
let s = t;
|
|
2650
2704
|
if ((s == null || s === "") && n && (s = (await this.loadConfig()).currentVaultId), s == null || s === "")
|
|
2651
2705
|
return;
|
|
@@ -2657,21 +2711,21 @@ class ci {
|
|
|
2657
2711
|
c = o.find((d) => d.id === l);
|
|
2658
2712
|
} else
|
|
2659
2713
|
c = o.find((l) => l.name === s);
|
|
2660
|
-
if (c && !(!
|
|
2714
|
+
if (c && !(!r && c.status === "Removed"))
|
|
2661
2715
|
return c;
|
|
2662
2716
|
}
|
|
2663
2717
|
vaultDir(t) {
|
|
2664
|
-
return
|
|
2718
|
+
return h.join(_.Dir.vaults, String(t));
|
|
2665
2719
|
}
|
|
2666
2720
|
archivePath(t, a) {
|
|
2667
|
-
return
|
|
2721
|
+
return h.join(this.vaultDir(t), String(a));
|
|
2668
2722
|
}
|
|
2669
|
-
archiveObjectPath(t, a,
|
|
2670
|
-
return
|
|
2723
|
+
archiveObjectPath(t, a, r) {
|
|
2724
|
+
return h.join(this.archivePath(t, a), r);
|
|
2671
2725
|
}
|
|
2672
2726
|
async resolveArchiveStorageLocation(t) {
|
|
2673
|
-
const a = this.archivePath(t.vaultId, t.id),
|
|
2674
|
-
if (!
|
|
2727
|
+
const a = this.archivePath(t.vaultId, t.id), r = await ge(a);
|
|
2728
|
+
if (!r || !r.isDirectory())
|
|
2675
2729
|
return;
|
|
2676
2730
|
const n = this.archiveObjectPath(t.vaultId, t.id, t.item);
|
|
2677
2731
|
if (await x(n))
|
|
@@ -2681,45 +2735,45 @@ class ci {
|
|
|
2681
2735
|
};
|
|
2682
2736
|
}
|
|
2683
2737
|
async ensureVaultDir(t) {
|
|
2684
|
-
await
|
|
2738
|
+
await Z(this.vaultDir(t));
|
|
2685
2739
|
}
|
|
2686
2740
|
async removeVaultDir(t) {
|
|
2687
|
-
t !==
|
|
2741
|
+
t !== f.Vault.id && await w.rm(this.vaultDir(t), { recursive: !0, force: !0 });
|
|
2688
2742
|
}
|
|
2689
2743
|
}
|
|
2690
|
-
class
|
|
2744
|
+
class dr {
|
|
2691
2745
|
constructor(t, a) {
|
|
2692
2746
|
this.context = t, this.logger = a;
|
|
2693
2747
|
}
|
|
2694
2748
|
async put(t, a) {
|
|
2695
2749
|
if (t.length === 0)
|
|
2696
|
-
throw new Error(
|
|
2697
|
-
const
|
|
2698
|
-
await this.context.ensureVaultDir(
|
|
2750
|
+
throw new Error(i("service.archive.error.at_least_one_item"));
|
|
2751
|
+
const r = await this.resolveTargetVault(a.vault);
|
|
2752
|
+
await this.context.ensureVaultDir(r.id);
|
|
2699
2753
|
const n = await this.preValidatePutItems(t);
|
|
2700
|
-
await this.preValidatePutSlots(
|
|
2754
|
+
await this.preValidatePutSlots(r.id, n.length);
|
|
2701
2755
|
const o = { ok: [], failed: [] };
|
|
2702
2756
|
for (const s of n) {
|
|
2703
|
-
const c = await this.context.nextAutoIncrement("archiveId"), l = this.context.archivePath(
|
|
2704
|
-
archivedAt:
|
|
2757
|
+
const c = await this.context.nextAutoIncrement("archiveId"), l = this.context.archivePath(r.id, c), d = {
|
|
2758
|
+
archivedAt: $e(),
|
|
2705
2759
|
status: C.Archived,
|
|
2706
2760
|
isDirectory: s.stats.isDirectory() ? 1 : 0,
|
|
2707
|
-
vaultId:
|
|
2761
|
+
vaultId: r.id,
|
|
2708
2762
|
id: c,
|
|
2709
|
-
item:
|
|
2710
|
-
directory:
|
|
2763
|
+
item: h.basename(s.resolvedPath),
|
|
2764
|
+
directory: h.dirname(s.resolvedPath),
|
|
2711
2765
|
message: a.message ?? "",
|
|
2712
2766
|
remark: a.remark ?? ""
|
|
2713
2767
|
};
|
|
2714
2768
|
try {
|
|
2715
2769
|
if (await x(l))
|
|
2716
2770
|
throw new Error(
|
|
2717
|
-
|
|
2771
|
+
i("service.archive.error.slot_exists", {
|
|
2718
2772
|
path: l
|
|
2719
2773
|
})
|
|
2720
2774
|
);
|
|
2721
2775
|
await w.mkdir(l, { recursive: !1 });
|
|
2722
|
-
const m = this.context.archiveObjectPath(
|
|
2776
|
+
const m = this.context.archiveObjectPath(r.id, c, d.item);
|
|
2723
2777
|
try {
|
|
2724
2778
|
await w.rename(s.resolvedPath, m);
|
|
2725
2779
|
} catch (u) {
|
|
@@ -2732,21 +2786,21 @@ class si {
|
|
|
2732
2786
|
main: "put",
|
|
2733
2787
|
args: [s.input],
|
|
2734
2788
|
opts: {
|
|
2735
|
-
vault: a.vault ??
|
|
2789
|
+
vault: a.vault ?? r.id
|
|
2736
2790
|
},
|
|
2737
2791
|
source: a.source ?? "u"
|
|
2738
2792
|
},
|
|
2739
|
-
|
|
2793
|
+
i("service.archive.log.archived", {
|
|
2740
2794
|
input: s.input
|
|
2741
2795
|
}),
|
|
2742
|
-
{ aid: c, vid:
|
|
2796
|
+
{ aid: c, vid: r.id }
|
|
2743
2797
|
), o.ok.push({
|
|
2744
2798
|
id: c,
|
|
2745
2799
|
input: s.input,
|
|
2746
2800
|
success: !0,
|
|
2747
|
-
message:
|
|
2748
|
-
name:
|
|
2749
|
-
id:
|
|
2801
|
+
message: i("service.archive.result.archived_to_vault", {
|
|
2802
|
+
name: r.name,
|
|
2803
|
+
id: r.id
|
|
2750
2804
|
})
|
|
2751
2805
|
});
|
|
2752
2806
|
} catch (m) {
|
|
@@ -2757,11 +2811,11 @@ class si {
|
|
|
2757
2811
|
main: "put",
|
|
2758
2812
|
args: [s.input],
|
|
2759
2813
|
opts: {
|
|
2760
|
-
vault: a.vault ??
|
|
2814
|
+
vault: a.vault ?? r.id
|
|
2761
2815
|
},
|
|
2762
2816
|
source: a.source ?? "u"
|
|
2763
2817
|
},
|
|
2764
|
-
|
|
2818
|
+
i("service.archive.log.archive_failed", {
|
|
2765
2819
|
input: s.input,
|
|
2766
2820
|
message: u
|
|
2767
2821
|
})
|
|
@@ -2777,19 +2831,19 @@ class si {
|
|
|
2777
2831
|
}
|
|
2778
2832
|
async restore(t) {
|
|
2779
2833
|
if (t.length === 0)
|
|
2780
|
-
throw new Error(
|
|
2781
|
-
const a = await this.context.loadListEntries(),
|
|
2834
|
+
throw new Error(i("service.archive.error.at_least_one_id"));
|
|
2835
|
+
const a = await this.context.loadListEntries(), r = new Map(a.map((s) => [s.id, s]));
|
|
2782
2836
|
for (const s of t) {
|
|
2783
|
-
const c =
|
|
2837
|
+
const c = r.get(s);
|
|
2784
2838
|
if (!c)
|
|
2785
2839
|
throw new Error(
|
|
2786
|
-
|
|
2840
|
+
i("service.archive.error.id_not_exists", {
|
|
2787
2841
|
id: s
|
|
2788
2842
|
})
|
|
2789
2843
|
);
|
|
2790
2844
|
if (c.status !== C.Archived)
|
|
2791
2845
|
throw new Error(
|
|
2792
|
-
|
|
2846
|
+
i("service.archive.error.id_already_restored", {
|
|
2793
2847
|
id: s
|
|
2794
2848
|
})
|
|
2795
2849
|
);
|
|
@@ -2797,26 +2851,26 @@ class si {
|
|
|
2797
2851
|
const n = { ok: [], failed: [] };
|
|
2798
2852
|
let o = !1;
|
|
2799
2853
|
for (const s of t) {
|
|
2800
|
-
const c =
|
|
2854
|
+
const c = r.get(s);
|
|
2801
2855
|
if (!c) {
|
|
2802
2856
|
n.failed.push({
|
|
2803
2857
|
input: String(s),
|
|
2804
2858
|
success: !1,
|
|
2805
|
-
message:
|
|
2859
|
+
message: i("service.archive.error.id_not_found_short")
|
|
2806
2860
|
});
|
|
2807
2861
|
continue;
|
|
2808
2862
|
}
|
|
2809
|
-
const l = await this.context.resolveArchiveStorageLocation(c), d =
|
|
2863
|
+
const l = await this.context.resolveArchiveStorageLocation(c), d = h.join(c.directory, c.item);
|
|
2810
2864
|
try {
|
|
2811
2865
|
if (!l)
|
|
2812
2866
|
throw new Error(
|
|
2813
|
-
|
|
2867
|
+
i("service.archive.error.object_missing", {
|
|
2814
2868
|
path: this.context.archivePath(c.vaultId, c.id)
|
|
2815
2869
|
})
|
|
2816
2870
|
);
|
|
2817
2871
|
if (await x(d))
|
|
2818
2872
|
throw new Error(
|
|
2819
|
-
|
|
2873
|
+
i("service.archive.error.restore_target_exists", {
|
|
2820
2874
|
path: d
|
|
2821
2875
|
})
|
|
2822
2876
|
);
|
|
@@ -2830,13 +2884,13 @@ class si {
|
|
|
2830
2884
|
args: [String(s)],
|
|
2831
2885
|
source: "u"
|
|
2832
2886
|
},
|
|
2833
|
-
|
|
2887
|
+
i("service.archive.log.restored", { id: s }),
|
|
2834
2888
|
{ aid: s, vid: c.vaultId }
|
|
2835
2889
|
), n.ok.push({
|
|
2836
2890
|
id: s,
|
|
2837
2891
|
input: String(s),
|
|
2838
2892
|
success: !0,
|
|
2839
|
-
message:
|
|
2893
|
+
message: i("service.archive.result.restored_to", { path: d })
|
|
2840
2894
|
});
|
|
2841
2895
|
} catch (m) {
|
|
2842
2896
|
const u = m.message;
|
|
@@ -2847,7 +2901,7 @@ class si {
|
|
|
2847
2901
|
args: [String(s)],
|
|
2848
2902
|
source: "u"
|
|
2849
2903
|
},
|
|
2850
|
-
|
|
2904
|
+
i("service.archive.log.restore_failed", { id: s, message: u }),
|
|
2851
2905
|
{ aid: s, vid: c.vaultId }
|
|
2852
2906
|
), n.failed.push({
|
|
2853
2907
|
id: s,
|
|
@@ -2861,51 +2915,51 @@ class si {
|
|
|
2861
2915
|
}
|
|
2862
2916
|
async move(t, a) {
|
|
2863
2917
|
if (t.length === 0)
|
|
2864
|
-
throw new Error(
|
|
2865
|
-
const
|
|
2918
|
+
throw new Error(i("service.archive.error.at_least_one_id"));
|
|
2919
|
+
const r = await this.context.resolveVault(a, {
|
|
2866
2920
|
includeRemoved: !1,
|
|
2867
2921
|
fallbackCurrent: !1
|
|
2868
2922
|
});
|
|
2869
|
-
if (!
|
|
2923
|
+
if (!r)
|
|
2870
2924
|
throw new Error(
|
|
2871
|
-
|
|
2925
|
+
i("service.archive.error.target_vault_not_found", {
|
|
2872
2926
|
vault: a
|
|
2873
2927
|
})
|
|
2874
2928
|
);
|
|
2875
|
-
await this.context.ensureVaultDir(
|
|
2929
|
+
await this.context.ensureVaultDir(r.id);
|
|
2876
2930
|
const n = await this.context.loadListEntries(), o = new Map(n.map((d) => [d.id, d])), s = /* @__PURE__ */ new Map();
|
|
2877
2931
|
for (const d of t) {
|
|
2878
2932
|
const m = o.get(d);
|
|
2879
2933
|
if (!m)
|
|
2880
2934
|
throw new Error(
|
|
2881
|
-
|
|
2935
|
+
i("service.archive.error.id_not_exists", {
|
|
2882
2936
|
id: d
|
|
2883
2937
|
})
|
|
2884
2938
|
);
|
|
2885
2939
|
if (m.status !== C.Archived)
|
|
2886
2940
|
throw new Error(
|
|
2887
|
-
|
|
2941
|
+
i("service.archive.error.id_restored_cannot_move", {
|
|
2888
2942
|
id: d
|
|
2889
2943
|
})
|
|
2890
2944
|
);
|
|
2891
|
-
if (m.vaultId ===
|
|
2945
|
+
if (m.vaultId === r.id)
|
|
2892
2946
|
throw new Error(
|
|
2893
|
-
|
|
2947
|
+
i("service.archive.error.id_already_in_vault", {
|
|
2894
2948
|
id: d,
|
|
2895
|
-
vault:
|
|
2949
|
+
vault: r.name
|
|
2896
2950
|
})
|
|
2897
2951
|
);
|
|
2898
|
-
const u = await this.context.resolveArchiveStorageLocation(m),
|
|
2952
|
+
const u = await this.context.resolveArchiveStorageLocation(m), g = this.context.archivePath(m.vaultId, m.id), p = this.context.archivePath(r.id, m.id);
|
|
2899
2953
|
if (!u)
|
|
2900
2954
|
throw new Error(
|
|
2901
|
-
|
|
2902
|
-
path:
|
|
2955
|
+
i("service.archive.error.object_missing", {
|
|
2956
|
+
path: g
|
|
2903
2957
|
})
|
|
2904
2958
|
);
|
|
2905
|
-
if (await x(
|
|
2959
|
+
if (await x(p))
|
|
2906
2960
|
throw new Error(
|
|
2907
|
-
|
|
2908
|
-
path:
|
|
2961
|
+
i("service.archive.error.target_slot_exists", {
|
|
2962
|
+
path: p
|
|
2909
2963
|
})
|
|
2910
2964
|
);
|
|
2911
2965
|
s.set(d, u);
|
|
@@ -2922,55 +2976,55 @@ class si {
|
|
|
2922
2976
|
id: d,
|
|
2923
2977
|
input: String(d),
|
|
2924
2978
|
success: !1,
|
|
2925
|
-
message:
|
|
2979
|
+
message: i("service.archive.error.object_missing_short")
|
|
2926
2980
|
});
|
|
2927
2981
|
continue;
|
|
2928
2982
|
}
|
|
2929
|
-
const
|
|
2983
|
+
const g = this.context.archivePath(r.id, m.id), p = m.vaultId;
|
|
2930
2984
|
try {
|
|
2931
|
-
await w.rename(u.slotPath,
|
|
2985
|
+
await w.rename(u.slotPath, g), m.vaultId = r.id, l = !0, await this.logger.log(
|
|
2932
2986
|
"INFO",
|
|
2933
2987
|
{
|
|
2934
2988
|
main: "move",
|
|
2935
2989
|
args: [String(d)],
|
|
2936
|
-
opts: { to:
|
|
2990
|
+
opts: { to: r.id },
|
|
2937
2991
|
source: "u"
|
|
2938
2992
|
},
|
|
2939
|
-
|
|
2993
|
+
i("service.archive.log.moved", {
|
|
2940
2994
|
id: d,
|
|
2941
|
-
fromVaultId:
|
|
2942
|
-
toVaultId:
|
|
2995
|
+
fromVaultId: p,
|
|
2996
|
+
toVaultId: r.id
|
|
2943
2997
|
}),
|
|
2944
|
-
{ aid: d, vid:
|
|
2998
|
+
{ aid: d, vid: r.id }
|
|
2945
2999
|
), c.ok.push({
|
|
2946
3000
|
id: d,
|
|
2947
3001
|
input: String(d),
|
|
2948
3002
|
success: !0,
|
|
2949
|
-
message:
|
|
2950
|
-
name:
|
|
2951
|
-
id:
|
|
3003
|
+
message: i("service.archive.result.moved_to_vault", {
|
|
3004
|
+
name: r.name,
|
|
3005
|
+
id: r.id
|
|
2952
3006
|
})
|
|
2953
3007
|
});
|
|
2954
|
-
} catch (
|
|
2955
|
-
const
|
|
3008
|
+
} catch (R) {
|
|
3009
|
+
const k = R.message;
|
|
2956
3010
|
await this.logger.log(
|
|
2957
3011
|
"ERROR",
|
|
2958
3012
|
{
|
|
2959
3013
|
main: "move",
|
|
2960
3014
|
args: [String(d)],
|
|
2961
|
-
opts: { to:
|
|
3015
|
+
opts: { to: r.id },
|
|
2962
3016
|
source: "u"
|
|
2963
3017
|
},
|
|
2964
|
-
|
|
3018
|
+
i("service.archive.log.move_failed", {
|
|
2965
3019
|
id: d,
|
|
2966
|
-
message:
|
|
3020
|
+
message: k
|
|
2967
3021
|
}),
|
|
2968
|
-
{ aid: d, vid:
|
|
3022
|
+
{ aid: d, vid: p }
|
|
2969
3023
|
), c.failed.push({
|
|
2970
3024
|
id: d,
|
|
2971
3025
|
input: String(d),
|
|
2972
3026
|
success: !1,
|
|
2973
|
-
message:
|
|
3027
|
+
message: k
|
|
2974
3028
|
});
|
|
2975
3029
|
}
|
|
2976
3030
|
}
|
|
@@ -2979,34 +3033,34 @@ class si {
|
|
|
2979
3033
|
async resolveCdTarget(t) {
|
|
2980
3034
|
const a = t.trim();
|
|
2981
3035
|
if (!a)
|
|
2982
|
-
throw new Error(
|
|
2983
|
-
const { vaultRef:
|
|
3036
|
+
throw new Error(i("service.archive.error.target_empty"));
|
|
3037
|
+
const { vaultRef: r, archiveId: n } = this.parseCdTarget(a), s = (await this.context.loadListEntries()).find((d) => d.id === n);
|
|
2984
3038
|
if (!s)
|
|
2985
3039
|
throw new Error(
|
|
2986
|
-
|
|
3040
|
+
i("service.archive.error.id_not_exists", {
|
|
2987
3041
|
id: n
|
|
2988
3042
|
})
|
|
2989
3043
|
);
|
|
2990
3044
|
if (s.status !== C.Archived)
|
|
2991
3045
|
throw new Error(
|
|
2992
|
-
|
|
3046
|
+
i("service.archive.error.id_restored_no_slot", {
|
|
2993
3047
|
id: n
|
|
2994
3048
|
})
|
|
2995
3049
|
);
|
|
2996
|
-
if (
|
|
2997
|
-
const d = await this.context.resolveVault(
|
|
3050
|
+
if (r !== void 0) {
|
|
3051
|
+
const d = await this.context.resolveVault(r, {
|
|
2998
3052
|
includeRemoved: !0,
|
|
2999
3053
|
fallbackCurrent: !1
|
|
3000
3054
|
});
|
|
3001
3055
|
if (!d)
|
|
3002
3056
|
throw new Error(
|
|
3003
|
-
|
|
3004
|
-
vault:
|
|
3057
|
+
i("service.archive.error.vault_not_found", {
|
|
3058
|
+
vault: r
|
|
3005
3059
|
})
|
|
3006
3060
|
);
|
|
3007
3061
|
if (d.id !== s.vaultId)
|
|
3008
3062
|
throw new Error(
|
|
3009
|
-
|
|
3063
|
+
i("service.archive.error.id_vault_mismatch", {
|
|
3010
3064
|
id: n,
|
|
3011
3065
|
actualVaultId: s.vaultId,
|
|
3012
3066
|
requestedVaultId: d.id
|
|
@@ -3019,7 +3073,7 @@ class si {
|
|
|
3019
3073
|
});
|
|
3020
3074
|
if (!c)
|
|
3021
3075
|
throw new Error(
|
|
3022
|
-
|
|
3076
|
+
i("service.archive.error.vault_for_archive_not_found", {
|
|
3023
3077
|
id: n,
|
|
3024
3078
|
vaultId: s.vaultId
|
|
3025
3079
|
})
|
|
@@ -3027,7 +3081,7 @@ class si {
|
|
|
3027
3081
|
const l = await this.context.resolveArchiveStorageLocation(s);
|
|
3028
3082
|
if (!l)
|
|
3029
3083
|
throw new Error(
|
|
3030
|
-
|
|
3084
|
+
i("service.archive.error.slot_missing_invalid", {
|
|
3031
3085
|
path: this.context.archivePath(s.vaultId, s.id)
|
|
3032
3086
|
})
|
|
3033
3087
|
);
|
|
@@ -3038,29 +3092,29 @@ class si {
|
|
|
3038
3092
|
};
|
|
3039
3093
|
}
|
|
3040
3094
|
async listEntries(t) {
|
|
3041
|
-
let
|
|
3042
|
-
if (t.all || (t.restored ?
|
|
3095
|
+
let r = await this.context.loadListEntries();
|
|
3096
|
+
if (t.all || (t.restored ? r = r.filter((n) => n.status === C.Restored) : r = r.filter((n) => n.status === C.Archived)), t.vault !== void 0) {
|
|
3043
3097
|
const n = await this.context.resolveVault(t.vault, {
|
|
3044
3098
|
includeRemoved: !0,
|
|
3045
3099
|
fallbackCurrent: !1
|
|
3046
3100
|
});
|
|
3047
3101
|
if (!n)
|
|
3048
3102
|
throw new Error(
|
|
3049
|
-
|
|
3103
|
+
i("service.archive.error.vault_not_found", {
|
|
3050
3104
|
vault: t.vault
|
|
3051
3105
|
})
|
|
3052
3106
|
);
|
|
3053
|
-
|
|
3107
|
+
r = r.filter((o) => o.vaultId === n.id);
|
|
3054
3108
|
}
|
|
3055
|
-
return
|
|
3109
|
+
return r.sort((n, o) => n.id - o.id);
|
|
3056
3110
|
}
|
|
3057
3111
|
async decorateEntries(t) {
|
|
3058
|
-
const a = await this.context.getVaults({ includeRemoved: !0, withDefault: !0 }),
|
|
3112
|
+
const a = await this.context.getVaults({ includeRemoved: !0, withDefault: !0 }), r = new Map(a.map((n) => [n.id, n]));
|
|
3059
3113
|
return t.map((n) => {
|
|
3060
|
-
const o =
|
|
3114
|
+
const o = r.get(n.vaultId), s = h.join(n.directory, n.item);
|
|
3061
3115
|
return {
|
|
3062
3116
|
...n,
|
|
3063
|
-
vaultName: o ? `${o.name}(${o.id})` :
|
|
3117
|
+
vaultName: o ? `${o.name}(${o.id})` : i("service.archive.decorated.unknown_vault", {
|
|
3064
3118
|
vaultId: n.vaultId
|
|
3065
3119
|
}),
|
|
3066
3120
|
displayPath: s
|
|
@@ -3073,12 +3127,12 @@ class si {
|
|
|
3073
3127
|
fallbackCurrent: !0
|
|
3074
3128
|
});
|
|
3075
3129
|
if (!a) {
|
|
3076
|
-
const
|
|
3077
|
-
throw new Error(
|
|
3130
|
+
const r = t ? i("service.archive.error.vault_not_found", { vault: t }) : i("service.archive.error.current_vault_invalid");
|
|
3131
|
+
throw new Error(r);
|
|
3078
3132
|
}
|
|
3079
3133
|
if (a.status === "Removed")
|
|
3080
3134
|
throw new Error(
|
|
3081
|
-
|
|
3135
|
+
i("service.archive.error.vault_removed", {
|
|
3082
3136
|
vault: a.name
|
|
3083
3137
|
})
|
|
3084
3138
|
);
|
|
@@ -3089,7 +3143,7 @@ class si {
|
|
|
3089
3143
|
if (a === -1) {
|
|
3090
3144
|
if (!/^\d+$/.test(t))
|
|
3091
3145
|
throw new Error(
|
|
3092
|
-
|
|
3146
|
+
i("service.archive.error.invalid_target_format", {
|
|
3093
3147
|
target: t
|
|
3094
3148
|
})
|
|
3095
3149
|
);
|
|
@@ -3097,48 +3151,48 @@ class si {
|
|
|
3097
3151
|
archiveId: Number(t)
|
|
3098
3152
|
};
|
|
3099
3153
|
}
|
|
3100
|
-
const
|
|
3101
|
-
if (!
|
|
3154
|
+
const r = t.slice(0, a).trim(), n = t.slice(a + 1).trim();
|
|
3155
|
+
if (!r)
|
|
3102
3156
|
throw new Error(
|
|
3103
|
-
|
|
3157
|
+
i("service.archive.error.invalid_target_no_vault", {
|
|
3104
3158
|
target: t
|
|
3105
3159
|
})
|
|
3106
3160
|
);
|
|
3107
3161
|
if (!/^\d+$/.test(n))
|
|
3108
3162
|
throw new Error(
|
|
3109
|
-
|
|
3163
|
+
i("service.archive.error.invalid_target_archive_id", {
|
|
3110
3164
|
target: t
|
|
3111
3165
|
})
|
|
3112
3166
|
);
|
|
3113
3167
|
return {
|
|
3114
|
-
vaultRef:
|
|
3168
|
+
vaultRef: r,
|
|
3115
3169
|
archiveId: Number(n)
|
|
3116
3170
|
};
|
|
3117
3171
|
}
|
|
3118
3172
|
async preValidatePutItems(t) {
|
|
3119
|
-
const a = [],
|
|
3173
|
+
const a = [], r = /* @__PURE__ */ new Set(), n = await Ke(_.Dir.root);
|
|
3120
3174
|
for (const o of t) {
|
|
3121
|
-
const s =
|
|
3175
|
+
const s = h.resolve(o), c = await ge(s);
|
|
3122
3176
|
if (!c)
|
|
3123
3177
|
throw new Error(
|
|
3124
|
-
|
|
3178
|
+
i("service.archive.error.path_not_exists", {
|
|
3125
3179
|
path: o
|
|
3126
3180
|
})
|
|
3127
3181
|
);
|
|
3128
|
-
const l = await
|
|
3129
|
-
if (
|
|
3182
|
+
const l = await Ke(s);
|
|
3183
|
+
if (Wa(l, n) || yt(n, l))
|
|
3130
3184
|
throw new Error(
|
|
3131
|
-
|
|
3185
|
+
i("service.archive.error.path_forbidden_archiver_scope", {
|
|
3132
3186
|
path: o
|
|
3133
3187
|
})
|
|
3134
3188
|
);
|
|
3135
|
-
if (
|
|
3189
|
+
if (r.has(l))
|
|
3136
3190
|
throw new Error(
|
|
3137
|
-
|
|
3191
|
+
i("service.archive.error.duplicate_input_path", {
|
|
3138
3192
|
path: o
|
|
3139
3193
|
})
|
|
3140
3194
|
);
|
|
3141
|
-
|
|
3195
|
+
r.add(l), a.push({
|
|
3142
3196
|
input: o,
|
|
3143
3197
|
resolvedPath: s,
|
|
3144
3198
|
canonicalPath: l,
|
|
@@ -3148,45 +3202,45 @@ class si {
|
|
|
3148
3202
|
return a;
|
|
3149
3203
|
}
|
|
3150
3204
|
async preValidatePutSlots(t, a) {
|
|
3151
|
-
const
|
|
3205
|
+
const r = await this.context.loadAutoIncr();
|
|
3152
3206
|
for (let n = 1; n <= a; n += 1) {
|
|
3153
|
-
const o =
|
|
3207
|
+
const o = r.archiveId + n, s = this.context.archivePath(t, o);
|
|
3154
3208
|
if (await x(s))
|
|
3155
3209
|
throw new Error(
|
|
3156
|
-
|
|
3210
|
+
i("service.archive.error.slot_already_occupied", {
|
|
3157
3211
|
path: s
|
|
3158
3212
|
})
|
|
3159
3213
|
);
|
|
3160
3214
|
}
|
|
3161
3215
|
}
|
|
3162
3216
|
}
|
|
3163
|
-
class
|
|
3217
|
+
class ur {
|
|
3164
3218
|
constructor(t) {
|
|
3165
3219
|
this.context = t;
|
|
3166
3220
|
}
|
|
3167
|
-
async log(t, a,
|
|
3221
|
+
async log(t, a, r, n) {
|
|
3168
3222
|
const c = {
|
|
3169
3223
|
id: await this.context.nextAutoIncrement("logId"),
|
|
3170
|
-
operedAt:
|
|
3224
|
+
operedAt: $e(/* @__PURE__ */ new Date()),
|
|
3171
3225
|
level: t,
|
|
3172
3226
|
oper: a,
|
|
3173
|
-
message:
|
|
3227
|
+
message: r,
|
|
3174
3228
|
...n?.aid !== void 0 ? { archiveIds: n.aid } : {},
|
|
3175
3229
|
...n?.vid !== void 0 ? { vaultIds: n.vid } : {}
|
|
3176
3230
|
};
|
|
3177
|
-
return await
|
|
3231
|
+
return await Et(_.File.log, c), c;
|
|
3178
3232
|
}
|
|
3179
3233
|
}
|
|
3180
|
-
function
|
|
3234
|
+
function ke(e) {
|
|
3181
3235
|
const t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
3182
|
-
for (const
|
|
3183
|
-
t.has(
|
|
3184
|
-
return [...a].sort((
|
|
3236
|
+
for (const r of e)
|
|
3237
|
+
t.has(r) ? a.add(r) : t.add(r);
|
|
3238
|
+
return [...a].sort((r, n) => r - n);
|
|
3185
3239
|
}
|
|
3186
|
-
function
|
|
3187
|
-
e.push({ level: t, code: a, message:
|
|
3240
|
+
function b(e, t, a, r) {
|
|
3241
|
+
e.push({ level: t, code: a, message: r });
|
|
3188
3242
|
}
|
|
3189
|
-
class
|
|
3243
|
+
class mr {
|
|
3190
3244
|
constructor(t) {
|
|
3191
3245
|
this.context = t;
|
|
3192
3246
|
}
|
|
@@ -3196,13 +3250,13 @@ class di {
|
|
|
3196
3250
|
info: []
|
|
3197
3251
|
};
|
|
3198
3252
|
await this.checkRequiredPaths(t);
|
|
3199
|
-
const a = await this.context.loadConfig(),
|
|
3200
|
-
return this.checkConfigVaultReference(t, a.currentVaultId, o), this.checkListIds(t, n,
|
|
3201
|
-
|
|
3253
|
+
const a = await this.context.loadConfig(), r = await this.context.loadAutoIncr(), n = await this.context.loadListEntries(), o = await this.context.getVaults({ includeRemoved: !0, withDefault: !0 });
|
|
3254
|
+
return this.checkConfigVaultReference(t, a.currentVaultId, o), this.checkListIds(t, n, r.archiveId), this.checkVaultIds(t, o, r.vaultId), await this.checkListConsistency(t, n, o), await this.checkVaultDirectoryConsistency(t, n, o), await this.checkLogConsistency(t, r.logId), t.info.push(
|
|
3255
|
+
i("service.check.info.checked_entries", {
|
|
3202
3256
|
count: n.length
|
|
3203
3257
|
})
|
|
3204
3258
|
), t.info.push(
|
|
3205
|
-
|
|
3259
|
+
i("service.check.info.checked_vaults", {
|
|
3206
3260
|
count: o.length
|
|
3207
3261
|
})
|
|
3208
3262
|
), t;
|
|
@@ -3211,150 +3265,150 @@ class di {
|
|
|
3211
3265
|
const a = [
|
|
3212
3266
|
...Object.values(_.Dir),
|
|
3213
3267
|
...Object.values(_.File),
|
|
3214
|
-
this.context.vaultDir(
|
|
3268
|
+
this.context.vaultDir(f.Vault.id)
|
|
3215
3269
|
];
|
|
3216
|
-
for (const
|
|
3217
|
-
await x(
|
|
3270
|
+
for (const r of a)
|
|
3271
|
+
await x(r) || b(
|
|
3218
3272
|
t.issues,
|
|
3219
|
-
|
|
3273
|
+
y.Error,
|
|
3220
3274
|
"MISSING_PATH",
|
|
3221
|
-
|
|
3222
|
-
path:
|
|
3275
|
+
i("service.check.issue.missing_path", {
|
|
3276
|
+
path: r
|
|
3223
3277
|
})
|
|
3224
3278
|
);
|
|
3225
3279
|
}
|
|
3226
|
-
checkConfigVaultReference(t, a,
|
|
3227
|
-
|
|
3280
|
+
checkConfigVaultReference(t, a, r) {
|
|
3281
|
+
r.find((o) => o.id === a && o.status !== $.Removed) || b(
|
|
3228
3282
|
t.issues,
|
|
3229
|
-
|
|
3283
|
+
y.Error,
|
|
3230
3284
|
"INVALID_CURRENT_VAULT",
|
|
3231
|
-
|
|
3285
|
+
i("service.check.issue.invalid_current_vault", {
|
|
3232
3286
|
currentVaultId: a
|
|
3233
3287
|
})
|
|
3234
3288
|
);
|
|
3235
3289
|
}
|
|
3236
|
-
checkListIds(t, a,
|
|
3237
|
-
const n = a.map((c) => c.id), o =
|
|
3238
|
-
o.length > 0 &&
|
|
3290
|
+
checkListIds(t, a, r) {
|
|
3291
|
+
const n = a.map((c) => c.id), o = ke(n);
|
|
3292
|
+
o.length > 0 && b(
|
|
3239
3293
|
t.issues,
|
|
3240
|
-
|
|
3294
|
+
y.Error,
|
|
3241
3295
|
"DUPLICATE_ARCHIVE_ID",
|
|
3242
|
-
|
|
3296
|
+
i("service.check.issue.duplicate_archive_id", {
|
|
3243
3297
|
ids: o.join(", ")
|
|
3244
3298
|
})
|
|
3245
3299
|
);
|
|
3246
3300
|
const s = n.length > 0 ? Math.max(...n) : 0;
|
|
3247
|
-
|
|
3301
|
+
r < s && b(
|
|
3248
3302
|
t.issues,
|
|
3249
|
-
|
|
3303
|
+
y.Error,
|
|
3250
3304
|
"ARCHIVE_AUTO_INCR_TOO_SMALL",
|
|
3251
|
-
|
|
3252
|
-
autoIncr:
|
|
3305
|
+
i("service.check.issue.archive_auto_incr_too_small", {
|
|
3306
|
+
autoIncr: r,
|
|
3253
3307
|
maxId: s
|
|
3254
3308
|
})
|
|
3255
3309
|
);
|
|
3256
3310
|
}
|
|
3257
|
-
checkVaultIds(t, a,
|
|
3258
|
-
const n = a.filter((m) => m.id !==
|
|
3259
|
-
s.length > 0 &&
|
|
3311
|
+
checkVaultIds(t, a, r) {
|
|
3312
|
+
const n = a.filter((m) => m.id !== f.Vault.id), o = n.map((m) => m.id), s = ke(o);
|
|
3313
|
+
s.length > 0 && b(
|
|
3260
3314
|
t.issues,
|
|
3261
|
-
|
|
3315
|
+
y.Error,
|
|
3262
3316
|
"DUPLICATE_VAULT_ID",
|
|
3263
|
-
|
|
3317
|
+
i("service.check.issue.duplicate_vault_id", {
|
|
3264
3318
|
ids: s.join(", ")
|
|
3265
3319
|
})
|
|
3266
3320
|
);
|
|
3267
3321
|
const c = n.map((m) => m.name), l = c.filter((m, u) => c.indexOf(m) !== u);
|
|
3268
|
-
l.length > 0 &&
|
|
3322
|
+
l.length > 0 && b(
|
|
3269
3323
|
t.issues,
|
|
3270
|
-
|
|
3324
|
+
y.Error,
|
|
3271
3325
|
"DUPLICATE_VAULT_NAME",
|
|
3272
|
-
|
|
3326
|
+
i("service.check.issue.duplicate_vault_name", {
|
|
3273
3327
|
names: [...new Set(l)].join(", ")
|
|
3274
3328
|
})
|
|
3275
3329
|
);
|
|
3276
3330
|
const d = o.length > 0 ? Math.max(...o) : 0;
|
|
3277
|
-
|
|
3331
|
+
r < d && b(
|
|
3278
3332
|
t.issues,
|
|
3279
|
-
|
|
3333
|
+
y.Error,
|
|
3280
3334
|
"VAULT_AUTO_INCR_TOO_SMALL",
|
|
3281
|
-
|
|
3282
|
-
autoIncr:
|
|
3335
|
+
i("service.check.issue.vault_auto_incr_too_small", {
|
|
3336
|
+
autoIncr: r,
|
|
3283
3337
|
maxId: d
|
|
3284
3338
|
})
|
|
3285
3339
|
);
|
|
3286
3340
|
}
|
|
3287
|
-
async checkListConsistency(t, a,
|
|
3288
|
-
const n = new Map(
|
|
3341
|
+
async checkListConsistency(t, a, r) {
|
|
3342
|
+
const n = new Map(r.map((o) => [o.id, o]));
|
|
3289
3343
|
for (const o of a) {
|
|
3290
3344
|
if (!n.get(o.vaultId)) {
|
|
3291
|
-
|
|
3345
|
+
b(
|
|
3292
3346
|
t.issues,
|
|
3293
|
-
|
|
3347
|
+
y.Error,
|
|
3294
3348
|
"UNKNOWN_VAULT_REFERENCE",
|
|
3295
|
-
|
|
3349
|
+
i("service.check.issue.unknown_vault_reference", {
|
|
3296
3350
|
archiveId: o.id,
|
|
3297
3351
|
vaultId: o.vaultId
|
|
3298
3352
|
})
|
|
3299
3353
|
);
|
|
3300
3354
|
continue;
|
|
3301
3355
|
}
|
|
3302
|
-
const c = this.context.archivePath(o.vaultId, o.id), l =
|
|
3356
|
+
const c = this.context.archivePath(o.vaultId, o.id), l = h.join(o.directory, o.item);
|
|
3303
3357
|
if (o.status === C.Archived) {
|
|
3304
3358
|
const d = await this.context.resolveArchiveStorageLocation(o);
|
|
3305
3359
|
if (!d)
|
|
3306
|
-
|
|
3360
|
+
b(
|
|
3307
3361
|
t.issues,
|
|
3308
|
-
|
|
3362
|
+
y.Error,
|
|
3309
3363
|
"MISSING_ARCHIVE_OBJECT",
|
|
3310
|
-
|
|
3364
|
+
i("service.check.issue.missing_archive_object", {
|
|
3311
3365
|
archiveId: o.id,
|
|
3312
3366
|
archivePath: c
|
|
3313
3367
|
})
|
|
3314
3368
|
);
|
|
3315
3369
|
else {
|
|
3316
|
-
const m = await
|
|
3370
|
+
const m = await ge(d.objectPath);
|
|
3317
3371
|
if (m) {
|
|
3318
|
-
const u = m.isDirectory(),
|
|
3319
|
-
u !==
|
|
3372
|
+
const u = m.isDirectory(), g = o.isDirectory === 1;
|
|
3373
|
+
u !== g && b(
|
|
3320
3374
|
t.issues,
|
|
3321
|
-
|
|
3375
|
+
y.Error,
|
|
3322
3376
|
"TYPE_MISMATCH_ARCHIVED",
|
|
3323
|
-
|
|
3377
|
+
i("service.check.issue.type_mismatch_archived", {
|
|
3324
3378
|
archiveId: o.id,
|
|
3325
|
-
expectedIsDir:
|
|
3379
|
+
expectedIsDir: g,
|
|
3326
3380
|
actualIsDir: u
|
|
3327
3381
|
})
|
|
3328
3382
|
);
|
|
3329
3383
|
}
|
|
3330
3384
|
}
|
|
3331
|
-
await x(l) &&
|
|
3385
|
+
await x(l) && b(
|
|
3332
3386
|
t.issues,
|
|
3333
|
-
|
|
3387
|
+
y.Warn,
|
|
3334
3388
|
"RESTORE_TARGET_ALREADY_EXISTS",
|
|
3335
|
-
|
|
3389
|
+
i("service.check.issue.restore_target_exists", {
|
|
3336
3390
|
archiveId: o.id,
|
|
3337
3391
|
restorePath: l
|
|
3338
3392
|
})
|
|
3339
3393
|
);
|
|
3340
3394
|
} else if (o.status === C.Restored)
|
|
3341
|
-
if (await x(c) &&
|
|
3395
|
+
if (await x(c) && b(
|
|
3342
3396
|
t.issues,
|
|
3343
|
-
|
|
3397
|
+
y.Warn,
|
|
3344
3398
|
"RESTORED_BUT_ARCHIVE_EXISTS",
|
|
3345
|
-
|
|
3399
|
+
i("service.check.issue.restored_but_archive_exists", {
|
|
3346
3400
|
archiveId: o.id,
|
|
3347
3401
|
archivePath: c
|
|
3348
3402
|
})
|
|
3349
3403
|
), await x(l)) {
|
|
3350
|
-
const d = await
|
|
3404
|
+
const d = await ge(l);
|
|
3351
3405
|
if (d) {
|
|
3352
3406
|
const m = d.isDirectory(), u = o.isDirectory === 1;
|
|
3353
|
-
m !== u &&
|
|
3407
|
+
m !== u && b(
|
|
3354
3408
|
t.issues,
|
|
3355
|
-
|
|
3409
|
+
y.Warn,
|
|
3356
3410
|
"TYPE_MISMATCH_RESTORED",
|
|
3357
|
-
|
|
3411
|
+
i("service.check.issue.type_mismatch_restored", {
|
|
3358
3412
|
archiveId: o.id,
|
|
3359
3413
|
expectedIsDir: u,
|
|
3360
3414
|
actualIsDir: m
|
|
@@ -3362,60 +3416,60 @@ class di {
|
|
|
3362
3416
|
);
|
|
3363
3417
|
}
|
|
3364
3418
|
} else
|
|
3365
|
-
|
|
3419
|
+
b(
|
|
3366
3420
|
t.issues,
|
|
3367
|
-
|
|
3421
|
+
y.Warn,
|
|
3368
3422
|
"RESTORED_TARGET_MISSING",
|
|
3369
|
-
|
|
3423
|
+
i("service.check.issue.restored_target_missing", {
|
|
3370
3424
|
archiveId: o.id,
|
|
3371
3425
|
restorePath: l
|
|
3372
3426
|
})
|
|
3373
3427
|
);
|
|
3374
3428
|
else
|
|
3375
|
-
|
|
3429
|
+
b(
|
|
3376
3430
|
t.issues,
|
|
3377
|
-
|
|
3431
|
+
y.Error,
|
|
3378
3432
|
"INVALID_ARCHIVE_STATUS",
|
|
3379
|
-
|
|
3433
|
+
i("service.check.issue.invalid_archive_status", {
|
|
3380
3434
|
archiveId: o.id,
|
|
3381
3435
|
status: o.status
|
|
3382
3436
|
})
|
|
3383
3437
|
);
|
|
3384
3438
|
}
|
|
3385
3439
|
}
|
|
3386
|
-
async checkVaultDirectoryConsistency(t, a,
|
|
3387
|
-
const n = new Set(
|
|
3440
|
+
async checkVaultDirectoryConsistency(t, a, r) {
|
|
3441
|
+
const n = new Set(r.map((c) => c.id)), o = new Set(
|
|
3388
3442
|
a.filter((c) => c.status === C.Archived).map((c) => `${c.vaultId}/${c.id}`)
|
|
3389
|
-
), s = await
|
|
3443
|
+
), s = await Ja(_.Dir.vaults);
|
|
3390
3444
|
for (const c of s) {
|
|
3391
3445
|
if (!/^\d+$/.test(c)) {
|
|
3392
|
-
|
|
3446
|
+
b(
|
|
3393
3447
|
t.issues,
|
|
3394
|
-
|
|
3448
|
+
y.Warn,
|
|
3395
3449
|
"NON_NUMERIC_VAULT_DIR",
|
|
3396
|
-
|
|
3397
|
-
path:
|
|
3450
|
+
i("service.check.issue.non_numeric_vault_dir", {
|
|
3451
|
+
path: h.join(_.Dir.vaults, c)
|
|
3398
3452
|
})
|
|
3399
3453
|
);
|
|
3400
3454
|
continue;
|
|
3401
3455
|
}
|
|
3402
3456
|
const l = Number(c);
|
|
3403
|
-
n.has(l) ||
|
|
3457
|
+
n.has(l) || b(
|
|
3404
3458
|
t.issues,
|
|
3405
|
-
|
|
3459
|
+
y.Warn,
|
|
3406
3460
|
"ORPHAN_VAULT_DIR",
|
|
3407
|
-
|
|
3408
|
-
path:
|
|
3461
|
+
i("service.check.issue.orphan_vault_dir", {
|
|
3462
|
+
path: h.join(_.Dir.vaults, c)
|
|
3409
3463
|
})
|
|
3410
3464
|
);
|
|
3411
3465
|
const d = this.context.vaultDir(l), m = await w.readdir(d, { withFileTypes: !0 });
|
|
3412
3466
|
for (const u of m) {
|
|
3413
3467
|
if (!/^[0-9]+$/.test(u.name)) {
|
|
3414
|
-
|
|
3468
|
+
b(
|
|
3415
3469
|
t.issues,
|
|
3416
|
-
|
|
3470
|
+
y.Warn,
|
|
3417
3471
|
"NON_NUMERIC_ARCHIVE_OBJECT",
|
|
3418
|
-
|
|
3472
|
+
i("service.check.issue.non_numeric_archive_object", {
|
|
3419
3473
|
vaultId: l,
|
|
3420
3474
|
name: u.name
|
|
3421
3475
|
})
|
|
@@ -3423,37 +3477,37 @@ class di {
|
|
|
3423
3477
|
continue;
|
|
3424
3478
|
}
|
|
3425
3479
|
if (!u.isDirectory()) {
|
|
3426
|
-
|
|
3480
|
+
b(
|
|
3427
3481
|
t.issues,
|
|
3428
|
-
|
|
3482
|
+
y.Error,
|
|
3429
3483
|
"INVALID_ARCHIVE_SLOT",
|
|
3430
|
-
|
|
3484
|
+
i("service.check.issue.invalid_archive_slot", {
|
|
3431
3485
|
vaultId: l,
|
|
3432
3486
|
slotName: u.name
|
|
3433
3487
|
})
|
|
3434
3488
|
);
|
|
3435
3489
|
continue;
|
|
3436
3490
|
}
|
|
3437
|
-
const
|
|
3438
|
-
o.has(
|
|
3491
|
+
const g = `${l}/${Number(u.name)}`;
|
|
3492
|
+
o.has(g) || b(
|
|
3439
3493
|
t.issues,
|
|
3440
|
-
|
|
3494
|
+
y.Warn,
|
|
3441
3495
|
"ORPHAN_ARCHIVE_OBJECT",
|
|
3442
|
-
|
|
3443
|
-
pairKey:
|
|
3496
|
+
i("service.check.issue.orphan_archive_object", {
|
|
3497
|
+
pairKey: g
|
|
3444
3498
|
})
|
|
3445
3499
|
);
|
|
3446
3500
|
}
|
|
3447
3501
|
}
|
|
3448
|
-
for (const c of
|
|
3502
|
+
for (const c of r) {
|
|
3449
3503
|
if (c.status !== "Valid" && c.status !== "Protected")
|
|
3450
3504
|
continue;
|
|
3451
3505
|
const l = this.context.vaultDir(c.id);
|
|
3452
|
-
await x(l) ||
|
|
3506
|
+
await x(l) || b(
|
|
3453
3507
|
t.issues,
|
|
3454
|
-
|
|
3508
|
+
y.Error,
|
|
3455
3509
|
"MISSING_VAULT_DIR",
|
|
3456
|
-
|
|
3510
|
+
i("service.check.issue.missing_vault_dir", {
|
|
3457
3511
|
vaultName: c.name,
|
|
3458
3512
|
vaultId: c.id,
|
|
3459
3513
|
path: l
|
|
@@ -3462,28 +3516,28 @@ class di {
|
|
|
3462
3516
|
}
|
|
3463
3517
|
}
|
|
3464
3518
|
async checkLogConsistency(t, a) {
|
|
3465
|
-
const n = (await
|
|
3466
|
-
o.length > 0 &&
|
|
3519
|
+
const n = (await pe(_.File.log)).map((c) => Number(c.id)).filter((c) => Number.isInteger(c)), o = ke(n);
|
|
3520
|
+
o.length > 0 && b(
|
|
3467
3521
|
t.issues,
|
|
3468
|
-
|
|
3522
|
+
y.Error,
|
|
3469
3523
|
"DUPLICATE_LOG_ID",
|
|
3470
|
-
|
|
3524
|
+
i("service.check.issue.duplicate_log_id", {
|
|
3471
3525
|
ids: o.join(", ")
|
|
3472
3526
|
})
|
|
3473
3527
|
);
|
|
3474
3528
|
const s = n.length > 0 ? Math.max(...n) : 0;
|
|
3475
|
-
a < s &&
|
|
3529
|
+
a < s && b(
|
|
3476
3530
|
t.issues,
|
|
3477
|
-
|
|
3531
|
+
y.Error,
|
|
3478
3532
|
"LOG_AUTO_INCR_TOO_SMALL",
|
|
3479
|
-
|
|
3533
|
+
i("service.check.issue.log_auto_incr_too_small", {
|
|
3480
3534
|
autoIncr: a,
|
|
3481
3535
|
maxId: s
|
|
3482
3536
|
})
|
|
3483
3537
|
);
|
|
3484
3538
|
}
|
|
3485
3539
|
}
|
|
3486
|
-
class
|
|
3540
|
+
class vr {
|
|
3487
3541
|
constructor(t) {
|
|
3488
3542
|
this.context = t;
|
|
3489
3543
|
}
|
|
@@ -3519,7 +3573,7 @@ class ui {
|
|
|
3519
3573
|
a.lastUpdateCheck = t, await this.context.saveConfig(a);
|
|
3520
3574
|
}
|
|
3521
3575
|
}
|
|
3522
|
-
function
|
|
3576
|
+
function hr(e) {
|
|
3523
3577
|
return {
|
|
3524
3578
|
id: Number(e.id),
|
|
3525
3579
|
operedAt: String(e.operedAt ?? ""),
|
|
@@ -3530,51 +3584,51 @@ function mi(e) {
|
|
|
3530
3584
|
...e.vaultIds !== void 0 ? { vaultIds: Number(e.vaultIds) } : {}
|
|
3531
3585
|
};
|
|
3532
3586
|
}
|
|
3533
|
-
function
|
|
3587
|
+
function fr(e) {
|
|
3534
3588
|
return e.operedAt.replace(/[-:\sT]/g, "").slice(0, 6);
|
|
3535
3589
|
}
|
|
3536
|
-
class
|
|
3590
|
+
class gr {
|
|
3537
3591
|
constructor(t) {
|
|
3538
3592
|
this.context = t;
|
|
3539
3593
|
}
|
|
3540
3594
|
async getLogs(t) {
|
|
3541
3595
|
const a = await this.loadAllLogs();
|
|
3542
|
-
return t.mode === "all" ? a : a.filter((
|
|
3543
|
-
const n =
|
|
3596
|
+
return t.mode === "all" ? a : a.filter((r) => {
|
|
3597
|
+
const n = fr(r);
|
|
3544
3598
|
return !n || n.length !== 6 ? !1 : n >= t.from && n <= t.to;
|
|
3545
3599
|
});
|
|
3546
3600
|
}
|
|
3547
3601
|
async getLogById(t) {
|
|
3548
|
-
const
|
|
3549
|
-
if (!
|
|
3602
|
+
const r = (await this.loadAllLogs()).find((o) => o.id === t);
|
|
3603
|
+
if (!r)
|
|
3550
3604
|
return;
|
|
3551
|
-
const n = { log:
|
|
3552
|
-
if (
|
|
3605
|
+
const n = { log: r };
|
|
3606
|
+
if (r.archiveIds !== void 0) {
|
|
3553
3607
|
const o = await this.context.loadListEntries();
|
|
3554
|
-
n.archive = o.find((s) => s.id ===
|
|
3608
|
+
n.archive = o.find((s) => s.id === r.archiveIds);
|
|
3555
3609
|
}
|
|
3556
|
-
if (
|
|
3610
|
+
if (r.vaultIds !== void 0) {
|
|
3557
3611
|
const o = await this.context.getVaults({ includeRemoved: !0, withDefault: !0 });
|
|
3558
|
-
n.vault = o.find((s) => s.id ===
|
|
3612
|
+
n.vault = o.find((s) => s.id === r.vaultIds);
|
|
3559
3613
|
}
|
|
3560
3614
|
return n;
|
|
3561
3615
|
}
|
|
3562
3616
|
async loadAllLogs() {
|
|
3563
|
-
const a = (await
|
|
3564
|
-
return a.sort((
|
|
3617
|
+
const a = (await pe(_.File.log)).map((r) => hr(r));
|
|
3618
|
+
return a.sort((r, n) => r.id - n.id), a;
|
|
3565
3619
|
}
|
|
3566
3620
|
}
|
|
3567
|
-
const
|
|
3568
|
-
function
|
|
3621
|
+
const pr = Ut(qt);
|
|
3622
|
+
function Ve(e) {
|
|
3569
3623
|
return e.trim().replace(/^v/i, "");
|
|
3570
3624
|
}
|
|
3571
|
-
function
|
|
3572
|
-
return
|
|
3625
|
+
function nt(e) {
|
|
3626
|
+
return Ve(e).split(".").map((t) => Number(t.replace(/[^0-9].*$/, ""))).map((t) => Number.isFinite(t) ? t : 0);
|
|
3573
3627
|
}
|
|
3574
|
-
function
|
|
3575
|
-
const a =
|
|
3628
|
+
function _r(e, t) {
|
|
3629
|
+
const a = nt(e), r = nt(t), n = Math.max(a.length, r.length);
|
|
3576
3630
|
for (let o = 0; o < n; o += 1) {
|
|
3577
|
-
const s = a[o] ?? 0, c =
|
|
3631
|
+
const s = a[o] ?? 0, c = r[o] ?? 0;
|
|
3578
3632
|
if (c > s)
|
|
3579
3633
|
return !0;
|
|
3580
3634
|
if (c < s)
|
|
@@ -3582,41 +3636,41 @@ function gi(e, t) {
|
|
|
3582
3636
|
}
|
|
3583
3637
|
return !1;
|
|
3584
3638
|
}
|
|
3585
|
-
class
|
|
3639
|
+
class wr {
|
|
3586
3640
|
currentVersion;
|
|
3587
3641
|
constructor(t) {
|
|
3588
|
-
this.currentVersion =
|
|
3642
|
+
this.currentVersion = Ve(t);
|
|
3589
3643
|
}
|
|
3590
|
-
async checkLatest(t =
|
|
3591
|
-
const a = await this.fetchLatestRelease(t),
|
|
3644
|
+
async checkLatest(t = W.Repo) {
|
|
3645
|
+
const a = await this.fetchLatestRelease(t), r = Ve(a.tag_name);
|
|
3592
3646
|
return {
|
|
3593
3647
|
currentVersion: this.currentVersion,
|
|
3594
|
-
latestVersion:
|
|
3595
|
-
hasUpdate:
|
|
3648
|
+
latestVersion: r,
|
|
3649
|
+
hasUpdate: _r(this.currentVersion, r),
|
|
3596
3650
|
htmlUrl: a.html_url,
|
|
3597
3651
|
publishedAt: a.published_at
|
|
3598
3652
|
};
|
|
3599
3653
|
}
|
|
3600
|
-
async installLatest(t =
|
|
3601
|
-
const
|
|
3602
|
-
if (!
|
|
3603
|
-
throw new Error(
|
|
3604
|
-
const n = await fetch(
|
|
3654
|
+
async installLatest(t = W.Repo) {
|
|
3655
|
+
const r = (await this.fetchLatestRelease(t)).assets?.find((c) => /install.*\.sh$/i.test(c.name));
|
|
3656
|
+
if (!r)
|
|
3657
|
+
throw new Error(i("service.update.error.no_install_asset"));
|
|
3658
|
+
const n = await fetch(r.browser_download_url, {
|
|
3605
3659
|
headers: {
|
|
3606
3660
|
"user-agent": "archiver-ts"
|
|
3607
3661
|
},
|
|
3608
|
-
signal: AbortSignal.timeout(
|
|
3662
|
+
signal: AbortSignal.timeout(W.Timeout)
|
|
3609
3663
|
});
|
|
3610
3664
|
if (!n.ok)
|
|
3611
3665
|
throw new Error(
|
|
3612
|
-
|
|
3666
|
+
i("service.update.error.download_failed", {
|
|
3613
3667
|
status: n.status
|
|
3614
3668
|
})
|
|
3615
3669
|
);
|
|
3616
|
-
const o = await n.text(), s =
|
|
3670
|
+
const o = await n.text(), s = h.join(ct.tmpdir(), `archiver-update-${Date.now()}.sh`);
|
|
3617
3671
|
await w.writeFile(s, o, { encoding: "utf8", mode: 493 });
|
|
3618
3672
|
try {
|
|
3619
|
-
const c = await
|
|
3673
|
+
const c = await pr("bash", [s], { maxBuffer: 4194304 });
|
|
3620
3674
|
return [c.stdout, c.stderr].filter(Boolean).join(`
|
|
3621
3675
|
`).trim();
|
|
3622
3676
|
} finally {
|
|
@@ -3624,37 +3678,37 @@ class pi {
|
|
|
3624
3678
|
}
|
|
3625
3679
|
}
|
|
3626
3680
|
async fetchLatestRelease(t) {
|
|
3627
|
-
const a = `https://api.github.com/repos/${t}/releases/latest`,
|
|
3681
|
+
const a = `https://api.github.com/repos/${t}/releases/latest`, r = await fetch(a, {
|
|
3628
3682
|
headers: {
|
|
3629
3683
|
accept: "application/vnd.github+json",
|
|
3630
3684
|
"user-agent": "archiver-ts"
|
|
3631
3685
|
},
|
|
3632
|
-
signal: AbortSignal.timeout(
|
|
3686
|
+
signal: AbortSignal.timeout(W.Timeout)
|
|
3633
3687
|
});
|
|
3634
|
-
if (!
|
|
3688
|
+
if (!r.ok)
|
|
3635
3689
|
throw new Error(
|
|
3636
|
-
|
|
3690
|
+
i("service.update.error.query_failed", {
|
|
3637
3691
|
repo: t,
|
|
3638
|
-
status:
|
|
3692
|
+
status: r.status
|
|
3639
3693
|
})
|
|
3640
3694
|
);
|
|
3641
|
-
const n = await
|
|
3695
|
+
const n = await r.json();
|
|
3642
3696
|
if (!n.tag_name)
|
|
3643
3697
|
throw new Error(
|
|
3644
|
-
|
|
3698
|
+
i("service.update.error.missing_tag_name", {
|
|
3645
3699
|
repo: t
|
|
3646
3700
|
})
|
|
3647
3701
|
);
|
|
3648
3702
|
return n;
|
|
3649
3703
|
}
|
|
3650
3704
|
}
|
|
3651
|
-
async function
|
|
3652
|
-
const e = new
|
|
3705
|
+
async function Ir() {
|
|
3706
|
+
const e = new lr();
|
|
3653
3707
|
await e.init();
|
|
3654
|
-
const t = new
|
|
3708
|
+
const t = new vr(e), a = new ur(e), r = new dr(e, a), n = new Ga(e, t), o = new gr(e), s = new mr(e), c = "0.4.4", l = new wr(c);
|
|
3655
3709
|
return {
|
|
3656
3710
|
context: e,
|
|
3657
|
-
archiveService:
|
|
3711
|
+
archiveService: r,
|
|
3658
3712
|
vaultService: n,
|
|
3659
3713
|
configService: t,
|
|
3660
3714
|
logService: o,
|
|
@@ -3664,45 +3718,45 @@ async function _i() {
|
|
|
3664
3718
|
version: c
|
|
3665
3719
|
};
|
|
3666
3720
|
}
|
|
3667
|
-
async function
|
|
3668
|
-
if (!
|
|
3721
|
+
async function yr(e) {
|
|
3722
|
+
if (!Ne())
|
|
3669
3723
|
return "help";
|
|
3670
|
-
|
|
3671
|
-
const t = await
|
|
3672
|
-
title:
|
|
3673
|
-
description:
|
|
3724
|
+
A(i("index.no_command_action.unknown"));
|
|
3725
|
+
const t = await fa({
|
|
3726
|
+
title: i("index.no_command_action.question"),
|
|
3727
|
+
description: i("index.no_command_action.note"),
|
|
3674
3728
|
options: [
|
|
3675
|
-
{ value: "list", label:
|
|
3676
|
-
{ value: "help", label:
|
|
3729
|
+
{ value: "list", label: i("index.no_command_action.option.list") },
|
|
3730
|
+
{ value: "help", label: i("index.no_command_action.option.help") }
|
|
3677
3731
|
],
|
|
3678
3732
|
initialValue: "list",
|
|
3679
|
-
hint:
|
|
3680
|
-
leftRight:
|
|
3681
|
-
enter:
|
|
3733
|
+
hint: i("index.no_command_action.hint", {
|
|
3734
|
+
leftRight: N(i("index.no_command_action.key.left_right")),
|
|
3735
|
+
enter: N(i("index.no_command_action.key.enter"))
|
|
3682
3736
|
})
|
|
3683
3737
|
});
|
|
3684
|
-
return t || process.exit(130), await e.configService.setNoCommandAction(t),
|
|
3738
|
+
return t || process.exit(130), await e.configService.setNoCommandAction(t), T(i("index.no_command_action.updated", { action: t })), t;
|
|
3685
3739
|
}
|
|
3686
|
-
async function
|
|
3687
|
-
const e = await
|
|
3688
|
-
|
|
3740
|
+
async function br() {
|
|
3741
|
+
const e = await Ae(_.File.config, f.Config);
|
|
3742
|
+
me(e.language), he({
|
|
3689
3743
|
style: e.style === "off" ? "off" : "on"
|
|
3690
3744
|
});
|
|
3691
|
-
const t = await
|
|
3745
|
+
const t = await sr();
|
|
3692
3746
|
if (t.installed) {
|
|
3693
3747
|
const o = t.profilePath ? ` ${t.profilePath}` : "";
|
|
3694
|
-
|
|
3695
|
-
|
|
3748
|
+
A(i("index.shell_wrapper.installed", { where: o })), t.reloadCommand && A(
|
|
3749
|
+
i("index.shell_wrapper.reload_hint", {
|
|
3696
3750
|
reloadCommand: t.reloadCommand
|
|
3697
3751
|
})
|
|
3698
3752
|
);
|
|
3699
3753
|
return;
|
|
3700
3754
|
}
|
|
3701
|
-
const a = await
|
|
3702
|
-
|
|
3703
|
-
const n =
|
|
3755
|
+
const a = await Ir(), r = await a.configService.getConfig();
|
|
3756
|
+
me(r.language), he(r);
|
|
3757
|
+
const n = Xa(a);
|
|
3704
3758
|
if (process.argv.length <= 2) {
|
|
3705
|
-
if ((
|
|
3759
|
+
if ((r.noCommandAction === "unknown" ? await yr(a) : r.noCommandAction) === "list") {
|
|
3706
3760
|
await n.parseAsync([...process.argv, "list"]);
|
|
3707
3761
|
return;
|
|
3708
3762
|
}
|
|
@@ -3711,6 +3765,6 @@ async function Ii() {
|
|
|
3711
3765
|
}
|
|
3712
3766
|
await n.parseAsync(process.argv);
|
|
3713
3767
|
}
|
|
3714
|
-
|
|
3715
|
-
|
|
3768
|
+
br().catch((e) => {
|
|
3769
|
+
K(e.message), process.exit(1);
|
|
3716
3770
|
});
|