archiver-ts 0.3.1 → 0.3.3
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 +393 -384
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import Je from "node:fs";
|
|
3
3
|
import h, { join as D } from "node:path";
|
|
4
4
|
import p from "node:fs/promises";
|
|
5
|
-
import { parse as
|
|
6
|
-
import
|
|
7
|
-
import { Command as
|
|
5
|
+
import { parse as mt, printParseErrorCode as vt, modify as ht, applyEdits as ft } from "jsonc-parser";
|
|
6
|
+
import Ge, { homedir as gt } from "node:os";
|
|
7
|
+
import { Command as pt } from "commander";
|
|
8
8
|
import v from "chalk";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { stdout as
|
|
12
|
-
import { execFile as
|
|
13
|
-
import { promisify as
|
|
14
|
-
function
|
|
9
|
+
import pe from "node:readline";
|
|
10
|
+
import _t from "node:readline/promises";
|
|
11
|
+
import { stdout as wt, stdin as It } from "node:process";
|
|
12
|
+
import { execFile as yt } from "node:child_process";
|
|
13
|
+
import { promisify as bt } from "node:util";
|
|
14
|
+
function kt(e) {
|
|
15
15
|
const t = h.join(import.meta.dirname, e);
|
|
16
|
-
return
|
|
16
|
+
return Je.existsSync(t) ? t : h.resolve(import.meta.dirname, "..", "..", "public", e);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
18
|
+
function Ke(e) {
|
|
19
|
+
return Je.readFileSync(kt(e), "utf8");
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const ue = Ke("config.default.jsonc"), me = Ke("auto-incr.default.jsonc"), Ct = {
|
|
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",
|
|
@@ -334,7 +334,7 @@ const de = Ge("config.default.jsonc"), ue = Ge("auto-incr.default.jsonc"), kt =
|
|
|
334
334
|
"terminal.status.log.warn": "WARN",
|
|
335
335
|
"terminal.status.log.error": "ERROR",
|
|
336
336
|
"terminal.status.log.fatal": "FATAL"
|
|
337
|
-
},
|
|
337
|
+
}, Et = {
|
|
338
338
|
"app.description": "将文件和文件夹归档到 ~/.archiver,并记录审计日志",
|
|
339
339
|
"defaults.vault.remark": "默认 vault",
|
|
340
340
|
"common.action.list": "list",
|
|
@@ -650,18 +650,18 @@ const de = Ge("config.default.jsonc"), ue = Ge("auto-incr.default.jsonc"), kt =
|
|
|
650
650
|
"terminal.status.log.warn": "警告",
|
|
651
651
|
"terminal.status.log.error": "错误",
|
|
652
652
|
"terminal.status.log.fatal": "致命"
|
|
653
|
-
},
|
|
654
|
-
zh:
|
|
655
|
-
en:
|
|
653
|
+
}, Se = {
|
|
654
|
+
zh: Et,
|
|
655
|
+
en: Ct
|
|
656
656
|
};
|
|
657
|
-
let
|
|
658
|
-
function
|
|
657
|
+
let ve = "zh";
|
|
658
|
+
function At(e) {
|
|
659
659
|
return e === "en" ? "en" : "zh";
|
|
660
660
|
}
|
|
661
661
|
function Z(e) {
|
|
662
|
-
return
|
|
662
|
+
return ve = At(e), ve;
|
|
663
663
|
}
|
|
664
|
-
function
|
|
664
|
+
function St(e, t) {
|
|
665
665
|
return t ? e.replace(/\{([a-zA-Z0-9_]+)\}/g, (a, i) => {
|
|
666
666
|
if (!(i in t))
|
|
667
667
|
return `{${i}}`;
|
|
@@ -670,15 +670,15 @@ function At(e, t) {
|
|
|
670
670
|
}) : e;
|
|
671
671
|
}
|
|
672
672
|
function r(e, t) {
|
|
673
|
-
const a =
|
|
674
|
-
return
|
|
673
|
+
const a = Se[ve][e] ?? Se.zh[e] ?? e;
|
|
674
|
+
return St(a, t);
|
|
675
675
|
}
|
|
676
|
-
function
|
|
676
|
+
function Xe(e) {
|
|
677
677
|
return e.endsWith(`
|
|
678
678
|
`) ? e : `${e}
|
|
679
679
|
`;
|
|
680
680
|
}
|
|
681
|
-
async function
|
|
681
|
+
async function _e(e) {
|
|
682
682
|
try {
|
|
683
683
|
return await p.readFile(e, "utf8");
|
|
684
684
|
} catch (t) {
|
|
@@ -688,9 +688,9 @@ async function pe(e) {
|
|
|
688
688
|
}
|
|
689
689
|
}
|
|
690
690
|
function Q(e, t) {
|
|
691
|
-
const a = [], i =
|
|
691
|
+
const a = [], i = mt(e, a, { allowTrailingComma: !0 });
|
|
692
692
|
if (a.length > 0) {
|
|
693
|
-
const n = a.map((o) => `${
|
|
693
|
+
const n = a.map((o) => `${vt(o.error)}@${o.offset}`).join(", ");
|
|
694
694
|
throw new Error(
|
|
695
695
|
r("util.jsonc.error.parse_file", {
|
|
696
696
|
filePath: t,
|
|
@@ -700,10 +700,10 @@ function Q(e, t) {
|
|
|
700
700
|
}
|
|
701
701
|
return i;
|
|
702
702
|
}
|
|
703
|
-
function
|
|
703
|
+
function xt(e, t) {
|
|
704
704
|
let a = e;
|
|
705
705
|
for (const [i, n] of Object.entries(t)) {
|
|
706
|
-
const o =
|
|
706
|
+
const o = ht(a, [i], n, {
|
|
707
707
|
isArrayInsertion: !1,
|
|
708
708
|
formattingOptions: {
|
|
709
709
|
insertSpaces: !0,
|
|
@@ -712,27 +712,27 @@ function St(e, t) {
|
|
|
712
712
|
`
|
|
713
713
|
}
|
|
714
714
|
});
|
|
715
|
-
a =
|
|
715
|
+
a = ft(a, o);
|
|
716
716
|
}
|
|
717
|
-
return
|
|
717
|
+
return Xe(a);
|
|
718
718
|
}
|
|
719
|
-
async function
|
|
720
|
-
const a = await
|
|
719
|
+
async function he(e, t) {
|
|
720
|
+
const a = await _e(e);
|
|
721
721
|
return !a || !a.trim() ? t : Q(a, e);
|
|
722
722
|
}
|
|
723
|
-
async function
|
|
724
|
-
await
|
|
723
|
+
async function xe(e, t) {
|
|
724
|
+
await _e(e) === void 0 && await p.writeFile(e, Xe(t), "utf8");
|
|
725
725
|
}
|
|
726
|
-
async function
|
|
727
|
-
const i = await
|
|
726
|
+
async function Ve(e, t, a) {
|
|
727
|
+
const i = await _e(e), n = i && i.trim().length > 0 ? i : a;
|
|
728
728
|
Q(n, e);
|
|
729
|
-
const o =
|
|
729
|
+
const o = xt(n, t);
|
|
730
730
|
await p.writeFile(e, o, "utf8");
|
|
731
731
|
}
|
|
732
732
|
var S = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Protected = "Protected", e))(S || {}), y = /* @__PURE__ */ ((e) => (e.Archived = "Archived", e.Restored = "Restored", e))(y || {}), w = /* @__PURE__ */ ((e) => (e.Info = "Info", e.Warn = "Warn", e.Error = "Error", e))(w || {}), g;
|
|
733
733
|
((e) => {
|
|
734
|
-
e.VaultId = 0, e.VaultName = "@", e.Config = Q(
|
|
735
|
-
|
|
734
|
+
e.VaultId = 0, e.VaultName = "@", e.Config = Q(ue, "default-files/config.default.jsonc"), e.AutoIncr = Q(
|
|
735
|
+
me,
|
|
736
736
|
"default-files/auto-incr.default.jsonc"
|
|
737
737
|
), e.Vault = {
|
|
738
738
|
id: e.VaultId,
|
|
@@ -742,7 +742,7 @@ var S = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Pro
|
|
|
742
742
|
status: S.Protected
|
|
743
743
|
}, e.LogTail = 15;
|
|
744
744
|
})(g || (g = {}));
|
|
745
|
-
const
|
|
745
|
+
const Vt = () => process.env.ARCHIVER_PATH ?? D(gt(), ".archiver"), $ = Vt();
|
|
746
746
|
var f;
|
|
747
747
|
((e) => {
|
|
748
748
|
e.Dir = {
|
|
@@ -760,19 +760,19 @@ var M;
|
|
|
760
760
|
((e) => {
|
|
761
761
|
e.CheckInterval = 1440 * 60 * 1e3, e.Repo = process.env.ARCHIVER_GITHUB_REPO ?? "aldia/archiver", e.Timeout = 1e4;
|
|
762
762
|
})(M || (M = {}));
|
|
763
|
-
const
|
|
764
|
-
function
|
|
763
|
+
const Rt = "archiver", z = (e) => e.toString().padStart(2, "0"), Lt = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
764
|
+
function we(e = /* @__PURE__ */ new Date()) {
|
|
765
765
|
const t = e.getFullYear(), a = z(e.getMonth() + 1), i = z(e.getDate()), n = z(e.getHours()), o = z(e.getMinutes()), c = z(e.getSeconds());
|
|
766
766
|
return `${t}-${a}-${i} ${n}:${o}:${c}`;
|
|
767
767
|
}
|
|
768
|
-
function
|
|
768
|
+
function se(e) {
|
|
769
769
|
if (!/^\d{6}$/.test(e))
|
|
770
770
|
return;
|
|
771
771
|
const t = Number(e.slice(0, 4)), a = Number(e.slice(4, 6));
|
|
772
772
|
if (!(a < 1 || a > 12))
|
|
773
773
|
return { year: t, month: a };
|
|
774
774
|
}
|
|
775
|
-
function
|
|
775
|
+
function Re(e) {
|
|
776
776
|
if (e.length === 0)
|
|
777
777
|
throw new Error(r("util.parse.error.at_least_one_id"));
|
|
778
778
|
const t = e.map((i) => {
|
|
@@ -784,19 +784,19 @@ function Ve(e) {
|
|
|
784
784
|
throw new Error(r("util.parse.error.duplicate_ids"));
|
|
785
785
|
return t;
|
|
786
786
|
}
|
|
787
|
-
function
|
|
787
|
+
function Tt(e) {
|
|
788
788
|
if (!e)
|
|
789
789
|
return { mode: "all" };
|
|
790
790
|
if (["all", "*", "a"].includes(e.toLowerCase()))
|
|
791
791
|
return { mode: "all" };
|
|
792
792
|
if (/^\d{6}$/.test(e)) {
|
|
793
|
-
if (!
|
|
793
|
+
if (!se(e))
|
|
794
794
|
throw new Error(r("util.parse.error.invalid_month_range", { range: e }));
|
|
795
795
|
return { mode: "month", from: e, to: e };
|
|
796
796
|
}
|
|
797
797
|
const t = e.split("-");
|
|
798
798
|
if (t.length === 2 && /^\d{6}$/.test(t[0]) && /^\d{6}$/.test(t[1])) {
|
|
799
|
-
const a =
|
|
799
|
+
const a = se(t[0]), i = se(t[1]);
|
|
800
800
|
if (!a || !i)
|
|
801
801
|
throw new Error(r("util.parse.error.invalid_range", { range: e }));
|
|
802
802
|
if (t[0] > t[1])
|
|
@@ -808,19 +808,19 @@ function Lt(e) {
|
|
|
808
808
|
function ne(e, t) {
|
|
809
809
|
return t === "green" ? v.black.bgGreen(` ${e} `) : t === "cyan" ? v.black.bgCyan(` ${e} `) : t === "yellow" ? v.black.bgYellow(` ${e} `) : v.white.bgRed(` ${e} `);
|
|
810
810
|
}
|
|
811
|
-
function
|
|
811
|
+
function k(e) {
|
|
812
812
|
console.log(`${ne(r("terminal.badge.ok"), "green")} ${v.green(e)}`);
|
|
813
813
|
}
|
|
814
|
-
function
|
|
814
|
+
function E(e) {
|
|
815
815
|
console.log(`${ne(r("terminal.badge.info"), "cyan")} ${v.cyan(e)}`);
|
|
816
816
|
}
|
|
817
|
-
function
|
|
817
|
+
function le(e) {
|
|
818
818
|
console.log(`${ne(r("terminal.badge.warn"), "yellow")} ${v.yellow(e)}`);
|
|
819
819
|
}
|
|
820
820
|
function j(e) {
|
|
821
821
|
console.error(`${ne(r("terminal.badge.error"), "red")} ${v.red(e)}`);
|
|
822
822
|
}
|
|
823
|
-
function
|
|
823
|
+
function $t(e, t) {
|
|
824
824
|
return Array.from({ length: t }, (a, i) => e[i] ?? "");
|
|
825
825
|
}
|
|
826
826
|
function B(e, t) {
|
|
@@ -829,27 +829,27 @@ function B(e, t) {
|
|
|
829
829
|
const a = e.length, i = [];
|
|
830
830
|
i.push(v.bold(e.join(" "))), i.push(v.dim(e.map((n) => "-".repeat(Math.max(n.length, 3))).join(" ")));
|
|
831
831
|
for (const n of t)
|
|
832
|
-
i.push(
|
|
832
|
+
i.push($t(n, a).join(" "));
|
|
833
833
|
return i.join(`
|
|
834
834
|
`);
|
|
835
835
|
}
|
|
836
|
-
function
|
|
836
|
+
function Ze(e) {
|
|
837
837
|
const t = e.toLowerCase();
|
|
838
838
|
return e === "A" || t === "archived" ? e === "A" ? v.green(e) : v.green(r("terminal.status.archive.archived")) : e === "R" || t === "restored" ? e === "R" ? v.gray(e) : v.gray(r("terminal.status.archive.restored")) : e;
|
|
839
839
|
}
|
|
840
|
-
function
|
|
840
|
+
function Nt(e) {
|
|
841
841
|
return e === "Valid" ? v.green(r("terminal.status.vault.valid")) : e === "Removed" ? v.yellow(r("terminal.status.vault.removed")) : e === "Protected" ? v.cyan(r("terminal.status.vault.protected")) : e;
|
|
842
842
|
}
|
|
843
|
-
function
|
|
843
|
+
function Le(e) {
|
|
844
844
|
return e === "ERROR" || e === "FATAL" ? v.red(r(e === "ERROR" ? "terminal.status.log.error" : "terminal.status.log.fatal")) : e === "WARN" ? v.yellow(r("terminal.status.log.warn")) : e === "INFO" ? v.cyan(r("terminal.status.log.info")) : e;
|
|
845
845
|
}
|
|
846
|
-
function
|
|
846
|
+
function Dt(e) {
|
|
847
847
|
return e === "put" ? r("command.batch.operation.put") : e === "restore" ? r("command.batch.operation.restore") : e === "move" ? r("command.batch.operation.move") : e;
|
|
848
848
|
}
|
|
849
849
|
function K(e, t) {
|
|
850
|
-
|
|
850
|
+
E(
|
|
851
851
|
r("command.batch.summary", {
|
|
852
|
-
operation:
|
|
852
|
+
operation: Dt(e),
|
|
853
853
|
ok: t.ok.length,
|
|
854
854
|
failed: t.failed.length
|
|
855
855
|
})
|
|
@@ -865,7 +865,7 @@ async function V(e) {
|
|
|
865
865
|
}
|
|
866
866
|
try {
|
|
867
867
|
const a = await e.updateService.checkLatest();
|
|
868
|
-
await e.configService.updateLastCheck(
|
|
868
|
+
await e.configService.updateLastCheck(Lt()), a.hasUpdate && E(
|
|
869
869
|
r("command.auto_update.new_available", {
|
|
870
870
|
latestVersion: a.latestVersion,
|
|
871
871
|
currentVersion: a.currentVersion
|
|
@@ -882,12 +882,12 @@ async function b(e) {
|
|
|
882
882
|
j(t.message), process.exitCode = 1;
|
|
883
883
|
}
|
|
884
884
|
}
|
|
885
|
-
function
|
|
885
|
+
function Pt(e, t) {
|
|
886
886
|
e.command("put").description(r("command.archive.put.description")).argument("<items...>", r("command.archive.put.argument.items")).option("-v, --vault <vault>", r("command.archive.put.option.vault")).option("-m, --message <message>", r("command.archive.put.option.message")).option("-r, --remark <remark>", r("command.archive.put.option.remark")).action(
|
|
887
887
|
(a, i) => b(async () => {
|
|
888
888
|
const n = await t.archiveService.put(a, i);
|
|
889
889
|
for (const o of n.ok)
|
|
890
|
-
|
|
890
|
+
k(
|
|
891
891
|
r("command.archive.result.put.ok", {
|
|
892
892
|
id: o.id,
|
|
893
893
|
input: o.input,
|
|
@@ -906,9 +906,9 @@ function Dt(e, t) {
|
|
|
906
906
|
})
|
|
907
907
|
), e.command("restore").description(r("command.archive.restore.description")).argument("<ids...>", r("command.archive.restore.argument.ids")).action(
|
|
908
908
|
(a) => b(async () => {
|
|
909
|
-
const i =
|
|
909
|
+
const i = Re(a), n = await t.archiveService.restore(i);
|
|
910
910
|
for (const o of n.ok)
|
|
911
|
-
|
|
911
|
+
k(
|
|
912
912
|
r("command.archive.result.restore.ok", {
|
|
913
913
|
id: o.id,
|
|
914
914
|
message: o.message
|
|
@@ -925,9 +925,9 @@ function Dt(e, t) {
|
|
|
925
925
|
})
|
|
926
926
|
), e.command("move").description(r("command.archive.move.description")).argument("<ids...>", r("command.archive.move.argument.ids")).requiredOption("--to <vault>", r("command.archive.move.option.to")).action(
|
|
927
927
|
(a, i) => b(async () => {
|
|
928
|
-
const n =
|
|
928
|
+
const n = Re(a), o = await t.archiveService.move(n, i.to);
|
|
929
929
|
for (const c of o.ok)
|
|
930
|
-
|
|
930
|
+
k(
|
|
931
931
|
r("command.archive.result.move.ok", {
|
|
932
932
|
id: c.id,
|
|
933
933
|
message: c.message
|
|
@@ -944,35 +944,35 @@ function Dt(e, t) {
|
|
|
944
944
|
})
|
|
945
945
|
);
|
|
946
946
|
}
|
|
947
|
-
const
|
|
948
|
-
function
|
|
947
|
+
const Mt = v.level;
|
|
948
|
+
function Ot(e) {
|
|
949
949
|
if (typeof e != "string")
|
|
950
950
|
return;
|
|
951
951
|
const t = e.trim().toLowerCase();
|
|
952
952
|
if (t === "on" || t === "off")
|
|
953
953
|
return t;
|
|
954
954
|
}
|
|
955
|
-
function
|
|
956
|
-
return
|
|
955
|
+
function Ft(e, t = process.env) {
|
|
956
|
+
return Ot(t.ARCHIVER_STYLE) ?? e;
|
|
957
957
|
}
|
|
958
|
-
function
|
|
958
|
+
function jt(e) {
|
|
959
959
|
if (e === "off") {
|
|
960
960
|
v.level = 0;
|
|
961
961
|
return;
|
|
962
962
|
}
|
|
963
|
-
v.level = Math.max(
|
|
963
|
+
v.level = Math.max(Mt, 1);
|
|
964
964
|
}
|
|
965
965
|
function ee(e, t = process.env) {
|
|
966
|
-
const a =
|
|
967
|
-
return
|
|
966
|
+
const a = Ft(e.style, t);
|
|
967
|
+
return jt(a), a;
|
|
968
968
|
}
|
|
969
|
-
function
|
|
969
|
+
function Qe(e, t) {
|
|
970
970
|
return e < 0 ? 0 : e > t.length ? t.length : e;
|
|
971
971
|
}
|
|
972
972
|
function P(e, t) {
|
|
973
|
-
return { value: e, cursor:
|
|
973
|
+
return { value: e, cursor: Qe(t, e) };
|
|
974
974
|
}
|
|
975
|
-
function
|
|
975
|
+
function Yt(e) {
|
|
976
976
|
if (!e)
|
|
977
977
|
return !1;
|
|
978
978
|
for (const t of e) {
|
|
@@ -982,13 +982,13 @@ function jt(e) {
|
|
|
982
982
|
}
|
|
983
983
|
return !0;
|
|
984
984
|
}
|
|
985
|
-
function
|
|
985
|
+
function Ht(e = "") {
|
|
986
986
|
return { value: e, cursor: e.length };
|
|
987
987
|
}
|
|
988
|
-
function
|
|
988
|
+
function Te(e, t) {
|
|
989
989
|
return t === "left" ? P(e.value, e.cursor - 1) : P(e.value, e.cursor + 1);
|
|
990
990
|
}
|
|
991
|
-
function
|
|
991
|
+
function $e(e, t, a) {
|
|
992
992
|
if (a.ctrl && a.name === "c")
|
|
993
993
|
return { state: e, action: "cancel" };
|
|
994
994
|
if (a.name === "escape")
|
|
@@ -996,9 +996,9 @@ function Te(e, t, a) {
|
|
|
996
996
|
if (a.name === "return" || a.name === "enter")
|
|
997
997
|
return { state: e, action: "submit" };
|
|
998
998
|
if (a.name === "left")
|
|
999
|
-
return { state:
|
|
999
|
+
return { state: Te(e, "left"), action: "continue" };
|
|
1000
1000
|
if (a.name === "right")
|
|
1001
|
-
return { state:
|
|
1001
|
+
return { state: Te(e, "right"), action: "continue" };
|
|
1002
1002
|
if (a.name === "home")
|
|
1003
1003
|
return { state: P(e.value, 0), action: "continue" };
|
|
1004
1004
|
if (a.name === "end")
|
|
@@ -1015,36 +1015,43 @@ function Te(e, t, a) {
|
|
|
1015
1015
|
const n = `${e.value.slice(0, e.cursor)}${e.value.slice(e.cursor + 1)}`;
|
|
1016
1016
|
return { state: P(n, e.cursor), action: "continue" };
|
|
1017
1017
|
}
|
|
1018
|
-
if (!
|
|
1018
|
+
if (!Yt(t))
|
|
1019
1019
|
return { state: e, action: "continue" };
|
|
1020
1020
|
const i = `${e.value.slice(0, e.cursor)}${t}${e.value.slice(e.cursor)}`;
|
|
1021
1021
|
return { state: P(i, e.cursor + t.length), action: "continue" };
|
|
1022
1022
|
}
|
|
1023
|
-
function
|
|
1023
|
+
function Ut(e, t = !0, a = "") {
|
|
1024
1024
|
if (!t) {
|
|
1025
1025
|
const s = e.value || a;
|
|
1026
1026
|
return v.dim(`[${s}]`);
|
|
1027
1027
|
}
|
|
1028
1028
|
if (!e.value)
|
|
1029
1029
|
return a ? `[${v.dim(a)}]` : `[${v.inverse(" ")}]`;
|
|
1030
|
-
const i =
|
|
1030
|
+
const i = Qe(e.cursor, e.value);
|
|
1031
1031
|
if (i >= e.value.length)
|
|
1032
1032
|
return `[${e.value}${v.inverse(" ")}]`;
|
|
1033
1033
|
const n = e.value.slice(0, i), o = e.value.slice(i, i + 1), c = e.value.slice(i + 1);
|
|
1034
1034
|
return `[${n}${v.inverse(o)}${c}]`;
|
|
1035
1035
|
}
|
|
1036
|
-
function
|
|
1036
|
+
function zt(e) {
|
|
1037
1037
|
return typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : 24;
|
|
1038
1038
|
}
|
|
1039
|
-
function
|
|
1040
|
-
const t = e.contentLines.length > 0 ? e.contentLines : [""], a = e.footerLines ?? [], i =
|
|
1039
|
+
function Bt(e) {
|
|
1040
|
+
const t = e.contentLines.length > 0 ? e.contentLines : [""], a = e.footerLines ?? [], i = zt(e.rows), n = Math.max(i - t.length - a.length, 0);
|
|
1041
1041
|
return [...t, ...Array.from({ length: n }, () => ""), ...a];
|
|
1042
1042
|
}
|
|
1043
|
-
function Ie(e
|
|
1043
|
+
function Ie(e) {
|
|
1044
|
+
return Bt({
|
|
1045
|
+
contentLines: e.contentLines,
|
|
1046
|
+
footerLines: [e.hintLine ?? "", e.statusLine ?? ""],
|
|
1047
|
+
rows: e.rows
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
function ye(e = {}) {
|
|
1044
1051
|
const t = e.stdinIsTTY ?? !!process.stdin.isTTY, a = e.stdoutIsTTY ?? !!process.stdout.isTTY, i = e.forceInteractive ?? process.env.ARCHIVER_FORCE_INTERACTIVE === "1", n = e.hasRawMode ?? typeof process.stdin.setRawMode == "function";
|
|
1045
1052
|
return t && n && (a || i);
|
|
1046
1053
|
}
|
|
1047
|
-
function
|
|
1054
|
+
function et(e, t, a) {
|
|
1048
1055
|
if (e.length === 0)
|
|
1049
1056
|
return;
|
|
1050
1057
|
const i = a === "left" ? -1 : 1;
|
|
@@ -1059,48 +1066,52 @@ function O(e, t) {
|
|
|
1059
1066
|
return { options: e, selectedIndex: 0 };
|
|
1060
1067
|
let a = t === void 0 ? 0 : e.findIndex((i) => Object.is(i.value, t));
|
|
1061
1068
|
if (a < 0 && (a = 0), e[a]?.disabled) {
|
|
1062
|
-
const i =
|
|
1069
|
+
const i = et(e, a, "right");
|
|
1063
1070
|
i !== void 0 && (a = i);
|
|
1064
1071
|
}
|
|
1065
1072
|
return { options: e, selectedIndex: a };
|
|
1066
1073
|
}
|
|
1067
1074
|
function q(e, t) {
|
|
1068
|
-
const a =
|
|
1075
|
+
const a = et(e.options, e.selectedIndex, t);
|
|
1069
1076
|
return a === void 0 ? e : { ...e, selectedIndex: a };
|
|
1070
1077
|
}
|
|
1071
1078
|
function H(e) {
|
|
1072
1079
|
return e.options[e.selectedIndex];
|
|
1073
1080
|
}
|
|
1074
|
-
function
|
|
1081
|
+
function qt(e) {
|
|
1075
1082
|
return Math.max(...e.map((t) => t.label.length), 1);
|
|
1076
1083
|
}
|
|
1077
|
-
function
|
|
1084
|
+
function Wt(e, t, a, i) {
|
|
1078
1085
|
const o = `${e.disabled ? "x" : t ? ">" : " "} ${e.label.padEnd(i, " ")}`;
|
|
1079
1086
|
return e.disabled ? v.dim(`[${o}]`) : t && a ? v.black.bgGreen(`[${o}]`) : t ? v.green(`[${o}]`) : a ? v.green(`[${o}]`) : v.dim(`[${o}]`);
|
|
1080
1087
|
}
|
|
1081
1088
|
function te(e, t = !0) {
|
|
1082
|
-
const a =
|
|
1083
|
-
return e.options.map((i, n) =>
|
|
1089
|
+
const a = qt(e.options);
|
|
1090
|
+
return e.options.map((i, n) => Wt(i, n === e.selectedIndex, t, a)).join(" ");
|
|
1084
1091
|
}
|
|
1085
1092
|
function R(e) {
|
|
1086
1093
|
return v.black.bgWhite(` ${e} `);
|
|
1087
1094
|
}
|
|
1088
|
-
async function
|
|
1095
|
+
async function Jt(e) {
|
|
1089
1096
|
const t = O(e.options, e.initialValue);
|
|
1090
1097
|
if (e.options.length === 0)
|
|
1091
1098
|
return null;
|
|
1092
|
-
if (!
|
|
1099
|
+
if (!ye())
|
|
1093
1100
|
return H(t)?.value ?? null;
|
|
1094
1101
|
const a = process.stdin;
|
|
1095
1102
|
let i = t;
|
|
1096
|
-
return
|
|
1103
|
+
return pe.emitKeypressEvents(a), a.setRawMode(!0), a.resume(), new Promise((n) => {
|
|
1097
1104
|
const o = () => {
|
|
1098
1105
|
const l = [e.title];
|
|
1099
1106
|
e.description && l.push(v.dim(e.description)), l.push("", te(i));
|
|
1100
|
-
const d =
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1107
|
+
const d = Ie({
|
|
1108
|
+
contentLines: l,
|
|
1109
|
+
hintLine: e.hint,
|
|
1110
|
+
statusLine: "",
|
|
1111
|
+
rows: process.stdout.rows
|
|
1112
|
+
});
|
|
1113
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(d.join(`
|
|
1114
|
+
`));
|
|
1104
1115
|
}, c = (l) => {
|
|
1105
1116
|
a.off("keypress", s), a.setRawMode(!1), a.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1106
1117
|
`), n(l);
|
|
@@ -1127,8 +1138,8 @@ async function qt(e) {
|
|
|
1127
1138
|
a.on("keypress", s), o();
|
|
1128
1139
|
});
|
|
1129
1140
|
}
|
|
1130
|
-
const
|
|
1131
|
-
function
|
|
1141
|
+
const Gt = ["updateCheck", "vaultItemSeparator", "style", "language", "noCommandAction"];
|
|
1142
|
+
function Kt(e) {
|
|
1132
1143
|
return {
|
|
1133
1144
|
updateCheck: e.updateCheck,
|
|
1134
1145
|
vaultItemSeparator: e.vaultItemSeparator,
|
|
@@ -1137,7 +1148,7 @@ function Jt(e) {
|
|
|
1137
1148
|
noCommandAction: e.noCommandAction
|
|
1138
1149
|
};
|
|
1139
1150
|
}
|
|
1140
|
-
function
|
|
1151
|
+
function Xt(e, t) {
|
|
1141
1152
|
return {
|
|
1142
1153
|
...e,
|
|
1143
1154
|
updateCheck: t.updateCheck,
|
|
@@ -1147,17 +1158,17 @@ function Gt(e, t) {
|
|
|
1147
1158
|
noCommandAction: t.noCommandAction
|
|
1148
1159
|
};
|
|
1149
1160
|
}
|
|
1150
|
-
function
|
|
1151
|
-
return
|
|
1161
|
+
function tt(e, t) {
|
|
1162
|
+
return Gt.every((a) => e[a] === t[a]);
|
|
1152
1163
|
}
|
|
1153
|
-
function
|
|
1164
|
+
function Zt(e) {
|
|
1154
1165
|
if (!e.vaultItemSeparator.trim())
|
|
1155
1166
|
return "command.config.vault_item_sep.error.empty";
|
|
1156
1167
|
}
|
|
1157
|
-
function
|
|
1168
|
+
function Qt() {
|
|
1158
1169
|
return !!(process.stdin.isTTY && process.stdout.isTTY && typeof process.stdin.setRawMode == "function");
|
|
1159
1170
|
}
|
|
1160
|
-
function
|
|
1171
|
+
function ea(e) {
|
|
1161
1172
|
return [
|
|
1162
1173
|
{
|
|
1163
1174
|
kind: "select",
|
|
@@ -1175,7 +1186,7 @@ function Zt(e) {
|
|
|
1175
1186
|
kind: "input",
|
|
1176
1187
|
key: "vaultItemSeparator",
|
|
1177
1188
|
label: r("command.config.edit.field.vault_item_sep"),
|
|
1178
|
-
state:
|
|
1189
|
+
state: Ht(e.vaultItemSeparator)
|
|
1179
1190
|
},
|
|
1180
1191
|
{
|
|
1181
1192
|
kind: "select",
|
|
@@ -1216,10 +1227,10 @@ function Zt(e) {
|
|
|
1216
1227
|
}
|
|
1217
1228
|
];
|
|
1218
1229
|
}
|
|
1219
|
-
function
|
|
1230
|
+
function Ne(e, t, a) {
|
|
1220
1231
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1221
1232
|
}
|
|
1222
|
-
function
|
|
1233
|
+
function at(e, t) {
|
|
1223
1234
|
const a = { ...t };
|
|
1224
1235
|
for (const i of e) {
|
|
1225
1236
|
if (i.kind === "input") {
|
|
@@ -1245,11 +1256,11 @@ function tt(e, t) {
|
|
|
1245
1256
|
}
|
|
1246
1257
|
return a;
|
|
1247
1258
|
}
|
|
1248
|
-
function
|
|
1259
|
+
function ta(e) {
|
|
1249
1260
|
return Math.max(...e.map((t) => t.label.length), 1);
|
|
1250
1261
|
}
|
|
1251
1262
|
function N(e, t, a, i, n) {
|
|
1252
|
-
const o =
|
|
1263
|
+
const o = at(e, a), c = !tt(o, a), s = ta(e), l = e.length, d = t === l, m = r("command.config.edit.hint", {
|
|
1253
1264
|
upDown: R(r("command.config.edit.key.up_down")),
|
|
1254
1265
|
leftRight: R(r("command.config.edit.key.left_right")),
|
|
1255
1266
|
type: R(r("command.config.edit.key.type")),
|
|
@@ -1257,37 +1268,37 @@ function N(e, t, a, i, n) {
|
|
|
1257
1268
|
cancel: R(r("command.config.edit.key.cancel"))
|
|
1258
1269
|
}), u = [];
|
|
1259
1270
|
u.push(v.bold(r("command.config.edit.title"))), u.push("");
|
|
1260
|
-
for (let
|
|
1261
|
-
const x = e[
|
|
1271
|
+
for (let L = 0; L < e.length; L += 1) {
|
|
1272
|
+
const x = e[L];
|
|
1262
1273
|
if (!x)
|
|
1263
1274
|
continue;
|
|
1264
|
-
const
|
|
1265
|
-
u.push(`${
|
|
1275
|
+
const T = L === t, re = T ? v.cyan(">") : " ", oe = T ? v.bold(x.label.padEnd(s, " ")) : x.label.padEnd(s, " "), ce = x.kind === "select" ? te(x.state, T) : Ut(x.state, T, r("command.config.edit.input.placeholder"));
|
|
1276
|
+
u.push(`${re} ${oe} ${ce}`);
|
|
1266
1277
|
}
|
|
1267
|
-
u.push(""), u.push(`${r("command.config.edit.action_prefix")} ${te(i, d)}`), u.push("")
|
|
1268
|
-
const _ =
|
|
1278
|
+
u.push(""), u.push(`${r("command.config.edit.action_prefix")} ${te(i, d)}`), u.push("");
|
|
1279
|
+
const _ = n ? v.yellow(n) : v.dim(r(c ? "command.config.edit.state.dirty" : "command.config.edit.state.clean")), A = Ie({
|
|
1269
1280
|
contentLines: u,
|
|
1270
|
-
|
|
1281
|
+
hintLine: m,
|
|
1282
|
+
statusLine: _,
|
|
1271
1283
|
rows: process.stdout.rows
|
|
1272
1284
|
});
|
|
1273
|
-
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(
|
|
1274
|
-
`)
|
|
1275
|
-
`);
|
|
1285
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(A.join(`
|
|
1286
|
+
`));
|
|
1276
1287
|
}
|
|
1277
|
-
async function
|
|
1278
|
-
if (!
|
|
1288
|
+
async function aa(e) {
|
|
1289
|
+
if (!Qt())
|
|
1279
1290
|
throw new Error(r("command.config.edit.error.no_tty"));
|
|
1280
|
-
const t = process.stdin, a =
|
|
1291
|
+
const t = process.stdin, a = ea(e);
|
|
1281
1292
|
let i = O([
|
|
1282
1293
|
{ value: "save", label: r("command.config.edit.action.save") },
|
|
1283
1294
|
{ value: "cancel", label: r("command.config.edit.action.cancel") }
|
|
1284
1295
|
]), n = 0, o = "";
|
|
1285
|
-
return
|
|
1296
|
+
return pe.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((c) => {
|
|
1286
1297
|
const s = (m) => {
|
|
1287
1298
|
t.off("keypress", d), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1288
1299
|
`), c(m);
|
|
1289
1300
|
}, l = () => {
|
|
1290
|
-
const m =
|
|
1301
|
+
const m = at(a, e), u = Zt(m);
|
|
1291
1302
|
if (u) {
|
|
1292
1303
|
o = r(u), N(a, n, e, i, o);
|
|
1293
1304
|
return;
|
|
@@ -1303,11 +1314,11 @@ async function ea(e) {
|
|
|
1303
1314
|
return;
|
|
1304
1315
|
}
|
|
1305
1316
|
if (u.name === "up") {
|
|
1306
|
-
n =
|
|
1317
|
+
n = Ne(n, "up", a.length + 1), o = "", N(a, n, e, i, o);
|
|
1307
1318
|
return;
|
|
1308
1319
|
}
|
|
1309
1320
|
if (u.name === "down") {
|
|
1310
|
-
n =
|
|
1321
|
+
n = Ne(n, "down", a.length + 1), o = "", N(a, n, e, i, o);
|
|
1311
1322
|
return;
|
|
1312
1323
|
}
|
|
1313
1324
|
if (n === a.length) {
|
|
@@ -1338,16 +1349,16 @@ async function ea(e) {
|
|
|
1338
1349
|
return;
|
|
1339
1350
|
}
|
|
1340
1351
|
if (u.name === "left" || u.name === "right") {
|
|
1341
|
-
_.kind === "select" ? _.state = q(_.state, u.name) : _.state =
|
|
1352
|
+
_.kind === "select" ? _.state = q(_.state, u.name) : _.state = $e(_.state, m, u).state, o = "", N(a, n, e, i, o);
|
|
1342
1353
|
return;
|
|
1343
1354
|
}
|
|
1344
1355
|
if (_.kind === "input") {
|
|
1345
|
-
const
|
|
1346
|
-
if (_.state =
|
|
1356
|
+
const A = $e(_.state, m, u);
|
|
1357
|
+
if (_.state = A.state, A.action === "cancel") {
|
|
1347
1358
|
s(null);
|
|
1348
1359
|
return;
|
|
1349
1360
|
}
|
|
1350
|
-
if (
|
|
1361
|
+
if (A.action === "submit") {
|
|
1351
1362
|
l();
|
|
1352
1363
|
return;
|
|
1353
1364
|
}
|
|
@@ -1359,7 +1370,7 @@ async function ea(e) {
|
|
|
1359
1370
|
t.on("keypress", d), N(a, n, e, i, o);
|
|
1360
1371
|
});
|
|
1361
1372
|
}
|
|
1362
|
-
function
|
|
1373
|
+
function ia(e, t) {
|
|
1363
1374
|
const a = e.command("config").description(r("command.config.description"));
|
|
1364
1375
|
a.command("list").description(r("command.config.list.description")).option("-c, --comment", r("command.config.list.option.comment")).action(
|
|
1365
1376
|
(i) => b(async () => {
|
|
@@ -1389,17 +1400,17 @@ function ta(e, t) {
|
|
|
1389
1400
|
})
|
|
1390
1401
|
), a.command("edit").alias("e").description(r("command.config.edit.description")).action(
|
|
1391
1402
|
() => b(async () => {
|
|
1392
|
-
const i = await t.configService.getConfig(), n =
|
|
1403
|
+
const i = await t.configService.getConfig(), n = Kt(i), o = await aa(n);
|
|
1393
1404
|
if (!o) {
|
|
1394
|
-
|
|
1405
|
+
E(r("command.config.edit.cancelled"));
|
|
1395
1406
|
return;
|
|
1396
1407
|
}
|
|
1397
|
-
if (
|
|
1398
|
-
|
|
1408
|
+
if (tt(n, o)) {
|
|
1409
|
+
E(r("command.config.edit.no_changes"));
|
|
1399
1410
|
return;
|
|
1400
1411
|
}
|
|
1401
|
-
const c =
|
|
1402
|
-
await t.context.saveConfig(c), ee(c),
|
|
1412
|
+
const c = Xt(i, o);
|
|
1413
|
+
await t.context.saveConfig(c), ee(c), k(r("command.config.edit.saved")), await t.auditLogger.log(
|
|
1403
1414
|
"INFO",
|
|
1404
1415
|
{ main: "config", sub: "edit", source: "u" },
|
|
1405
1416
|
r("command.config.edit.audit.saved")
|
|
@@ -1410,7 +1421,7 @@ function ta(e, t) {
|
|
|
1410
1421
|
const n = i.toLowerCase();
|
|
1411
1422
|
if (n !== "on" && n !== "off")
|
|
1412
1423
|
throw new Error(r("command.config.state.error"));
|
|
1413
|
-
await t.configService.setUpdateCheck(n),
|
|
1424
|
+
await t.configService.setUpdateCheck(n), k(r("command.config.update_check.updated", { state: n })), await t.auditLogger.log(
|
|
1414
1425
|
"INFO",
|
|
1415
1426
|
{ main: "config", sub: "update-check", args: [n], source: "u" },
|
|
1416
1427
|
r("command.config.update_check.updated", { state: n })
|
|
@@ -1422,7 +1433,7 @@ function ta(e, t) {
|
|
|
1422
1433
|
if (n !== "on" && n !== "off")
|
|
1423
1434
|
throw new Error(r("command.config.state.error"));
|
|
1424
1435
|
const o = await t.configService.setStyle(n);
|
|
1425
|
-
ee(o),
|
|
1436
|
+
ee(o), k(r("command.config.style.updated", { state: n })), await t.auditLogger.log(
|
|
1426
1437
|
"INFO",
|
|
1427
1438
|
{ main: "config", sub: "style", args: [n], source: "u" },
|
|
1428
1439
|
r("command.config.style.updated", { state: n })
|
|
@@ -1432,7 +1443,7 @@ function ta(e, t) {
|
|
|
1432
1443
|
(i) => b(async () => {
|
|
1433
1444
|
if (!i.trim())
|
|
1434
1445
|
throw new Error(r("command.config.vault_item_sep.error.empty"));
|
|
1435
|
-
await t.configService.setVaultItemSeparator(i),
|
|
1446
|
+
await t.configService.setVaultItemSeparator(i), k(
|
|
1436
1447
|
r("command.config.vault_item_sep.updated", {
|
|
1437
1448
|
separator: i
|
|
1438
1449
|
})
|
|
@@ -1449,7 +1460,7 @@ function ta(e, t) {
|
|
|
1449
1460
|
const n = i.toLowerCase();
|
|
1450
1461
|
if (n !== "help" && n !== "list" && n !== "unknown")
|
|
1451
1462
|
throw new Error(r("command.config.no_command_action.error.invalid"));
|
|
1452
|
-
await t.configService.setNoCommandAction(n),
|
|
1463
|
+
await t.configService.setNoCommandAction(n), k(r("command.config.no_command_action.updated", { action: n })), await t.auditLogger.log(
|
|
1453
1464
|
"INFO",
|
|
1454
1465
|
{ main: "config", sub: "no-command-action", args: [n], source: "u" },
|
|
1455
1466
|
r("command.config.no_command_action.updated", { action: n })
|
|
@@ -1460,7 +1471,7 @@ function ta(e, t) {
|
|
|
1460
1471
|
const n = i.toLowerCase();
|
|
1461
1472
|
if (n !== "zh" && n !== "en")
|
|
1462
1473
|
throw new Error(r("command.config.language.error.invalid"));
|
|
1463
|
-
await t.configService.setLanguage(n),
|
|
1474
|
+
await t.configService.setLanguage(n), k(r("command.config.language.updated", { language: n })), await t.auditLogger.log(
|
|
1464
1475
|
"INFO",
|
|
1465
1476
|
{ main: "config", sub: "language", args: [n], source: "u" },
|
|
1466
1477
|
r("command.config.language.updated", { language: n })
|
|
@@ -1468,8 +1479,8 @@ function ta(e, t) {
|
|
|
1468
1479
|
})
|
|
1469
1480
|
);
|
|
1470
1481
|
}
|
|
1471
|
-
const
|
|
1472
|
-
function
|
|
1482
|
+
const na = "__ARCHIVER_CD__:";
|
|
1483
|
+
function ra(e, t) {
|
|
1473
1484
|
if (e.includes(`
|
|
1474
1485
|
`) || e.includes("\r"))
|
|
1475
1486
|
throw new Error(
|
|
@@ -1478,38 +1489,38 @@ function ia(e, t) {
|
|
|
1478
1489
|
})
|
|
1479
1490
|
);
|
|
1480
1491
|
}
|
|
1481
|
-
function
|
|
1482
|
-
return
|
|
1492
|
+
function oa(e) {
|
|
1493
|
+
return ra(e, r("util.cd.label.archive_slot_path")), `${na}${e}`;
|
|
1483
1494
|
}
|
|
1484
|
-
async function
|
|
1485
|
-
console.log(
|
|
1495
|
+
async function ca(e) {
|
|
1496
|
+
console.log(oa(e));
|
|
1486
1497
|
}
|
|
1487
|
-
function
|
|
1498
|
+
function De(e) {
|
|
1488
1499
|
return r(e === "enter" ? "command.list.interactive.action.enter" : "command.list.interactive.action.restore");
|
|
1489
1500
|
}
|
|
1490
|
-
function
|
|
1491
|
-
return
|
|
1501
|
+
function it() {
|
|
1502
|
+
return ye();
|
|
1492
1503
|
}
|
|
1493
|
-
function
|
|
1504
|
+
function fe(e, t) {
|
|
1494
1505
|
return t === "enter" || t === "restore" ? e.status === y.Archived : !1;
|
|
1495
1506
|
}
|
|
1496
|
-
function
|
|
1507
|
+
function be(e, t) {
|
|
1497
1508
|
return O(
|
|
1498
1509
|
[
|
|
1499
|
-
{ value: "enter", label:
|
|
1500
|
-
{ value: "restore", label:
|
|
1510
|
+
{ value: "enter", label: De("enter"), disabled: !fe(e, "enter") },
|
|
1511
|
+
{ value: "restore", label: De("restore"), disabled: !fe(e, "restore") }
|
|
1501
1512
|
],
|
|
1502
1513
|
t
|
|
1503
1514
|
);
|
|
1504
1515
|
}
|
|
1505
|
-
function
|
|
1506
|
-
return H(
|
|
1516
|
+
function sa(e, t) {
|
|
1517
|
+
return H(be(e, t))?.value ?? t;
|
|
1507
1518
|
}
|
|
1508
|
-
function
|
|
1509
|
-
const i =
|
|
1519
|
+
function Pe(e, t, a) {
|
|
1520
|
+
const i = be(e, t), n = q(i, a);
|
|
1510
1521
|
return H(n)?.value ?? t;
|
|
1511
1522
|
}
|
|
1512
|
-
function
|
|
1523
|
+
function Me(e, t, a) {
|
|
1513
1524
|
return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
|
|
1514
1525
|
}
|
|
1515
1526
|
function F(e, t, a, i) {
|
|
@@ -1521,38 +1532,36 @@ function F(e, t, a, i) {
|
|
|
1521
1532
|
leftRight: R(r("command.list.interactive.key.left_right")),
|
|
1522
1533
|
enter: R(r("command.list.interactive.key.enter")),
|
|
1523
1534
|
cancel: R(r("command.list.interactive.key.cancel"))
|
|
1524
|
-
}), s =
|
|
1535
|
+
}), s = be(n, a), l = [
|
|
1525
1536
|
`${r("command.list.interactive.action_prefix")} ${te(s)}`,
|
|
1526
|
-
i ? v.yellow(i) : "",
|
|
1527
1537
|
""
|
|
1528
|
-
], m = Math.max(o - l.length - 2, 2), u = Math.max(Math.floor(m / 2), 1), _ = Math.floor(u / 2),
|
|
1529
|
-
for (let W =
|
|
1538
|
+
], m = Math.max(o - l.length - 2, 2), u = Math.max(Math.floor(m / 2), 1), _ = Math.floor(u / 2), A = Math.max(e.length - u, 0), L = Math.min(Math.max(t - _, 0), A), x = Math.min(L + u, e.length), T = [...l];
|
|
1539
|
+
for (let W = L; W < x; W += 1) {
|
|
1530
1540
|
const U = e[W];
|
|
1531
1541
|
if (!U)
|
|
1532
1542
|
continue;
|
|
1533
|
-
const
|
|
1534
|
-
|
|
1535
|
-
}
|
|
1536
|
-
const re =
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(
|
|
1547
|
-
`)
|
|
1548
|
-
`);
|
|
1543
|
+
const Ce = W === t, dt = Ce ? v.cyan(">") : " ", ut = U.status === y.Archived ? v.green("A") : v.gray("R"), Ee = `${dt} [${String(U.id).padStart(4, " ")}] ${ut} ${U.title}`, Ae = ` ${v.dim(U.path)}`;
|
|
1544
|
+
Ce ? (T.push(v.bold(Ee)), T.push(v.cyan(Ae))) : (T.push(Ee), T.push(Ae));
|
|
1545
|
+
}
|
|
1546
|
+
const re = r("command.list.interactive.showing", {
|
|
1547
|
+
start: L + 1,
|
|
1548
|
+
end: x,
|
|
1549
|
+
total: e.length
|
|
1550
|
+
}), oe = i ? v.yellow(i) : v.dim(re), ce = Ie({
|
|
1551
|
+
contentLines: T,
|
|
1552
|
+
hintLine: c,
|
|
1553
|
+
statusLine: oe,
|
|
1554
|
+
rows: o
|
|
1555
|
+
});
|
|
1556
|
+
process.stdout.write("\x1B[2J\x1B[H\x1B[?25l"), process.stdout.write(ce.join(`
|
|
1557
|
+
`));
|
|
1549
1558
|
}
|
|
1550
|
-
async function
|
|
1551
|
-
if (e.length === 0 || !
|
|
1559
|
+
async function la(e) {
|
|
1560
|
+
if (e.length === 0 || !it())
|
|
1552
1561
|
return null;
|
|
1553
1562
|
const t = process.stdin;
|
|
1554
1563
|
let a = 0, i = "enter", n = "";
|
|
1555
|
-
return
|
|
1564
|
+
return pe.emitKeypressEvents(t), t.setRawMode(!0), t.resume(), new Promise((o) => {
|
|
1556
1565
|
const c = (l) => {
|
|
1557
1566
|
t.off("keypress", s), t.setRawMode(!1), t.pause(), process.stdout.write(`\x1B[2J\x1B[H\x1B[?25h
|
|
1558
1567
|
`), o(l);
|
|
@@ -1562,11 +1571,11 @@ async function ca(e) {
|
|
|
1562
1571
|
return;
|
|
1563
1572
|
}
|
|
1564
1573
|
if (d.name === "up") {
|
|
1565
|
-
a =
|
|
1574
|
+
a = Me(a, "up", e.length), n = "", F(e, a, i, n);
|
|
1566
1575
|
return;
|
|
1567
1576
|
}
|
|
1568
1577
|
if (d.name === "down") {
|
|
1569
|
-
a =
|
|
1578
|
+
a = Me(a, "down", e.length), n = "", F(e, a, i, n);
|
|
1570
1579
|
return;
|
|
1571
1580
|
}
|
|
1572
1581
|
if (d.name === "left") {
|
|
@@ -1575,7 +1584,7 @@ async function ca(e) {
|
|
|
1575
1584
|
c(null);
|
|
1576
1585
|
return;
|
|
1577
1586
|
}
|
|
1578
|
-
i =
|
|
1587
|
+
i = Pe(m, i, "left"), n = "", F(e, a, i, n);
|
|
1579
1588
|
return;
|
|
1580
1589
|
}
|
|
1581
1590
|
if (d.name === "right") {
|
|
@@ -1584,7 +1593,7 @@ async function ca(e) {
|
|
|
1584
1593
|
c(null);
|
|
1585
1594
|
return;
|
|
1586
1595
|
}
|
|
1587
|
-
i =
|
|
1596
|
+
i = Pe(m, i, "right"), n = "", F(e, a, i, n);
|
|
1588
1597
|
return;
|
|
1589
1598
|
}
|
|
1590
1599
|
if (d.name === "return" || d.name === "enter") {
|
|
@@ -1593,8 +1602,8 @@ async function ca(e) {
|
|
|
1593
1602
|
c(null);
|
|
1594
1603
|
return;
|
|
1595
1604
|
}
|
|
1596
|
-
const u =
|
|
1597
|
-
if (!
|
|
1605
|
+
const u = sa(m, i);
|
|
1606
|
+
if (!fe(m, u)) {
|
|
1598
1607
|
n = r("command.list.interactive.note.restored_unavailable"), F(e, a, i, n);
|
|
1599
1608
|
return;
|
|
1600
1609
|
}
|
|
@@ -1606,41 +1615,41 @@ async function ca(e) {
|
|
|
1606
1615
|
t.on("keypress", s), F(e, a, i, n);
|
|
1607
1616
|
});
|
|
1608
1617
|
}
|
|
1609
|
-
function
|
|
1618
|
+
function ke(e, t) {
|
|
1610
1619
|
return e.vaultId === g.Vault.id ? e.item : `${e.vaultName}${t}${e.item}`;
|
|
1611
1620
|
}
|
|
1612
|
-
function
|
|
1621
|
+
function da(e) {
|
|
1613
1622
|
return String(e).padStart(4, "0");
|
|
1614
1623
|
}
|
|
1615
|
-
function
|
|
1624
|
+
function nt(e) {
|
|
1616
1625
|
return e.status === y.Archived ? "A" : "R";
|
|
1617
1626
|
}
|
|
1618
|
-
function
|
|
1619
|
-
const a =
|
|
1620
|
-
return `[${
|
|
1627
|
+
function ua(e, t) {
|
|
1628
|
+
const a = Ze(nt(e));
|
|
1629
|
+
return `[${da(e.id)}] ${a} ${ke(e, t)}`;
|
|
1621
1630
|
}
|
|
1622
|
-
function
|
|
1623
|
-
return e.map((a) =>
|
|
1631
|
+
function ma(e, t) {
|
|
1632
|
+
return e.map((a) => ua(a, t)).join(`
|
|
1624
1633
|
`);
|
|
1625
1634
|
}
|
|
1626
|
-
function
|
|
1627
|
-
return e.map((a) => `${a.id} ${
|
|
1635
|
+
function va(e, t) {
|
|
1636
|
+
return e.map((a) => `${a.id} ${nt(a)} ${ke(a, t)}`).join(`
|
|
1628
1637
|
`);
|
|
1629
1638
|
}
|
|
1630
|
-
function
|
|
1639
|
+
function ha(e, t) {
|
|
1631
1640
|
return e.map((a) => ({
|
|
1632
1641
|
id: a.id,
|
|
1633
1642
|
status: a.status,
|
|
1634
|
-
title:
|
|
1643
|
+
title: ke(a, t),
|
|
1635
1644
|
path: a.displayPath
|
|
1636
1645
|
}));
|
|
1637
1646
|
}
|
|
1638
|
-
async function
|
|
1647
|
+
async function fa(e, t) {
|
|
1639
1648
|
const a = t.entry.id;
|
|
1640
1649
|
if (t.action === "restore") {
|
|
1641
1650
|
const n = await e.archiveService.restore([a]);
|
|
1642
1651
|
for (const o of n.ok)
|
|
1643
|
-
|
|
1652
|
+
k(
|
|
1644
1653
|
r("command.archive.result.restore.ok", {
|
|
1645
1654
|
id: o.id,
|
|
1646
1655
|
message: o.message
|
|
@@ -1670,37 +1679,37 @@ async function va(e, t) {
|
|
|
1670
1679
|
archiveId: i.archiveId
|
|
1671
1680
|
}),
|
|
1672
1681
|
{ aid: i.archiveId, vid: i.vault.id }
|
|
1673
|
-
), await
|
|
1682
|
+
), await ca(i.slotPath);
|
|
1674
1683
|
}
|
|
1675
|
-
function
|
|
1684
|
+
function ga(e, t) {
|
|
1676
1685
|
e.command("list").description(r("command.list.description")).option("-r, --restored", r("command.list.option.restored")).option("-a, --all", r("command.list.option.all")).option("-v, --vault <vault>", r("command.list.option.vault")).option("--no-interactive", r("command.list.option.no_interactive")).option("-p, --plain", r("command.list.option.plain")).action(
|
|
1677
1686
|
(a) => b(async () => {
|
|
1678
1687
|
const i = await t.archiveService.listEntries(a), n = await t.archiveService.decorateEntries(i), o = await t.configService.getConfig();
|
|
1679
1688
|
if (n.length === 0) {
|
|
1680
1689
|
if (a.plain)
|
|
1681
1690
|
return;
|
|
1682
|
-
|
|
1691
|
+
E(r("command.list.empty"));
|
|
1683
1692
|
return;
|
|
1684
1693
|
}
|
|
1685
1694
|
if (a.plain) {
|
|
1686
|
-
console.log(
|
|
1695
|
+
console.log(va(n, o.vaultItemSeparator));
|
|
1687
1696
|
return;
|
|
1688
1697
|
}
|
|
1689
|
-
const c = a.interactive !== !1 &&
|
|
1698
|
+
const c = a.interactive !== !1 && it(), s = n.some((d) => d.status === y.Archived);
|
|
1690
1699
|
if (!c || !s) {
|
|
1691
|
-
console.log(
|
|
1700
|
+
console.log(ma(n, o.vaultItemSeparator)), c && !s && E(r("command.list.restored_only_notice"));
|
|
1692
1701
|
return;
|
|
1693
1702
|
}
|
|
1694
|
-
const l = await
|
|
1703
|
+
const l = await la(ha(n, o.vaultItemSeparator));
|
|
1695
1704
|
if (!l) {
|
|
1696
|
-
|
|
1705
|
+
E(r("command.list.cancelled"));
|
|
1697
1706
|
return;
|
|
1698
1707
|
}
|
|
1699
|
-
await
|
|
1708
|
+
await fa(t, l);
|
|
1700
1709
|
})
|
|
1701
1710
|
);
|
|
1702
1711
|
}
|
|
1703
|
-
function
|
|
1712
|
+
function pa(e, t) {
|
|
1704
1713
|
e.command("log").description(r("command.log.description")).argument("[range]", r("command.log.argument.range")).option("--id <id>", r("command.log.option.id")).action(
|
|
1705
1714
|
(a, i) => b(async () => {
|
|
1706
1715
|
if (i.id !== void 0) {
|
|
@@ -1709,7 +1718,7 @@ function fa(e, t) {
|
|
|
1709
1718
|
const s = Number(i.id), l = await t.logService.getLogById(s);
|
|
1710
1719
|
if (!l)
|
|
1711
1720
|
throw new Error(r("command.log.error.not_found", { id: s }));
|
|
1712
|
-
|
|
1721
|
+
E(
|
|
1713
1722
|
r("command.log.detail.title", {
|
|
1714
1723
|
id: l.log.id
|
|
1715
1724
|
})
|
|
@@ -1719,7 +1728,7 @@ function fa(e, t) {
|
|
|
1719
1728
|
[
|
|
1720
1729
|
[r("command.log.detail.field.id"), String(l.log.id)],
|
|
1721
1730
|
[r("command.log.detail.field.time"), l.log.operedAt],
|
|
1722
|
-
[r("command.log.detail.field.level"),
|
|
1731
|
+
[r("command.log.detail.field.level"), Le(l.log.level)],
|
|
1723
1732
|
[
|
|
1724
1733
|
r("command.log.detail.field.operation"),
|
|
1725
1734
|
`${l.log.oper.main}${l.log.oper.sub ? `/${l.log.oper.sub}` : ""}`
|
|
@@ -1735,7 +1744,7 @@ function fa(e, t) {
|
|
|
1735
1744
|
]
|
|
1736
1745
|
]
|
|
1737
1746
|
)
|
|
1738
|
-
), l.archive && (
|
|
1747
|
+
), l.archive && (E(r("command.log.detail.linked_archive")), console.log(
|
|
1739
1748
|
B(
|
|
1740
1749
|
[
|
|
1741
1750
|
r("command.log.detail.archive.table.id"),
|
|
@@ -1747,14 +1756,14 @@ function fa(e, t) {
|
|
|
1747
1756
|
[
|
|
1748
1757
|
[
|
|
1749
1758
|
String(l.archive.id),
|
|
1750
|
-
|
|
1759
|
+
Ze(l.archive.status),
|
|
1751
1760
|
String(l.archive.vaultId),
|
|
1752
1761
|
l.archive.item,
|
|
1753
1762
|
l.archive.directory
|
|
1754
1763
|
]
|
|
1755
1764
|
]
|
|
1756
1765
|
)
|
|
1757
|
-
)), l.vault && (
|
|
1766
|
+
)), l.vault && (E(r("command.log.detail.linked_vault")), console.log(
|
|
1758
1767
|
B(
|
|
1759
1768
|
[
|
|
1760
1769
|
r("command.log.detail.vault.table.id"),
|
|
@@ -1766,7 +1775,7 @@ function fa(e, t) {
|
|
|
1766
1775
|
[
|
|
1767
1776
|
String(l.vault.id),
|
|
1768
1777
|
l.vault.name,
|
|
1769
|
-
|
|
1778
|
+
Nt(l.vault.status),
|
|
1770
1779
|
l.vault.remark
|
|
1771
1780
|
]
|
|
1772
1781
|
]
|
|
@@ -1774,15 +1783,15 @@ function fa(e, t) {
|
|
|
1774
1783
|
));
|
|
1775
1784
|
return;
|
|
1776
1785
|
}
|
|
1777
|
-
const n =
|
|
1786
|
+
const n = Tt(a), o = await t.logService.getLogs(n);
|
|
1778
1787
|
if (o.length === 0) {
|
|
1779
|
-
|
|
1788
|
+
E(r("command.log.empty"));
|
|
1780
1789
|
return;
|
|
1781
1790
|
}
|
|
1782
1791
|
const c = o.map((s) => [
|
|
1783
1792
|
String(s.id),
|
|
1784
1793
|
s.operedAt,
|
|
1785
|
-
|
|
1794
|
+
Le(s.level),
|
|
1786
1795
|
`${s.oper.main}${s.oper.sub ? `/${s.oper.sub}` : ""}`,
|
|
1787
1796
|
s.message,
|
|
1788
1797
|
s.archiveIds !== void 0 ? String(s.archiveIds) : "",
|
|
@@ -1808,17 +1817,17 @@ function fa(e, t) {
|
|
|
1808
1817
|
async function Y(e) {
|
|
1809
1818
|
await p.mkdir(e, { recursive: !0 });
|
|
1810
1819
|
}
|
|
1811
|
-
const
|
|
1812
|
-
function
|
|
1820
|
+
const C = (e) => p.access(e).then(() => !0).catch(() => !1), Oe = (e) => p.realpath(e).catch(() => h.resolve(e)), _a = (e, t) => h.normalize(e) === h.normalize(t);
|
|
1821
|
+
function rt(e, t) {
|
|
1813
1822
|
const a = h.relative(h.resolve(e), h.resolve(t));
|
|
1814
1823
|
return a.length > 0 && !a.startsWith("..") && !h.isAbsolute(a);
|
|
1815
1824
|
}
|
|
1816
|
-
function
|
|
1817
|
-
return
|
|
1825
|
+
function wa(e, t) {
|
|
1826
|
+
return _a(e, t) || rt(e, t);
|
|
1818
1827
|
}
|
|
1819
1828
|
async function X(e) {
|
|
1820
1829
|
const t = h.dirname(e);
|
|
1821
|
-
await Y(t), await
|
|
1830
|
+
await Y(t), await C(e) || await p.writeFile(e, "", "utf8");
|
|
1822
1831
|
}
|
|
1823
1832
|
async function ae(e) {
|
|
1824
1833
|
try {
|
|
@@ -1829,7 +1838,7 @@ async function ae(e) {
|
|
|
1829
1838
|
throw t;
|
|
1830
1839
|
}
|
|
1831
1840
|
}
|
|
1832
|
-
async function
|
|
1841
|
+
async function Ia(e) {
|
|
1833
1842
|
try {
|
|
1834
1843
|
return (await p.readdir(e, { withFileTypes: !0 })).filter((a) => a.isDirectory()).map((a) => a.name);
|
|
1835
1844
|
} catch (t) {
|
|
@@ -1838,7 +1847,7 @@ async function _a(e) {
|
|
|
1838
1847
|
throw t;
|
|
1839
1848
|
}
|
|
1840
1849
|
}
|
|
1841
|
-
class
|
|
1850
|
+
class ot extends Error {
|
|
1842
1851
|
constructor(t) {
|
|
1843
1852
|
super(
|
|
1844
1853
|
r("service.vault.error.removed_exists", {
|
|
@@ -1847,7 +1856,7 @@ class rt extends Error {
|
|
|
1847
1856
|
), this.name = "VaultRemovedExistsError";
|
|
1848
1857
|
}
|
|
1849
1858
|
}
|
|
1850
|
-
class
|
|
1859
|
+
class ya {
|
|
1851
1860
|
constructor(t, a) {
|
|
1852
1861
|
this.context = t, this.configService = a;
|
|
1853
1862
|
}
|
|
@@ -1873,14 +1882,14 @@ class wa {
|
|
|
1873
1882
|
);
|
|
1874
1883
|
if (n?.status === "Removed") {
|
|
1875
1884
|
if (!t.recoverRemoved)
|
|
1876
|
-
throw new
|
|
1885
|
+
throw new ot(a);
|
|
1877
1886
|
return n.status = S.Valid, await this.context.ensureVaultDir(n.id), await this.context.saveVaults(i), t.activate && await this.configService.setCurrentVault(n.id), { vault: n, recovered: !0 };
|
|
1878
1887
|
}
|
|
1879
1888
|
const c = {
|
|
1880
1889
|
id: await this.context.nextAutoIncrement("vaultId"),
|
|
1881
1890
|
name: a,
|
|
1882
1891
|
remark: t.remark ?? "",
|
|
1883
|
-
createdAt:
|
|
1892
|
+
createdAt: we(),
|
|
1884
1893
|
status: S.Valid
|
|
1885
1894
|
};
|
|
1886
1895
|
return i.push(c), await this.context.saveVaults(i), await this.context.ensureVaultDir(c.id), t.activate && await this.configService.setCurrentVault(c.id), { vault: c, recovered: !1 };
|
|
@@ -1988,13 +1997,13 @@ class wa {
|
|
|
1988
1997
|
async validateMoveToDefault(t) {
|
|
1989
1998
|
for (const a of t) {
|
|
1990
1999
|
const i = this.context.archivePath(a.vaultId, a.id), n = this.context.archivePath(g.Vault.id, a.id);
|
|
1991
|
-
if (!await
|
|
2000
|
+
if (!await C(i))
|
|
1992
2001
|
throw new Error(
|
|
1993
2002
|
r("service.vault.error.archived_object_missing", {
|
|
1994
2003
|
path: i
|
|
1995
2004
|
})
|
|
1996
2005
|
);
|
|
1997
|
-
if (await
|
|
2006
|
+
if (await C(n))
|
|
1998
2007
|
throw new Error(
|
|
1999
2008
|
r("service.vault.error.default_contains_archive_id", {
|
|
2000
2009
|
id: a.id
|
|
@@ -2011,7 +2020,7 @@ class wa {
|
|
|
2011
2020
|
}
|
|
2012
2021
|
async listArchivedIdsInVault(t) {
|
|
2013
2022
|
const a = this.context.vaultDir(t);
|
|
2014
|
-
return await
|
|
2023
|
+
return await C(a) ? (await p.readdir(a, { withFileTypes: !0 })).filter((o) => o.isFile() || o.isDirectory() || o.isSymbolicLink()).map((o) => o.name).filter((o) => /^\d+$/.test(o)).map((o) => Number(o)).sort((o, c) => o - c) : [];
|
|
2015
2024
|
}
|
|
2016
2025
|
getVaultDisplay(t) {
|
|
2017
2026
|
return t.id === g.Vault.id ? `${t.name}(${t.id})` : `${t.name}(${t.id})`;
|
|
@@ -2020,24 +2029,24 @@ class wa {
|
|
|
2020
2029
|
return h.join(f.Dir.vaults, String(t.id));
|
|
2021
2030
|
}
|
|
2022
2031
|
}
|
|
2023
|
-
async function
|
|
2024
|
-
const t =
|
|
2032
|
+
async function ct(e) {
|
|
2033
|
+
const t = _t.createInterface({ input: It, output: wt });
|
|
2025
2034
|
try {
|
|
2026
2035
|
return (await t.question(e)).trim();
|
|
2027
2036
|
} finally {
|
|
2028
2037
|
t.close();
|
|
2029
2038
|
}
|
|
2030
2039
|
}
|
|
2031
|
-
async function
|
|
2032
|
-
const a = (await
|
|
2040
|
+
async function Fe(e, t = !0) {
|
|
2041
|
+
const a = (await ct(e)).toLowerCase();
|
|
2033
2042
|
return a ? ["y", "yes"].includes(a) : !t;
|
|
2034
2043
|
}
|
|
2035
|
-
function
|
|
2044
|
+
function ba(e, t) {
|
|
2036
2045
|
const a = e.command("vault").description(r("command.vault.description"));
|
|
2037
2046
|
a.command("use").description(r("command.vault.use.description")).argument("<name-or-id>", r("command.vault.use.argument")).action(
|
|
2038
2047
|
(i) => b(async () => {
|
|
2039
2048
|
const n = await t.vaultService.useVault(i);
|
|
2040
|
-
|
|
2049
|
+
k(
|
|
2041
2050
|
r("command.vault.use.updated", {
|
|
2042
2051
|
name: n.name,
|
|
2043
2052
|
id: n.id
|
|
@@ -2062,12 +2071,12 @@ function Ia(e, t) {
|
|
|
2062
2071
|
activate: n.activate,
|
|
2063
2072
|
recoverRemoved: s
|
|
2064
2073
|
});
|
|
2065
|
-
o = l.recovered,
|
|
2074
|
+
o = l.recovered, k(
|
|
2066
2075
|
r(o ? "command.vault.create.recovered" : "command.vault.create.created", {
|
|
2067
2076
|
name: l.vault.name,
|
|
2068
2077
|
id: l.vault.id
|
|
2069
2078
|
})
|
|
2070
|
-
), n.activate &&
|
|
2079
|
+
), n.activate && k(
|
|
2071
2080
|
r("command.vault.create.activated", {
|
|
2072
2081
|
name: l.vault.name,
|
|
2073
2082
|
id: l.vault.id
|
|
@@ -2093,13 +2102,13 @@ function Ia(e, t) {
|
|
|
2093
2102
|
try {
|
|
2094
2103
|
await c(!1);
|
|
2095
2104
|
} catch (s) {
|
|
2096
|
-
if (s instanceof
|
|
2097
|
-
if (!await
|
|
2105
|
+
if (s instanceof ot) {
|
|
2106
|
+
if (!await Fe(
|
|
2098
2107
|
r("command.vault.create.confirm_recover", {
|
|
2099
2108
|
name: i
|
|
2100
2109
|
})
|
|
2101
2110
|
)) {
|
|
2102
|
-
|
|
2111
|
+
le(r("command.vault.operation.cancelled"));
|
|
2103
2112
|
return;
|
|
2104
2113
|
}
|
|
2105
2114
|
await c(!0);
|
|
@@ -2110,30 +2119,30 @@ function Ia(e, t) {
|
|
|
2110
2119
|
})
|
|
2111
2120
|
), a.command("remove").description(r("command.vault.remove.description")).argument("<name-or-id>", r("command.vault.remove.argument")).action(
|
|
2112
2121
|
(i) => b(async () => {
|
|
2113
|
-
if (!await
|
|
2122
|
+
if (!await Fe(
|
|
2114
2123
|
r("command.vault.remove.confirm", {
|
|
2115
2124
|
nameOrId: i
|
|
2116
2125
|
})
|
|
2117
2126
|
)) {
|
|
2118
|
-
|
|
2127
|
+
le(r("command.vault.operation.cancelled"));
|
|
2119
2128
|
return;
|
|
2120
2129
|
}
|
|
2121
2130
|
const o = Math.random().toString(36).slice(2, 8).toUpperCase();
|
|
2122
|
-
if (await
|
|
2131
|
+
if (await ct(
|
|
2123
2132
|
r("command.vault.remove.verify_prompt", {
|
|
2124
2133
|
verifyCode: o
|
|
2125
2134
|
})
|
|
2126
2135
|
) !== o) {
|
|
2127
|
-
|
|
2136
|
+
le(r("command.vault.remove.verify_mismatch"));
|
|
2128
2137
|
return;
|
|
2129
2138
|
}
|
|
2130
2139
|
const s = await t.vaultService.removeVault(i);
|
|
2131
|
-
|
|
2140
|
+
k(
|
|
2132
2141
|
r("command.vault.remove.done", {
|
|
2133
2142
|
name: s.vault.name,
|
|
2134
2143
|
id: s.vault.id
|
|
2135
2144
|
})
|
|
2136
|
-
), s.movedArchiveIds.length > 0 &&
|
|
2145
|
+
), s.movedArchiveIds.length > 0 && E(
|
|
2137
2146
|
r("command.vault.remove.moved_to_default", {
|
|
2138
2147
|
count: s.movedArchiveIds.length,
|
|
2139
2148
|
name: g.Vault.name
|
|
@@ -2156,7 +2165,7 @@ function Ia(e, t) {
|
|
|
2156
2165
|
), a.command("recover").description(r("command.vault.recover.description")).argument("<name-or-id>", r("command.vault.recover.argument")).action(
|
|
2157
2166
|
(i) => b(async () => {
|
|
2158
2167
|
const n = await t.vaultService.recoverVault(i);
|
|
2159
|
-
|
|
2168
|
+
k(
|
|
2160
2169
|
r("command.vault.recover.done", {
|
|
2161
2170
|
name: n.name,
|
|
2162
2171
|
id: n.id
|
|
@@ -2179,7 +2188,7 @@ function Ia(e, t) {
|
|
|
2179
2188
|
), a.command("rename").description(r("command.vault.rename.description")).argument("<old>", r("command.vault.rename.argument.old")).argument("<new>", r("command.vault.rename.argument.new")).action(
|
|
2180
2189
|
(i, n) => b(async () => {
|
|
2181
2190
|
const o = await t.vaultService.renameVault(i, n);
|
|
2182
|
-
|
|
2191
|
+
k(
|
|
2183
2192
|
r("command.vault.rename.done", {
|
|
2184
2193
|
name: o.name,
|
|
2185
2194
|
id: o.id
|
|
@@ -2203,7 +2212,7 @@ function Ia(e, t) {
|
|
|
2203
2212
|
(i) => b(async () => {
|
|
2204
2213
|
const n = await t.vaultService.listVaults(!!i.all);
|
|
2205
2214
|
if (n.length === 0) {
|
|
2206
|
-
|
|
2215
|
+
E(r("command.vault.list.empty"));
|
|
2207
2216
|
return;
|
|
2208
2217
|
}
|
|
2209
2218
|
const o = n.map((c) => `${String(c.id).padStart(3, " ")} ${c.name}`).join(`
|
|
@@ -2212,11 +2221,11 @@ function Ia(e, t) {
|
|
|
2212
2221
|
})
|
|
2213
2222
|
);
|
|
2214
2223
|
}
|
|
2215
|
-
function
|
|
2216
|
-
const t = new
|
|
2217
|
-
return t.name(
|
|
2224
|
+
function ka(e) {
|
|
2225
|
+
const t = new pt();
|
|
2226
|
+
return t.name(Rt).description(r("app.description")).version(e.version), Pt(t, e), ba(t, e), ga(t, e), pa(t, e), ia(t, e), t;
|
|
2218
2227
|
}
|
|
2219
|
-
const
|
|
2228
|
+
const je = {
|
|
2220
2229
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2221
2230
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2222
2231
|
functionPattern: /(^|\n)\s*(function\s+)?arv\s*(\(\))?\s*\{/m,
|
|
@@ -2241,7 +2250,7 @@ const Fe = {
|
|
|
2241
2250
|
fi
|
|
2242
2251
|
return $status
|
|
2243
2252
|
}`
|
|
2244
|
-
},
|
|
2253
|
+
}, Ca = {
|
|
2245
2254
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2246
2255
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2247
2256
|
functionPattern: /(^|\n)\s*function\s+arv\b/m,
|
|
@@ -2267,7 +2276,7 @@ const Fe = {
|
|
|
2267
2276
|
rm -f $target_tmp
|
|
2268
2277
|
return $status
|
|
2269
2278
|
end`
|
|
2270
|
-
},
|
|
2279
|
+
}, Ea = {
|
|
2271
2280
|
startMarker: "# >>> archiver arv wrapper >>>",
|
|
2272
2281
|
endMarker: "# <<< archiver arv wrapper <<<",
|
|
2273
2282
|
functionPattern: /(^|\r?\n)\s*function\s+arv\b/im,
|
|
@@ -2307,7 +2316,7 @@ end`
|
|
|
2307
2316
|
$global:LASTEXITCODE = $status
|
|
2308
2317
|
}`
|
|
2309
2318
|
};
|
|
2310
|
-
function
|
|
2319
|
+
function Aa(e) {
|
|
2311
2320
|
const t = h.basename(e).toLowerCase();
|
|
2312
2321
|
if (t.includes("bash"))
|
|
2313
2322
|
return "bash";
|
|
@@ -2318,17 +2327,17 @@ function Ca(e) {
|
|
|
2318
2327
|
if (t.includes("pwsh") || t.includes("powershell"))
|
|
2319
2328
|
return "powershell";
|
|
2320
2329
|
}
|
|
2321
|
-
function
|
|
2330
|
+
function Ye(e) {
|
|
2322
2331
|
return e.endsWith(`
|
|
2323
2332
|
`) ? e : `${e}
|
|
2324
2333
|
`;
|
|
2325
2334
|
}
|
|
2326
|
-
function
|
|
2335
|
+
function st(e) {
|
|
2327
2336
|
return `${e.startMarker}
|
|
2328
2337
|
${e.body}
|
|
2329
2338
|
${e.endMarker}`;
|
|
2330
2339
|
}
|
|
2331
|
-
function
|
|
2340
|
+
function Sa(e, t) {
|
|
2332
2341
|
const a = e.indexOf(t.startMarker);
|
|
2333
2342
|
if (a === -1)
|
|
2334
2343
|
return;
|
|
@@ -2339,8 +2348,8 @@ function Ea(e, t) {
|
|
|
2339
2348
|
end: i + t.endMarker.length
|
|
2340
2349
|
};
|
|
2341
2350
|
}
|
|
2342
|
-
function
|
|
2343
|
-
const a =
|
|
2351
|
+
function xa(e, t) {
|
|
2352
|
+
const a = st(t);
|
|
2344
2353
|
if (e.trim().length === 0)
|
|
2345
2354
|
return `${a}
|
|
2346
2355
|
`;
|
|
@@ -2352,99 +2361,99 @@ function Aa(e, t) {
|
|
|
2352
2361
|
return `${e}${i}${a}
|
|
2353
2362
|
`;
|
|
2354
2363
|
}
|
|
2355
|
-
async function
|
|
2364
|
+
async function Va(e, t) {
|
|
2356
2365
|
for (const a of t) {
|
|
2357
2366
|
const i = h.join(e, a);
|
|
2358
|
-
if (await
|
|
2367
|
+
if (await C(i))
|
|
2359
2368
|
return i;
|
|
2360
2369
|
}
|
|
2361
2370
|
return h.join(e, t[0] ?? ".bashrc");
|
|
2362
2371
|
}
|
|
2363
2372
|
async function J(e, t) {
|
|
2364
2373
|
await X(e);
|
|
2365
|
-
const a = await p.readFile(e, "utf8"), i =
|
|
2374
|
+
const a = await p.readFile(e, "utf8"), i = Sa(a, t);
|
|
2366
2375
|
if (i) {
|
|
2367
|
-
const o = a.slice(i.start, i.end), c =
|
|
2376
|
+
const o = a.slice(i.start, i.end), c = st(t);
|
|
2368
2377
|
if (o === c)
|
|
2369
2378
|
return !1;
|
|
2370
2379
|
const s = `${a.slice(0, i.start)}${c}${a.slice(i.end)}`;
|
|
2371
|
-
return await p.writeFile(e,
|
|
2380
|
+
return await p.writeFile(e, Ye(s), "utf8"), !0;
|
|
2372
2381
|
}
|
|
2373
2382
|
if (t.functionPattern.test(a))
|
|
2374
2383
|
return !1;
|
|
2375
|
-
const n =
|
|
2384
|
+
const n = Ye(xa(a, t));
|
|
2376
2385
|
return await p.writeFile(e, n, "utf8"), !0;
|
|
2377
2386
|
}
|
|
2378
|
-
function
|
|
2387
|
+
function Ra(e, t) {
|
|
2379
2388
|
const a = h.resolve(t), i = h.resolve(e);
|
|
2380
2389
|
if (i === a)
|
|
2381
2390
|
return "~";
|
|
2382
2391
|
const n = `${a}${h.sep}`;
|
|
2383
2392
|
return i.startsWith(n) ? `~${i.slice(a.length)}` : e;
|
|
2384
2393
|
}
|
|
2385
|
-
function
|
|
2394
|
+
function La(e) {
|
|
2386
2395
|
return `'${e.replaceAll("'", "'\\''")}'`;
|
|
2387
2396
|
}
|
|
2388
|
-
function
|
|
2397
|
+
function Ta(e) {
|
|
2389
2398
|
return `'${e.replaceAll("'", "''")}'`;
|
|
2390
2399
|
}
|
|
2391
|
-
async function
|
|
2400
|
+
async function $a(e) {
|
|
2392
2401
|
if (process.platform === "win32") {
|
|
2393
2402
|
const t = [
|
|
2394
2403
|
h.join(e, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1"),
|
|
2395
2404
|
h.join(e, "Documents", "WindowsPowerShell", "Microsoft.PowerShell_profile.ps1")
|
|
2396
2405
|
];
|
|
2397
2406
|
for (const a of t)
|
|
2398
|
-
if (await
|
|
2407
|
+
if (await C(a))
|
|
2399
2408
|
return a;
|
|
2400
2409
|
return t[0];
|
|
2401
2410
|
}
|
|
2402
2411
|
return h.join(e, ".config", "powershell", "Microsoft.PowerShell_profile.ps1");
|
|
2403
2412
|
}
|
|
2404
2413
|
function G(e, t, a, i) {
|
|
2405
|
-
const n =
|
|
2414
|
+
const n = Ra(t, a);
|
|
2406
2415
|
return e === "powershell" ? {
|
|
2407
2416
|
installed: i,
|
|
2408
2417
|
shell: e,
|
|
2409
2418
|
profilePath: n,
|
|
2410
|
-
reloadCommand: `. ${
|
|
2419
|
+
reloadCommand: `. ${Ta(t)}`
|
|
2411
2420
|
} : {
|
|
2412
2421
|
installed: i,
|
|
2413
2422
|
shell: e,
|
|
2414
2423
|
profilePath: n,
|
|
2415
|
-
reloadCommand: `source ${
|
|
2424
|
+
reloadCommand: `source ${La(t)}`
|
|
2416
2425
|
};
|
|
2417
2426
|
}
|
|
2418
|
-
async function
|
|
2427
|
+
async function Na(e = {}) {
|
|
2419
2428
|
const t = e.env ?? process.env;
|
|
2420
2429
|
if (t.ARCHIVER_DISABLE_SHELL_INIT === "1")
|
|
2421
2430
|
return { installed: !1 };
|
|
2422
2431
|
if (!(e.stdinIsTTY ?? !!process.stdin.isTTY))
|
|
2423
2432
|
return { installed: !1 };
|
|
2424
|
-
const i = e.homeDir ?? t.HOME ?? t.USERPROFILE ??
|
|
2433
|
+
const i = e.homeDir ?? t.HOME ?? t.USERPROFILE ?? Ge.homedir();
|
|
2425
2434
|
if (!i)
|
|
2426
2435
|
return { installed: !1 };
|
|
2427
|
-
const n = e.shellPath ?? t.SHELL ?? "", o =
|
|
2436
|
+
const n = e.shellPath ?? t.SHELL ?? "", o = Aa(n);
|
|
2428
2437
|
if (!o)
|
|
2429
2438
|
return { installed: !1 };
|
|
2430
2439
|
try {
|
|
2431
2440
|
if (o === "bash") {
|
|
2432
|
-
const l = await
|
|
2441
|
+
const l = await Va(i, [".bashrc", ".bash_profile", ".profile"]), d = await J(l, je);
|
|
2433
2442
|
return G(o, l, i, d);
|
|
2434
2443
|
}
|
|
2435
2444
|
if (o === "zsh") {
|
|
2436
|
-
const l = h.join(i, ".zshrc"), d = await J(l,
|
|
2445
|
+
const l = h.join(i, ".zshrc"), d = await J(l, je);
|
|
2437
2446
|
return G(o, l, i, d);
|
|
2438
2447
|
}
|
|
2439
2448
|
if (o === "fish") {
|
|
2440
2449
|
const l = h.join(i, ".config", "fish", "functions", "arv.fish");
|
|
2441
2450
|
await Y(h.dirname(l));
|
|
2442
|
-
const d = await J(l,
|
|
2451
|
+
const d = await J(l, Ca);
|
|
2443
2452
|
return G(o, l, i, d);
|
|
2444
2453
|
}
|
|
2445
|
-
const c = await
|
|
2454
|
+
const c = await $a(i);
|
|
2446
2455
|
await Y(h.dirname(c));
|
|
2447
|
-
const s = await J(c,
|
|
2456
|
+
const s = await J(c, Ea);
|
|
2448
2457
|
return G(o, c, i, s);
|
|
2449
2458
|
} catch {
|
|
2450
2459
|
return { installed: !1 };
|
|
@@ -2471,17 +2480,17 @@ async function ie(e) {
|
|
|
2471
2480
|
throw t;
|
|
2472
2481
|
}
|
|
2473
2482
|
}
|
|
2474
|
-
async function
|
|
2483
|
+
async function He(e, t) {
|
|
2475
2484
|
const a = t.map((i) => JSON.stringify(i)).join(`
|
|
2476
2485
|
`);
|
|
2477
2486
|
await p.writeFile(e, a.length > 0 ? `${a}
|
|
2478
2487
|
` : "", "utf8");
|
|
2479
2488
|
}
|
|
2480
|
-
async function
|
|
2489
|
+
async function lt(e, t) {
|
|
2481
2490
|
await p.appendFile(e, `${JSON.stringify(t)}
|
|
2482
2491
|
`, "utf8");
|
|
2483
2492
|
}
|
|
2484
|
-
function
|
|
2493
|
+
function Ue(e) {
|
|
2485
2494
|
return {
|
|
2486
2495
|
currentVaultId: Number.isInteger(e.currentVaultId) && e.currentVaultId >= 0 ? e.currentVaultId : g.Config.currentVaultId,
|
|
2487
2496
|
updateCheck: e.updateCheck === "off" ? "off" : "on",
|
|
@@ -2492,14 +2501,14 @@ function He(e) {
|
|
|
2492
2501
|
noCommandAction: e.noCommandAction === "help" || e.noCommandAction === "list" ? e.noCommandAction : "unknown"
|
|
2493
2502
|
};
|
|
2494
2503
|
}
|
|
2495
|
-
function
|
|
2504
|
+
function ze(e) {
|
|
2496
2505
|
return {
|
|
2497
2506
|
logId: Number.isInteger(e.logId) && e.logId >= 0 ? e.logId : 0,
|
|
2498
2507
|
vaultId: Number.isInteger(e.vaultId) && e.vaultId >= 0 ? e.vaultId : 0,
|
|
2499
2508
|
archiveId: Number.isInteger(e.archiveId) && e.archiveId >= 0 ? e.archiveId : 0
|
|
2500
2509
|
};
|
|
2501
2510
|
}
|
|
2502
|
-
function
|
|
2511
|
+
function Be(e) {
|
|
2503
2512
|
const t = e.isDirectory === 1 ? 1 : 0, a = e.status === y.Restored ? y.Restored : y.Archived;
|
|
2504
2513
|
return {
|
|
2505
2514
|
archivedAt: String(e.archivedAt ?? ""),
|
|
@@ -2513,7 +2522,7 @@ function ze(e) {
|
|
|
2513
2522
|
remark: String(e.remark ?? "")
|
|
2514
2523
|
};
|
|
2515
2524
|
}
|
|
2516
|
-
function
|
|
2525
|
+
function qe(e) {
|
|
2517
2526
|
const t = S[e.status] ?? S.Valid;
|
|
2518
2527
|
return {
|
|
2519
2528
|
id: e.id,
|
|
@@ -2523,7 +2532,7 @@ function Be(e) {
|
|
|
2523
2532
|
status: t
|
|
2524
2533
|
};
|
|
2525
2534
|
}
|
|
2526
|
-
class
|
|
2535
|
+
class Da {
|
|
2527
2536
|
configCache;
|
|
2528
2537
|
autoIncrCache;
|
|
2529
2538
|
listCache;
|
|
@@ -2531,27 +2540,27 @@ class $a {
|
|
|
2531
2540
|
async init() {
|
|
2532
2541
|
for (const a of Object.values(f.Dir))
|
|
2533
2542
|
await Y(a);
|
|
2534
|
-
await Y(this.vaultDir(g.Vault.id)), await
|
|
2543
|
+
await Y(this.vaultDir(g.Vault.id)), await xe(f.File.config, ue), await xe(f.File.autoIncr, me), await X(f.File.list), await X(f.File.vaults), await X(f.File.log);
|
|
2535
2544
|
const t = await this.loadConfig();
|
|
2536
|
-
t.currentVaultId === 0 || await
|
|
2545
|
+
t.currentVaultId === 0 || await C(this.vaultDir(t.currentVaultId)) || (t.currentVaultId = g.Vault.id, await this.saveConfig(t));
|
|
2537
2546
|
}
|
|
2538
2547
|
async loadConfig(t = !1) {
|
|
2539
2548
|
if (this.configCache && !t)
|
|
2540
2549
|
return this.configCache;
|
|
2541
|
-
const a = await
|
|
2550
|
+
const a = await he(f.File.config, g.Config), i = Ue({ ...g.Config, ...a });
|
|
2542
2551
|
return Z(i.language), this.configCache = i, i;
|
|
2543
2552
|
}
|
|
2544
2553
|
async saveConfig(t) {
|
|
2545
|
-
this.configCache =
|
|
2554
|
+
this.configCache = Ue(t), Z(this.configCache.language), await Ve(f.File.config, this.configCache, ue);
|
|
2546
2555
|
}
|
|
2547
2556
|
async loadAutoIncr(t = !1) {
|
|
2548
2557
|
if (this.autoIncrCache && !t)
|
|
2549
2558
|
return this.autoIncrCache;
|
|
2550
|
-
const a = await
|
|
2559
|
+
const a = await he(f.File.autoIncr, g.AutoIncr), i = ze({ ...g.AutoIncr, ...a });
|
|
2551
2560
|
return this.autoIncrCache = i, i;
|
|
2552
2561
|
}
|
|
2553
2562
|
async saveAutoIncr(t) {
|
|
2554
|
-
this.autoIncrCache =
|
|
2563
|
+
this.autoIncrCache = ze(t), await Ve(f.File.autoIncr, this.autoIncrCache, me);
|
|
2555
2564
|
}
|
|
2556
2565
|
async nextAutoIncrement(t) {
|
|
2557
2566
|
const a = await this.loadAutoIncr();
|
|
@@ -2561,24 +2570,24 @@ class $a {
|
|
|
2561
2570
|
if (this.listCache && !t)
|
|
2562
2571
|
return this.listCache;
|
|
2563
2572
|
const a = await ie(f.File.list);
|
|
2564
|
-
return this.listCache = a.map((i) =>
|
|
2573
|
+
return this.listCache = a.map((i) => Be(i)).filter((i) => Number.isInteger(i.id) && i.id > 0), this.listCache.sort((i, n) => i.id - n.id), this.listCache;
|
|
2565
2574
|
}
|
|
2566
2575
|
async saveListEntries(t) {
|
|
2567
|
-
this.listCache = [...t].sort((a, i) => a.id - i.id), await
|
|
2576
|
+
this.listCache = [...t].sort((a, i) => a.id - i.id), await He(f.File.list, this.listCache);
|
|
2568
2577
|
}
|
|
2569
2578
|
async appendListEntry(t) {
|
|
2570
|
-
const a =
|
|
2571
|
-
this.listCache || (this.listCache = await this.loadListEntries()), this.listCache.push(a), this.listCache.sort((i, n) => i.id - n.id), await
|
|
2579
|
+
const a = Be(t);
|
|
2580
|
+
this.listCache || (this.listCache = await this.loadListEntries()), this.listCache.push(a), this.listCache.sort((i, n) => i.id - n.id), await lt(f.File.list, a);
|
|
2572
2581
|
}
|
|
2573
2582
|
async loadVaults(t = !1) {
|
|
2574
2583
|
if (this.vaultCache && !t)
|
|
2575
2584
|
return this.vaultCache;
|
|
2576
2585
|
const a = await ie(f.File.vaults);
|
|
2577
|
-
return this.vaultCache = a.map((i) =>
|
|
2586
|
+
return this.vaultCache = a.map((i) => qe(i)).filter((i) => Number.isInteger(i.id) && i.id > 0).sort((i, n) => i.id - n.id), this.vaultCache;
|
|
2578
2587
|
}
|
|
2579
2588
|
async saveVaults(t) {
|
|
2580
|
-
const a = t.map((i) =>
|
|
2581
|
-
this.vaultCache = a, await
|
|
2589
|
+
const a = t.map((i) => qe(i)).filter((i) => i.id > 0).sort((i, n) => i.id - n.id);
|
|
2590
|
+
this.vaultCache = a, await He(f.File.vaults, a);
|
|
2582
2591
|
}
|
|
2583
2592
|
async getVaults(t) {
|
|
2584
2593
|
const a = t?.includeRemoved ?? !1, i = t?.withDefault ?? !0, n = await this.loadVaults(), o = a ? n : n.filter((c) => c.status === "Valid");
|
|
@@ -2620,7 +2629,7 @@ class $a {
|
|
|
2620
2629
|
if (!i || !i.isDirectory())
|
|
2621
2630
|
return;
|
|
2622
2631
|
const n = this.archiveObjectPath(t.vaultId, t.id, t.item);
|
|
2623
|
-
if (await
|
|
2632
|
+
if (await C(n))
|
|
2624
2633
|
return {
|
|
2625
2634
|
slotPath: a,
|
|
2626
2635
|
objectPath: n
|
|
@@ -2633,7 +2642,7 @@ class $a {
|
|
|
2633
2642
|
t !== g.Vault.id && await p.rm(this.vaultDir(t), { recursive: !0, force: !0 });
|
|
2634
2643
|
}
|
|
2635
2644
|
}
|
|
2636
|
-
class
|
|
2645
|
+
class Pa {
|
|
2637
2646
|
constructor(t, a) {
|
|
2638
2647
|
this.context = t, this.logger = a;
|
|
2639
2648
|
}
|
|
@@ -2647,7 +2656,7 @@ class Na {
|
|
|
2647
2656
|
const o = { ok: [], failed: [] };
|
|
2648
2657
|
for (const c of n) {
|
|
2649
2658
|
const s = await this.context.nextAutoIncrement("archiveId"), l = this.context.archivePath(i.id, s), d = {
|
|
2650
|
-
archivedAt:
|
|
2659
|
+
archivedAt: we(),
|
|
2651
2660
|
status: y.Archived,
|
|
2652
2661
|
isDirectory: c.stats.isDirectory() ? 1 : 0,
|
|
2653
2662
|
vaultId: i.id,
|
|
@@ -2658,7 +2667,7 @@ class Na {
|
|
|
2658
2667
|
remark: a.remark ?? ""
|
|
2659
2668
|
};
|
|
2660
2669
|
try {
|
|
2661
|
-
if (await
|
|
2670
|
+
if (await C(l))
|
|
2662
2671
|
throw new Error(
|
|
2663
2672
|
r("service.archive.error.slot_exists", {
|
|
2664
2673
|
path: l
|
|
@@ -2760,7 +2769,7 @@ class Na {
|
|
|
2760
2769
|
path: this.context.archivePath(s.vaultId, s.id)
|
|
2761
2770
|
})
|
|
2762
2771
|
);
|
|
2763
|
-
if (await
|
|
2772
|
+
if (await C(d))
|
|
2764
2773
|
throw new Error(
|
|
2765
2774
|
r("service.archive.error.restore_target_exists", {
|
|
2766
2775
|
path: d
|
|
@@ -2841,17 +2850,17 @@ class Na {
|
|
|
2841
2850
|
vault: i.name
|
|
2842
2851
|
})
|
|
2843
2852
|
);
|
|
2844
|
-
const u = await this.context.resolveArchiveStorageLocation(m), _ = this.context.archivePath(m.vaultId, m.id),
|
|
2853
|
+
const u = await this.context.resolveArchiveStorageLocation(m), _ = this.context.archivePath(m.vaultId, m.id), A = this.context.archivePath(i.id, m.id);
|
|
2845
2854
|
if (!u)
|
|
2846
2855
|
throw new Error(
|
|
2847
2856
|
r("service.archive.error.object_missing", {
|
|
2848
2857
|
path: _
|
|
2849
2858
|
})
|
|
2850
2859
|
);
|
|
2851
|
-
if (await
|
|
2860
|
+
if (await C(A))
|
|
2852
2861
|
throw new Error(
|
|
2853
2862
|
r("service.archive.error.target_slot_exists", {
|
|
2854
|
-
path:
|
|
2863
|
+
path: A
|
|
2855
2864
|
})
|
|
2856
2865
|
);
|
|
2857
2866
|
c.set(d, u);
|
|
@@ -2872,7 +2881,7 @@ class Na {
|
|
|
2872
2881
|
});
|
|
2873
2882
|
continue;
|
|
2874
2883
|
}
|
|
2875
|
-
const _ = this.context.archivePath(i.id, m.id),
|
|
2884
|
+
const _ = this.context.archivePath(i.id, m.id), A = m.vaultId;
|
|
2876
2885
|
try {
|
|
2877
2886
|
await p.rename(u.slotPath, _), m.vaultId = i.id, l = !0, await this.logger.log(
|
|
2878
2887
|
"INFO",
|
|
@@ -2884,7 +2893,7 @@ class Na {
|
|
|
2884
2893
|
},
|
|
2885
2894
|
r("service.archive.log.moved", {
|
|
2886
2895
|
id: d,
|
|
2887
|
-
fromVaultId:
|
|
2896
|
+
fromVaultId: A,
|
|
2888
2897
|
toVaultId: i.id
|
|
2889
2898
|
}),
|
|
2890
2899
|
{ aid: d, vid: i.id }
|
|
@@ -2897,8 +2906,8 @@ class Na {
|
|
|
2897
2906
|
id: i.id
|
|
2898
2907
|
})
|
|
2899
2908
|
});
|
|
2900
|
-
} catch (
|
|
2901
|
-
const
|
|
2909
|
+
} catch (L) {
|
|
2910
|
+
const x = L.message;
|
|
2902
2911
|
await this.logger.log(
|
|
2903
2912
|
"ERROR",
|
|
2904
2913
|
{
|
|
@@ -2909,14 +2918,14 @@ class Na {
|
|
|
2909
2918
|
},
|
|
2910
2919
|
r("service.archive.log.move_failed", {
|
|
2911
2920
|
id: d,
|
|
2912
|
-
message:
|
|
2921
|
+
message: x
|
|
2913
2922
|
}),
|
|
2914
|
-
{ aid: d, vid:
|
|
2923
|
+
{ aid: d, vid: A }
|
|
2915
2924
|
), s.failed.push({
|
|
2916
2925
|
id: d,
|
|
2917
2926
|
input: String(d),
|
|
2918
2927
|
success: !1,
|
|
2919
|
-
message:
|
|
2928
|
+
message: x
|
|
2920
2929
|
});
|
|
2921
2930
|
}
|
|
2922
2931
|
}
|
|
@@ -3062,7 +3071,7 @@ class Na {
|
|
|
3062
3071
|
};
|
|
3063
3072
|
}
|
|
3064
3073
|
async preValidatePutItems(t) {
|
|
3065
|
-
const a = [], i = /* @__PURE__ */ new Set(), n = await
|
|
3074
|
+
const a = [], i = /* @__PURE__ */ new Set(), n = await Oe(f.Dir.root);
|
|
3066
3075
|
for (const o of t) {
|
|
3067
3076
|
const c = h.resolve(o), s = await ae(c);
|
|
3068
3077
|
if (!s)
|
|
@@ -3071,8 +3080,8 @@ class Na {
|
|
|
3071
3080
|
path: o
|
|
3072
3081
|
})
|
|
3073
3082
|
);
|
|
3074
|
-
const l = await
|
|
3075
|
-
if (
|
|
3083
|
+
const l = await Oe(c);
|
|
3084
|
+
if (wa(l, n) || rt(n, l))
|
|
3076
3085
|
throw new Error(
|
|
3077
3086
|
r("service.archive.error.path_forbidden_archiver_scope", {
|
|
3078
3087
|
path: o
|
|
@@ -3097,7 +3106,7 @@ class Na {
|
|
|
3097
3106
|
const i = await this.context.loadAutoIncr();
|
|
3098
3107
|
for (let n = 1; n <= a; n += 1) {
|
|
3099
3108
|
const o = i.archiveId + n, c = this.context.archivePath(t, o);
|
|
3100
|
-
if (await
|
|
3109
|
+
if (await C(c))
|
|
3101
3110
|
throw new Error(
|
|
3102
3111
|
r("service.archive.error.slot_already_occupied", {
|
|
3103
3112
|
path: c
|
|
@@ -3106,24 +3115,24 @@ class Na {
|
|
|
3106
3115
|
}
|
|
3107
3116
|
}
|
|
3108
3117
|
}
|
|
3109
|
-
class
|
|
3118
|
+
class Ma {
|
|
3110
3119
|
constructor(t) {
|
|
3111
3120
|
this.context = t;
|
|
3112
3121
|
}
|
|
3113
3122
|
async log(t, a, i, n) {
|
|
3114
3123
|
const s = {
|
|
3115
3124
|
id: await this.context.nextAutoIncrement("logId"),
|
|
3116
|
-
operedAt:
|
|
3125
|
+
operedAt: we(/* @__PURE__ */ new Date()),
|
|
3117
3126
|
level: t,
|
|
3118
3127
|
oper: a,
|
|
3119
3128
|
message: i,
|
|
3120
3129
|
...n?.aid !== void 0 ? { archiveIds: n.aid } : {},
|
|
3121
3130
|
...n?.vid !== void 0 ? { vaultIds: n.vid } : {}
|
|
3122
3131
|
};
|
|
3123
|
-
return await
|
|
3132
|
+
return await lt(f.File.log, s), s;
|
|
3124
3133
|
}
|
|
3125
3134
|
}
|
|
3126
|
-
function
|
|
3135
|
+
function de(e) {
|
|
3127
3136
|
const t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
3128
3137
|
for (const i of e)
|
|
3129
3138
|
t.has(i) ? a.add(i) : t.add(i);
|
|
@@ -3132,7 +3141,7 @@ function le(e) {
|
|
|
3132
3141
|
function I(e, t, a, i) {
|
|
3133
3142
|
e.push({ level: t, code: a, message: i });
|
|
3134
3143
|
}
|
|
3135
|
-
class
|
|
3144
|
+
class Oa {
|
|
3136
3145
|
constructor(t) {
|
|
3137
3146
|
this.context = t;
|
|
3138
3147
|
}
|
|
@@ -3160,7 +3169,7 @@ class Pa {
|
|
|
3160
3169
|
this.context.vaultDir(g.Vault.id)
|
|
3161
3170
|
];
|
|
3162
3171
|
for (const i of a)
|
|
3163
|
-
await
|
|
3172
|
+
await C(i) || I(
|
|
3164
3173
|
t.issues,
|
|
3165
3174
|
w.Error,
|
|
3166
3175
|
"MISSING_PATH",
|
|
@@ -3180,7 +3189,7 @@ class Pa {
|
|
|
3180
3189
|
);
|
|
3181
3190
|
}
|
|
3182
3191
|
checkListIds(t, a, i) {
|
|
3183
|
-
const n = a.map((s) => s.id), o =
|
|
3192
|
+
const n = a.map((s) => s.id), o = de(n);
|
|
3184
3193
|
o.length > 0 && I(
|
|
3185
3194
|
t.issues,
|
|
3186
3195
|
w.Error,
|
|
@@ -3201,7 +3210,7 @@ class Pa {
|
|
|
3201
3210
|
);
|
|
3202
3211
|
}
|
|
3203
3212
|
checkVaultIds(t, a, i) {
|
|
3204
|
-
const n = a.filter((m) => m.id !== g.Vault.id), o = n.map((m) => m.id), c =
|
|
3213
|
+
const n = a.filter((m) => m.id !== g.Vault.id), o = n.map((m) => m.id), c = de(o);
|
|
3205
3214
|
c.length > 0 && I(
|
|
3206
3215
|
t.issues,
|
|
3207
3216
|
w.Error,
|
|
@@ -3274,7 +3283,7 @@ class Pa {
|
|
|
3274
3283
|
);
|
|
3275
3284
|
}
|
|
3276
3285
|
}
|
|
3277
|
-
await
|
|
3286
|
+
await C(l) && I(
|
|
3278
3287
|
t.issues,
|
|
3279
3288
|
w.Warn,
|
|
3280
3289
|
"RESTORE_TARGET_ALREADY_EXISTS",
|
|
@@ -3284,7 +3293,7 @@ class Pa {
|
|
|
3284
3293
|
})
|
|
3285
3294
|
);
|
|
3286
3295
|
} else if (o.status === y.Restored)
|
|
3287
|
-
if (await
|
|
3296
|
+
if (await C(s) && I(
|
|
3288
3297
|
t.issues,
|
|
3289
3298
|
w.Warn,
|
|
3290
3299
|
"RESTORED_BUT_ARCHIVE_EXISTS",
|
|
@@ -3292,7 +3301,7 @@ class Pa {
|
|
|
3292
3301
|
archiveId: o.id,
|
|
3293
3302
|
archivePath: s
|
|
3294
3303
|
})
|
|
3295
|
-
), await
|
|
3304
|
+
), await C(l)) {
|
|
3296
3305
|
const d = await ae(l);
|
|
3297
3306
|
if (d) {
|
|
3298
3307
|
const m = d.isDirectory(), u = o.isDirectory === 1;
|
|
@@ -3332,7 +3341,7 @@ class Pa {
|
|
|
3332
3341
|
async checkVaultDirectoryConsistency(t, a, i) {
|
|
3333
3342
|
const n = new Set(i.map((s) => s.id)), o = new Set(
|
|
3334
3343
|
a.filter((s) => s.status === y.Archived).map((s) => `${s.vaultId}/${s.id}`)
|
|
3335
|
-
), c = await
|
|
3344
|
+
), c = await Ia(f.Dir.vaults);
|
|
3336
3345
|
for (const s of c) {
|
|
3337
3346
|
if (!/^\d+$/.test(s)) {
|
|
3338
3347
|
I(
|
|
@@ -3395,7 +3404,7 @@ class Pa {
|
|
|
3395
3404
|
if (s.status !== "Valid" && s.status !== "Protected")
|
|
3396
3405
|
continue;
|
|
3397
3406
|
const l = this.context.vaultDir(s.id);
|
|
3398
|
-
await
|
|
3407
|
+
await C(l) || I(
|
|
3399
3408
|
t.issues,
|
|
3400
3409
|
w.Error,
|
|
3401
3410
|
"MISSING_VAULT_DIR",
|
|
@@ -3408,7 +3417,7 @@ class Pa {
|
|
|
3408
3417
|
}
|
|
3409
3418
|
}
|
|
3410
3419
|
async checkLogConsistency(t, a) {
|
|
3411
|
-
const n = (await ie(f.File.log)).map((s) => Number(s.id)).filter((s) => Number.isInteger(s)), o =
|
|
3420
|
+
const n = (await ie(f.File.log)).map((s) => Number(s.id)).filter((s) => Number.isInteger(s)), o = de(n);
|
|
3412
3421
|
o.length > 0 && I(
|
|
3413
3422
|
t.issues,
|
|
3414
3423
|
w.Error,
|
|
@@ -3429,7 +3438,7 @@ class Pa {
|
|
|
3429
3438
|
);
|
|
3430
3439
|
}
|
|
3431
3440
|
}
|
|
3432
|
-
class
|
|
3441
|
+
class Fa {
|
|
3433
3442
|
constructor(t) {
|
|
3434
3443
|
this.context = t;
|
|
3435
3444
|
}
|
|
@@ -3465,7 +3474,7 @@ class Ma {
|
|
|
3465
3474
|
a.lastUpdateCheck = t, await this.context.saveConfig(a);
|
|
3466
3475
|
}
|
|
3467
3476
|
}
|
|
3468
|
-
function
|
|
3477
|
+
function ja(e) {
|
|
3469
3478
|
return {
|
|
3470
3479
|
id: Number(e.id),
|
|
3471
3480
|
operedAt: String(e.operedAt ?? ""),
|
|
@@ -3476,17 +3485,17 @@ function Oa(e) {
|
|
|
3476
3485
|
...e.vaultIds !== void 0 ? { vaultIds: Number(e.vaultIds) } : {}
|
|
3477
3486
|
};
|
|
3478
3487
|
}
|
|
3479
|
-
function
|
|
3488
|
+
function Ya(e) {
|
|
3480
3489
|
return e.operedAt.replace(/[-:\sT]/g, "").slice(0, 6);
|
|
3481
3490
|
}
|
|
3482
|
-
class
|
|
3491
|
+
class Ha {
|
|
3483
3492
|
constructor(t) {
|
|
3484
3493
|
this.context = t;
|
|
3485
3494
|
}
|
|
3486
3495
|
async getLogs(t) {
|
|
3487
3496
|
const a = await this.loadAllLogs();
|
|
3488
3497
|
return t.mode === "all" ? a : a.filter((i) => {
|
|
3489
|
-
const n =
|
|
3498
|
+
const n = Ya(i);
|
|
3490
3499
|
return !n || n.length !== 6 ? !1 : n >= t.from && n <= t.to;
|
|
3491
3500
|
});
|
|
3492
3501
|
}
|
|
@@ -3506,19 +3515,19 @@ class ja {
|
|
|
3506
3515
|
return n;
|
|
3507
3516
|
}
|
|
3508
3517
|
async loadAllLogs() {
|
|
3509
|
-
const a = (await ie(f.File.log)).map((i) =>
|
|
3518
|
+
const a = (await ie(f.File.log)).map((i) => ja(i));
|
|
3510
3519
|
return a.sort((i, n) => i.id - n.id), a;
|
|
3511
3520
|
}
|
|
3512
3521
|
}
|
|
3513
|
-
const
|
|
3514
|
-
function
|
|
3522
|
+
const Ua = bt(yt);
|
|
3523
|
+
function ge(e) {
|
|
3515
3524
|
return e.trim().replace(/^v/i, "");
|
|
3516
3525
|
}
|
|
3517
|
-
function
|
|
3518
|
-
return
|
|
3526
|
+
function We(e) {
|
|
3527
|
+
return ge(e).split(".").map((t) => Number(t.replace(/[^0-9].*$/, ""))).map((t) => Number.isFinite(t) ? t : 0);
|
|
3519
3528
|
}
|
|
3520
|
-
function
|
|
3521
|
-
const a =
|
|
3529
|
+
function za(e, t) {
|
|
3530
|
+
const a = We(e), i = We(t), n = Math.max(a.length, i.length);
|
|
3522
3531
|
for (let o = 0; o < n; o += 1) {
|
|
3523
3532
|
const c = a[o] ?? 0, s = i[o] ?? 0;
|
|
3524
3533
|
if (s > c)
|
|
@@ -3528,17 +3537,17 @@ function Ha(e, t) {
|
|
|
3528
3537
|
}
|
|
3529
3538
|
return !1;
|
|
3530
3539
|
}
|
|
3531
|
-
class
|
|
3540
|
+
class Ba {
|
|
3532
3541
|
currentVersion;
|
|
3533
3542
|
constructor(t) {
|
|
3534
|
-
this.currentVersion =
|
|
3543
|
+
this.currentVersion = ge(t);
|
|
3535
3544
|
}
|
|
3536
3545
|
async checkLatest(t = M.Repo) {
|
|
3537
|
-
const a = await this.fetchLatestRelease(t), i =
|
|
3546
|
+
const a = await this.fetchLatestRelease(t), i = ge(a.tag_name);
|
|
3538
3547
|
return {
|
|
3539
3548
|
currentVersion: this.currentVersion,
|
|
3540
3549
|
latestVersion: i,
|
|
3541
|
-
hasUpdate:
|
|
3550
|
+
hasUpdate: za(this.currentVersion, i),
|
|
3542
3551
|
htmlUrl: a.html_url,
|
|
3543
3552
|
publishedAt: a.published_at
|
|
3544
3553
|
};
|
|
@@ -3559,10 +3568,10 @@ class Ua {
|
|
|
3559
3568
|
status: n.status
|
|
3560
3569
|
})
|
|
3561
3570
|
);
|
|
3562
|
-
const o = await n.text(), c = h.join(
|
|
3571
|
+
const o = await n.text(), c = h.join(Ge.tmpdir(), `archiver-update-${Date.now()}.sh`);
|
|
3563
3572
|
await p.writeFile(c, o, { encoding: "utf8", mode: 493 });
|
|
3564
3573
|
try {
|
|
3565
|
-
const s = await
|
|
3574
|
+
const s = await Ua("bash", [c], { maxBuffer: 4194304 });
|
|
3566
3575
|
return [s.stdout, s.stderr].filter(Boolean).join(`
|
|
3567
3576
|
`).trim();
|
|
3568
3577
|
} finally {
|
|
@@ -3594,10 +3603,10 @@ class Ua {
|
|
|
3594
3603
|
return n;
|
|
3595
3604
|
}
|
|
3596
3605
|
}
|
|
3597
|
-
async function
|
|
3598
|
-
const e = new
|
|
3606
|
+
async function qa() {
|
|
3607
|
+
const e = new Da();
|
|
3599
3608
|
await e.init();
|
|
3600
|
-
const t = new
|
|
3609
|
+
const t = new Fa(e), a = new Ma(e), i = new Pa(e, a), n = new ya(e, t), o = new Ha(e), c = new Oa(e), s = "0.3.3", l = new Ba(s);
|
|
3601
3610
|
return {
|
|
3602
3611
|
context: e,
|
|
3603
3612
|
archiveService: i,
|
|
@@ -3610,11 +3619,11 @@ async function za() {
|
|
|
3610
3619
|
version: s
|
|
3611
3620
|
};
|
|
3612
3621
|
}
|
|
3613
|
-
async function
|
|
3614
|
-
if (!
|
|
3622
|
+
async function Wa(e) {
|
|
3623
|
+
if (!ye())
|
|
3615
3624
|
return "help";
|
|
3616
|
-
|
|
3617
|
-
const t = await
|
|
3625
|
+
E(r("index.no_command_action.unknown"));
|
|
3626
|
+
const t = await Jt({
|
|
3618
3627
|
title: r("index.no_command_action.question"),
|
|
3619
3628
|
description: r("index.no_command_action.note"),
|
|
3620
3629
|
options: [
|
|
@@ -3627,28 +3636,28 @@ async function Ba(e) {
|
|
|
3627
3636
|
enter: R(r("index.no_command_action.key.enter"))
|
|
3628
3637
|
})
|
|
3629
3638
|
});
|
|
3630
|
-
return t || process.exit(130), await e.configService.setNoCommandAction(t),
|
|
3639
|
+
return t || process.exit(130), await e.configService.setNoCommandAction(t), k(r("index.no_command_action.updated", { action: t })), t;
|
|
3631
3640
|
}
|
|
3632
|
-
async function
|
|
3633
|
-
const e = await
|
|
3641
|
+
async function Ja() {
|
|
3642
|
+
const e = await he(f.File.config, g.Config);
|
|
3634
3643
|
Z(e.language), ee({
|
|
3635
3644
|
style: e.style === "off" ? "off" : "on"
|
|
3636
3645
|
});
|
|
3637
|
-
const t = await
|
|
3646
|
+
const t = await Na();
|
|
3638
3647
|
if (t.installed) {
|
|
3639
3648
|
const o = t.profilePath ? ` ${t.profilePath}` : "";
|
|
3640
|
-
|
|
3649
|
+
E(r("index.shell_wrapper.installed", { where: o })), t.reloadCommand && E(
|
|
3641
3650
|
r("index.shell_wrapper.reload_hint", {
|
|
3642
3651
|
reloadCommand: t.reloadCommand
|
|
3643
3652
|
})
|
|
3644
3653
|
);
|
|
3645
3654
|
return;
|
|
3646
3655
|
}
|
|
3647
|
-
const a = await
|
|
3656
|
+
const a = await qa(), i = await a.configService.getConfig();
|
|
3648
3657
|
Z(i.language), ee(i);
|
|
3649
|
-
const n =
|
|
3658
|
+
const n = ka(a);
|
|
3650
3659
|
if (process.argv.length <= 2) {
|
|
3651
|
-
if ((i.noCommandAction === "unknown" ? await
|
|
3660
|
+
if ((i.noCommandAction === "unknown" ? await Wa(a) : i.noCommandAction) === "list") {
|
|
3652
3661
|
await n.parseAsync([...process.argv, "list"]);
|
|
3653
3662
|
return;
|
|
3654
3663
|
}
|
|
@@ -3657,6 +3666,6 @@ async function qa() {
|
|
|
3657
3666
|
}
|
|
3658
3667
|
await n.parseAsync(process.argv);
|
|
3659
3668
|
}
|
|
3660
|
-
|
|
3669
|
+
Ja().catch((e) => {
|
|
3661
3670
|
j(e.message), process.exit(1);
|
|
3662
3671
|
});
|