@ghostlytools/cli 1.7.3 → 1.8.0
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/README.md +30 -19
- package/SKILL.md +6 -4
- package/dist/assets/{api-B42F9ytB.js → api-Dj1yn0px.js} +2 -2
- package/dist/assets/{api-tf-wAAnB.js → api-I_KbuXHa.js} +192 -88
- package/dist/assets/api-I_KbuXHa.js.map +1 -0
- package/dist/assets/{apiKit-DJb9hulp.js → apiKit-C-_PWZvy.js} +44 -9
- package/dist/assets/apiKit-C-_PWZvy.js.map +1 -0
- package/dist/assets/{apps-DIrWmLgL.js → apps-DKIe8VjF.js} +11 -8
- package/dist/assets/apps-DKIe8VjF.js.map +1 -0
- package/dist/assets/{apps-BfoDISRg.js → apps-DbEfL_3b.js} +1 -1
- package/dist/assets/{arkade-CJAhhgPQ.js → arkade-k1bdSm70.js} +2 -2
- package/dist/assets/{arkade-CJAhhgPQ.js.map → arkade-k1bdSm70.js.map} +1 -1
- package/dist/assets/{backup-BkUeeduy.js → backup-Cdd6-HNu.js} +1 -1
- package/dist/assets/{backup-Bko-AAm0.js → backup-beKfbfNk.js} +7 -7
- package/dist/assets/{backup-Bko-AAm0.js.map → backup-beKfbfNk.js.map} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{blobFiles-Bckz9fjp.js → blobFiles-DOQDRdDI.js} +3 -3
- package/dist/assets/{blobFiles-Bckz9fjp.js.map → blobFiles-DOQDRdDI.js.map} +1 -1
- package/dist/assets/buttons-BO1_7V4L.js +2 -0
- package/dist/assets/{buttons-DeA6Yddq.js → buttons-ClI13rdv.js} +7 -6
- package/dist/assets/buttons-ClI13rdv.js.map +1 -0
- package/dist/assets/{daemonProof-Bp9lJDxf.js → daemonProof-DtrL5lE5.js} +2 -2
- package/dist/assets/{daemonProof-Bp9lJDxf.js.map → daemonProof-DtrL5lE5.js.map} +1 -1
- package/dist/assets/{envelope-Cz5fc7BM.js → envelope-B88yiCQj.js} +2 -2
- package/dist/assets/{envelope-Cz5fc7BM.js.map → envelope-B88yiCQj.js.map} +1 -1
- package/dist/assets/{errors-mnjSQlbX.js → errors-R4S2SAEM.js} +8 -3
- package/dist/assets/errors-R4S2SAEM.js.map +1 -0
- package/dist/assets/{fileBytes-OolN5cSY.js → fileBytes-BPDKufla.js} +1 -1
- package/dist/assets/{fileBytes-BD0v3rRG.js → fileBytes-DNgrRL0R.js} +3 -3
- package/dist/assets/{fileBytes-BD0v3rRG.js.map → fileBytes-DNgrRL0R.js.map} +1 -1
- package/dist/assets/{fileBytes-_fd-2JRY.js → fileBytes-Q3ehcEr8.js} +2 -2
- package/dist/assets/{fileBytes-_fd-2JRY.js.map → fileBytes-Q3ehcEr8.js.map} +1 -1
- package/dist/assets/fileBytesIdb-DZcESfTt.js +2 -0
- package/dist/assets/{fileBytesIdb-NtA8r9EM.js → fileBytesIdb-Dm1EyEbT.js} +3 -3
- package/dist/assets/{fileBytesIdb-NtA8r9EM.js.map → fileBytesIdb-Dm1EyEbT.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-B8fJwkwM.js → fileBytesOpfs-ZGD21c4Q.js} +3 -3
- package/dist/assets/{fileBytesOpfs-B8fJwkwM.js.map → fileBytesOpfs-ZGD21c4Q.js.map} +1 -1
- package/dist/assets/{groupFiles-BlZRBWpt.js → groupFiles-DjQc5XXv.js} +151 -28
- package/dist/assets/groupFiles-DjQc5XXv.js.map +1 -0
- package/dist/assets/{host-BX0DmKW6.js → host-CNWGB3-j.js} +86 -24
- package/dist/assets/host-CNWGB3-j.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-DitYDnXx.js → hyperdhtRelay-g7eXzf5h.js} +2 -2
- package/dist/assets/{hyperdhtRelay-DitYDnXx.js.map → hyperdhtRelay-g7eXzf5h.js.map} +1 -1
- package/dist/assets/{idb-BlH8-O3R.js → idb-BkOJES5_.js} +5 -3
- package/dist/assets/idb-BkOJES5_.js.map +1 -0
- package/dist/assets/{irohWeb-R3bcd34h.js → irohWeb-Bx8dI4be.js} +2 -2
- package/dist/assets/{irohWeb-R3bcd34h.js.map → irohWeb-Bx8dI4be.js.map} +1 -1
- package/dist/assets/{main-6QOSvQ8b.js → main-BRxhBctJ.js} +462 -126
- package/dist/assets/main-BRxhBctJ.js.map +1 -0
- package/dist/assets/{mainline-BfwezHWi.js → mainline-CwuS6ngj.js} +39 -12
- package/dist/assets/mainline-CwuS6ngj.js.map +1 -0
- package/dist/assets/mints-BaOmx517.js +2 -0
- package/dist/assets/{mints-BrlY773j.js → mints-j5XAOk4f.js} +15 -3
- package/dist/assets/mints-j5XAOk4f.js.map +1 -0
- package/dist/assets/{networkReason-Ba9415nn.js → networkReason-CIAMieQm.js} +3 -3
- package/dist/assets/{networkReason-Ba9415nn.js.map → networkReason-CIAMieQm.js.map} +1 -1
- package/dist/assets/{nwc-ovXSN2M2.js → nwc-C9JLJJkL.js} +3 -3
- package/dist/assets/{nwc-ovXSN2M2.js.map → nwc-C9JLJJkL.js.map} +1 -1
- package/dist/assets/{nwcProvider-BzZbfFP3.js → nwcProvider-pFMrsUJh.js} +2 -2
- package/dist/assets/{nwcProvider-BzZbfFP3.js.map → nwcProvider-pFMrsUJh.js.map} +1 -1
- package/dist/assets/{profiles-C6XWqre5.js → profiles-MFtCmJwK.js} +104 -10
- package/dist/assets/profiles-MFtCmJwK.js.map +1 -0
- package/dist/assets/{registry-B0Uv9yL6.js → registry-Cks7FA_o.js} +45 -14
- package/dist/assets/registry-Cks7FA_o.js.map +1 -0
- package/dist/assets/{registry-CFtlhWCI.js → registry-DY2ixQfU.js} +1 -1
- package/dist/assets/{resolve-BzFG4WDU.js → resolve-C4Y2HPqQ.js} +79 -30
- package/dist/assets/resolve-C4Y2HPqQ.js.map +1 -0
- package/dist/assets/{restoredRows-Fv-MuY45.js → restoredRows-BCRCjhdF.js} +27 -3
- package/dist/assets/{restoredRows-Fv-MuY45.js.map → restoredRows-BCRCjhdF.js.map} +1 -1
- package/dist/assets/{server-BGCuHbmQ.js → server-D9RAmGdm.js} +1398 -358
- package/dist/assets/server-D9RAmGdm.js.map +1 -0
- package/dist/assets/{src-DWw2hUE5.js → src-1RU4TilT.js} +1416 -234
- package/dist/assets/src-1RU4TilT.js.map +1 -0
- package/dist/assets/{translate-DObb-1tq.js → translate-od5GbpvR.js} +19 -13
- package/dist/assets/translate-od5GbpvR.js.map +1 -0
- package/dist/assets/{usdt-Bkva90Vo.js → usdt-DldXV0MR.js} +3 -3
- package/dist/assets/{usdt-Bkva90Vo.js.map → usdt-DldXV0MR.js.map} +1 -1
- package/dist/assets/waitNotice-Ck3el3_Z.js +45 -0
- package/dist/assets/waitNotice-Ck3el3_Z.js.map +1 -0
- package/dist/assets/{words-odSAoasK.js → words-BS2qq_vV.js} +7 -4
- package/dist/assets/words-BS2qq_vV.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/claude-code-agent.sh +1 -1
- package/package.json +1 -1
- package/dist/assets/api-tf-wAAnB.js.map +0 -1
- package/dist/assets/apiKit-DJb9hulp.js.map +0 -1
- package/dist/assets/apps-DIrWmLgL.js.map +0 -1
- package/dist/assets/buttons-Be7u0V5g.js +0 -2
- package/dist/assets/buttons-DeA6Yddq.js.map +0 -1
- package/dist/assets/errors-mnjSQlbX.js.map +0 -1
- package/dist/assets/fileBytesIdb-CsSQcSxD.js +0 -2
- package/dist/assets/groupFiles-BlZRBWpt.js.map +0 -1
- package/dist/assets/host-BX0DmKW6.js.map +0 -1
- package/dist/assets/idb-BlH8-O3R.js.map +0 -1
- package/dist/assets/main-6QOSvQ8b.js.map +0 -1
- package/dist/assets/mainline-BfwezHWi.js.map +0 -1
- package/dist/assets/mints-BrlY773j.js.map +0 -1
- package/dist/assets/mints-CqTdA4Gk.js +0 -2
- package/dist/assets/profiles-C6XWqre5.js.map +0 -1
- package/dist/assets/registry-B0Uv9yL6.js.map +0 -1
- package/dist/assets/resolve-BzFG4WDU.js.map +0 -1
- package/dist/assets/server-BGCuHbmQ.js.map +0 -1
- package/dist/assets/src-DWw2hUE5.js.map +0 -1
- package/dist/assets/translate-DObb-1tq.js.map +0 -1
- package/dist/assets/words-odSAoasK.js.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { u as fileStore } from "./idb-
|
|
3
|
-
import {
|
|
4
|
-
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-
|
|
5
|
-
import { t as IDENTITY_PROVIDERS } from "./registry-
|
|
6
|
-
import { a as waitForConfirmed, c as waitForMessage, i as pressable, l as waitForRemoval, n as buttonsCard, o as waitForEdit, s as waitForGroupFrame, t as BUTTON_METHODS, u as findSecret } from "./buttons-
|
|
7
|
-
import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-
|
|
8
|
-
import { i as localFileError, r as asCliError, t as CliError } from "./errors-
|
|
9
|
-
import { _ as oneOf, a as dhtOnly, b as str, c as findGroup, d as inviteTaken, f as list, g as num, h as node, i as chatOrGroup, n as bool, o as findChat, p as messageOf, r as chatOf, s as findChatOrGroup, u as groupOf, v as sentAt, x as
|
|
10
|
-
import { a as checkShownName } from "./profiles-
|
|
11
|
-
import { t as BACKUP_METHODS } from "./backup-
|
|
12
|
-
import { o as checkedBundle } from "./apps-
|
|
1
|
+
import { Au as toBase64Url, Bo as parseLocalTarget, Cu as MAX_AVATAR_LENGTH, Fr as TYPING_KINDS, Gn as GROUP_FILE_LIMITS, Ho as LIMITS, Ir as TYPING_REFRESH_MS, Ka as replySnippet, Ki as identityStatement, Rc as APP_PERMISSIONS, Ro as GhostlyHttpError, Rr as sanitizeTypingStatus, Sl as inviteLink, Uc as isAppUrl, X as groupName, Zc as appRef, ao as cardLine, ba as voiceLevel, cl as readImageMeta, da as sanitizeMime, fa as PLAYABLE_AUDIO, fo as claimedTime, ga as downsamplePeaks, ha as baseMime, ii as APP_DATA_MAX_BYTES, jo as AWAITING_PEER_MS, ku as randomBytes$1, lo as statusCardBytes, ma as VOICE_METER, pa as VOICE_LIMITS, ro as appCardId, so as checkStatusCard, tl as isAppRef, to as STATUS_CARD_LIMITS, ua as sanitizeFileName, va as parseVoiceMeta, wl as ownInviteRefusal, wu as sanitizeAvatar, ya as voiceDownloadName } from "./src-1RU4TilT.js";
|
|
2
|
+
import { u as fileStore } from "./idb-BkOJES5_.js";
|
|
3
|
+
import { O as waitingGroupFile, T as removeStored, X as iceServerProblem, Z as iceServerSetting, i as groupOfFile, k as IDENTITY_DRAFT_TTL_MS, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-DjQc5XXv.js";
|
|
4
|
+
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-DNgrRL0R.js";
|
|
5
|
+
import { t as IDENTITY_PROVIDERS } from "./registry-Cks7FA_o.js";
|
|
6
|
+
import { a as waitForConfirmed, c as waitForMessage, i as pressable, l as waitForRemoval, n as buttonsCard, o as waitForEdit, s as waitForGroupFrame, t as BUTTON_METHODS, u as findSecret } from "./buttons-ClI13rdv.js";
|
|
7
|
+
import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-BS2qq_vV.js";
|
|
8
|
+
import { i as localFileError, r as asCliError, t as CliError } from "./errors-R4S2SAEM.js";
|
|
9
|
+
import { S as waitForState, _ as oneOf, a as dhtOnly, b as str, c as findGroup, d as inviteTaken, f as list, g as num, h as node, i as chatOrGroup, n as bool, o as findChat, p as messageOf, r as chatOf, s as findChatOrGroup, u as groupOf, v as sentAt, x as transportOffered, y as state } from "./apiKit-C-_PWZvy.js";
|
|
10
|
+
import { a as checkShownName } from "./profiles-MFtCmJwK.js";
|
|
11
|
+
import { t as BACKUP_METHODS } from "./backup-beKfbfNk.js";
|
|
12
|
+
import { o as checkedBundle } from "./apps-DKIe8VjF.js";
|
|
13
13
|
import { generateMnemonic } from "@scure/bip39";
|
|
14
14
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
15
|
+
import { execFile, spawn } from "node:child_process";
|
|
15
16
|
import { openAsBlob, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { access, constants as constants$1, open, readFile, rm, stat } from "node:fs/promises";
|
|
17
|
+
import { access, constants as constants$1, copyFile, link, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
17
18
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
18
|
-
import { spawn } from "node:child_process";
|
|
19
19
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
20
20
|
import { createServer } from "node:http";
|
|
21
21
|
import { Readable } from "node:stream";
|
|
@@ -749,6 +749,34 @@ function filesOf(messages, transferOf) {
|
|
|
749
749
|
transfer: transferOf(m.file.id) ?? null
|
|
750
750
|
}));
|
|
751
751
|
}
|
|
752
|
+
/** A file's size as a person reads it: "40 MB", "26.2 MB". */
|
|
753
|
+
var megabytes = (size) => `${Math.round(size / 1e5) / 10} MB`;
|
|
754
|
+
/**
|
|
755
|
+
* Where an unfinished transfer stands, in words, for a person reading a timeout: the stage's id ("asking", "waiting")
|
|
756
|
+
* stays in `details.stage` for a bot. A group's file says why it waits (`note`), as the app does.
|
|
757
|
+
*/
|
|
758
|
+
function stageWords(transfer) {
|
|
759
|
+
switch (transfer.stage) {
|
|
760
|
+
case "preparing": return "getting it ready to send";
|
|
761
|
+
case "waiting": return transfer.note ?? "waiting for a connection to the contact";
|
|
762
|
+
case "asking": return transfer.direction === "in" ? "waiting for you to take it (file accept)" : "waiting for the contact to take it";
|
|
763
|
+
case "queued": return "waiting its turn";
|
|
764
|
+
case "paused": return transfer.pausedBy === "peer" ? "paused by the contact" : "paused here (file resume)";
|
|
765
|
+
case "verifying": return "every byte here, checking it";
|
|
766
|
+
default: return String(transfer.stage);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* A transfer that waits for a person's decision (`asking`), with whose: `me` (`file accept` takes it here) or `contact`
|
|
771
|
+
* (theirs). A received file's `transferring` alone read as if it were moving.
|
|
772
|
+
*/
|
|
773
|
+
function withWaitingFor(transfer) {
|
|
774
|
+
if (transfer?.state !== "transferring" || transfer.stage !== "asking") return transfer;
|
|
775
|
+
return {
|
|
776
|
+
...transfer,
|
|
777
|
+
waitingFor: transfer.direction === "in" ? "me" : "contact"
|
|
778
|
+
};
|
|
779
|
+
}
|
|
752
780
|
/** The chat or the group a file command names (`findChatOrGroup`). */
|
|
753
781
|
var chatOrGroupOf = (ctx, params) => findChatOrGroup(state(ctx).links, state(ctx).groups, str(params, "chat", true));
|
|
754
782
|
/**
|
|
@@ -904,6 +932,42 @@ function saveName(name) {
|
|
|
904
932
|
const clean = sanitizeFileName(name);
|
|
905
933
|
return fitName(clean.startsWith("-") ? `_${clean}` : clean);
|
|
906
934
|
}
|
|
935
|
+
/**
|
|
936
|
+
* Gives the whole file at `partial` the name `target`: over a file there when `force`, else never (EEXIST). Where the
|
|
937
|
+
* file system has no hard links (exFAT, some network shares), it is copied under the name, still never over a file.
|
|
938
|
+
*/
|
|
939
|
+
async function place(partial, target, force) {
|
|
940
|
+
if (force) return rename(partial, target);
|
|
941
|
+
try {
|
|
942
|
+
await link(partial, target);
|
|
943
|
+
} catch (error) {
|
|
944
|
+
if (![
|
|
945
|
+
"EPERM",
|
|
946
|
+
"ENOTSUP",
|
|
947
|
+
"EOPNOTSUPP",
|
|
948
|
+
"ENOSYS"
|
|
949
|
+
].includes(error.code ?? "")) throw error;
|
|
950
|
+
await copyFile(partial, target, constants$1.COPYFILE_EXCL);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Marks a saved copy of a contact's file as downloaded, as a browser and Ghostly Desktop (`file_store.rs`
|
|
955
|
+
* `mark_downloaded`) do, so the system checks it when it is opened: Gatekeeper's "downloaded from the internet" on
|
|
956
|
+
* macOS, SmartScreen and Office's Protected View on Windows. Node has no extended attributes, so macOS's own `xattr`
|
|
957
|
+
* writes `com.apple.quarantine`; on Windows it is the file's `Zone.Identifier` stream. Best effort: a file system that
|
|
958
|
+
* cannot hold the mark still gets the file.
|
|
959
|
+
*/
|
|
960
|
+
async function markDownloaded(path) {
|
|
961
|
+
if (process.platform === "darwin") {
|
|
962
|
+
const value = `0081;${Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0")};Ghostly;`;
|
|
963
|
+
await new Promise((done) => execFile("/usr/bin/xattr", [
|
|
964
|
+
"-w",
|
|
965
|
+
"com.apple.quarantine",
|
|
966
|
+
value,
|
|
967
|
+
path
|
|
968
|
+
], { timeout: 1e4 }, () => done()));
|
|
969
|
+
} else if (process.platform === "win32") await writeFile(`${path}:Zone.Identifier`, "[ZoneTransfer]\r\nZoneId=3\r\n").catch(() => {});
|
|
970
|
+
}
|
|
907
971
|
var ACTIONS = [
|
|
908
972
|
"accept",
|
|
909
973
|
"decline",
|
|
@@ -1012,13 +1076,13 @@ var FILE_METHODS = {
|
|
|
1012
1076
|
const kept = await keptOf(`group:${target.group.id}`);
|
|
1013
1077
|
return {
|
|
1014
1078
|
group: target.group.id,
|
|
1015
|
-
files: filesOf(await node(ctx).groupMessages({ groupId: target.group.id }), (id) => views[id] ?? kept.get(id))
|
|
1079
|
+
files: filesOf(await node(ctx).groupMessages({ groupId: target.group.id }), (id) => withWaitingFor(views[id] ?? kept.get(id)))
|
|
1016
1080
|
};
|
|
1017
1081
|
}
|
|
1018
1082
|
const kept = await keptOf(target.link.id);
|
|
1019
1083
|
return {
|
|
1020
1084
|
chat: target.link.id,
|
|
1021
|
-
files: filesOf(await node(ctx).getMessages(target.link.id), (id) => views[id] ?? kept.get(id))
|
|
1085
|
+
files: filesOf(await node(ctx).getMessages(target.link.id), (id) => withWaitingFor(views[id] ?? kept.get(id)))
|
|
1022
1086
|
};
|
|
1023
1087
|
},
|
|
1024
1088
|
/**
|
|
@@ -1059,7 +1123,14 @@ var FILE_METHODS = {
|
|
|
1059
1123
|
const transfer = state(ctx).transfers[fileId];
|
|
1060
1124
|
if (!transfer || transfer.state === "done") throw new CliError("refused", outgoing ? "Nothing to send again: it arrived whole" : "Nothing to ask for: the file is all here");
|
|
1061
1125
|
if (transfer.state === "failed" && (!outgoing || !transfer.retry)) throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
|
|
1062
|
-
} else
|
|
1126
|
+
} else {
|
|
1127
|
+
const outgoing = fileId.startsWith(`${linkId}-out-`);
|
|
1128
|
+
if (outgoing && (action === "accept" || action === "decline")) throw new CliError("bad_request", "A file sent from here is not accepted or declined: file cancel stops it");
|
|
1129
|
+
await refuseAllHere();
|
|
1130
|
+
const transfer = state(ctx).transfers[fileId] ?? (await fileStore.get(fileId).catch(() => void 0))?.transfer;
|
|
1131
|
+
if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}${outgoing && transfer.retry ? " (file resend sends it again)" : ""}`);
|
|
1132
|
+
if (outgoing && action === "cancel" && transfer?.state === "transferring" && (transfer.stage === "verifying" || transfer.size > 0 && transfer.transferred >= transfer.size && transfer.stage !== "asking" && transfer.stage !== "queued" && transfer.stage !== "paused")) throw new CliError("refused", "Too late to cancel: it arrived whole, and the contact keeps it");
|
|
1133
|
+
}
|
|
1063
1134
|
await node(ctx).fileAction({
|
|
1064
1135
|
linkId,
|
|
1065
1136
|
fileId,
|
|
@@ -1087,10 +1158,10 @@ var FILE_METHODS = {
|
|
|
1087
1158
|
}) * 1e3;
|
|
1088
1159
|
const transfer = await waitForState(ctx, (s) => {
|
|
1089
1160
|
const now = s.transfers[fileId] ?? stored?.transfer;
|
|
1090
|
-
return now && (now.state === "done" || now.state === "failed") ? now : void 0;
|
|
1161
|
+
return now && (now.state === "done" || now.state === "failed" || now.stage === "asking" && now.direction === "in") ? now : void 0;
|
|
1091
1162
|
}, ms, `file ${fileId} to arrive`).catch((error) => {
|
|
1092
1163
|
const now = state(ctx).transfers[fileId];
|
|
1093
|
-
if (error instanceof CliError && error.code === "timeout" && now) throw new CliError("timeout", `${error.message} (${now.transferred} of ${now.size} bytes${now.stage ? `, ${now
|
|
1164
|
+
if (error instanceof CliError && error.code === "timeout" && now) throw new CliError("timeout", `${error.message} (${now.transferred} of ${now.size} bytes${now.stage ? `, ${stageWords(now)}` : ""})`, {
|
|
1094
1165
|
file: fileId,
|
|
1095
1166
|
transferred: now.transferred,
|
|
1096
1167
|
size: now.size,
|
|
@@ -1103,6 +1174,15 @@ var FILE_METHODS = {
|
|
|
1103
1174
|
...where,
|
|
1104
1175
|
retry: !!transfer.retry
|
|
1105
1176
|
});
|
|
1177
|
+
if (transfer.state !== "done") {
|
|
1178
|
+
const name = (stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name ?? "The file";
|
|
1179
|
+
throw new CliError("confirm", `${name} (${megabytes(transfer.size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
1180
|
+
file: fileId,
|
|
1181
|
+
...where,
|
|
1182
|
+
size: transfer.size,
|
|
1183
|
+
stage: "asking"
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1106
1186
|
return {
|
|
1107
1187
|
...where,
|
|
1108
1188
|
file: fileId,
|
|
@@ -1126,22 +1206,28 @@ var FILE_METHODS = {
|
|
|
1126
1206
|
if (!stored?.metadata) throw new CliError("not_found", `No file ${fileId}`);
|
|
1127
1207
|
if (stored.leftOut) throw new CliError("not_found", "Not in this backup: the light backup this profile was restored from left the file out");
|
|
1128
1208
|
const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? stored.transfer;
|
|
1209
|
+
if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
|
|
1129
1210
|
if (transfer && transfer.state !== "done") throw new CliError("unavailable", `The file is not all here yet (${transfer.transferred} of ${transfer.size} bytes)`);
|
|
1130
1211
|
const named = str(params, "path") ? resolve(str(params, "path", true)) : join(resolve(str(params, "dir") ?? "."), saveName(stored.metadata.voice ? voiceDownloadName(stored.metadata.mime, await voiceTime(ctx, stored)) : stored.metadata.name));
|
|
1131
1212
|
const force = bool(params, "force");
|
|
1132
1213
|
const free = !force && !str(params, "path") && !!stored.metadata.voice;
|
|
1133
1214
|
const ext = extname(named), stem = named.slice(0, named.length - ext.length);
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1215
|
+
const taken = async (target, code) => {
|
|
1216
|
+
const there = await stat(target).catch(() => void 0);
|
|
1217
|
+
if (there?.isDirectory()) return new CliError("bad_request", `${target} is a folder: name a file, or use --dir ${target} (dir over the socket)`);
|
|
1218
|
+
if (there && !force || code === "EEXIST") return new CliError("confirm", `${target} exists: pass --force (force: true over the socket) to replace it`);
|
|
1219
|
+
};
|
|
1220
|
+
let target = named;
|
|
1221
|
+
for (let n = 2, refused = await taken(target); refused; n += 1, refused = await taken(target)) {
|
|
1222
|
+
if (!free || refused.code !== "confirm" || n > 1e3) throw refused;
|
|
1223
|
+
target = `${stem} (${n})${ext}`;
|
|
1224
|
+
}
|
|
1225
|
+
const partial = join(dirname(target), `.ghostly-save-${process.pid}-${toBase64Url(randomBytes$1(6))}.partial`);
|
|
1226
|
+
let out;
|
|
1227
|
+
try {
|
|
1228
|
+
out = await open(partial, "wx", 384);
|
|
1137
1229
|
} catch (error) {
|
|
1138
1230
|
const code = error.code;
|
|
1139
|
-
if (free && code === "EEXIST" && n <= 1e3) {
|
|
1140
|
-
target = `${stem} (${n})${ext}`;
|
|
1141
|
-
continue;
|
|
1142
|
-
}
|
|
1143
|
-
if ((code === "EEXIST" || code === "EISDIR") && (await stat(target).catch(() => void 0))?.isDirectory()) throw new CliError("bad_request", `${target} is a folder: name a file, or use dir (--dir ${target})`);
|
|
1144
|
-
if (code === "EEXIST") throw new CliError("confirm", `${target} exists: pass force (--force) to replace it`);
|
|
1145
1231
|
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
1146
1232
|
const folder = dirname(target), there = await stat(folder).catch(() => void 0);
|
|
1147
1233
|
if (!there) throw new CliError("not_found", `No such file or folder: ${folder}`);
|
|
@@ -1165,10 +1251,24 @@ var FILE_METHODS = {
|
|
|
1165
1251
|
await out.write(chunk);
|
|
1166
1252
|
written = chunk.length;
|
|
1167
1253
|
} else throw new CliError("not_found", "The file's bytes are not on this device");
|
|
1168
|
-
complete = true;
|
|
1169
|
-
} finally {
|
|
1170
1254
|
await out.close();
|
|
1171
|
-
|
|
1255
|
+
out = null;
|
|
1256
|
+
for (let n = 2; !complete; n += 1) try {
|
|
1257
|
+
await place(partial, target, force);
|
|
1258
|
+
complete = true;
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
const code = error.code;
|
|
1261
|
+
const refused = code === "EEXIST" || code === "EISDIR" || code === "ENOTEMPTY" ? await taken(target, code) : void 0;
|
|
1262
|
+
if (free && refused?.code === "confirm" && n <= 1e3) {
|
|
1263
|
+
target = `${stem} (${n})${ext}`;
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
throw refused ?? error;
|
|
1267
|
+
}
|
|
1268
|
+
if (stored.direction !== "out") await markDownloaded(target);
|
|
1269
|
+
} finally {
|
|
1270
|
+
await out?.close();
|
|
1271
|
+
await rm(partial, { force: true });
|
|
1172
1272
|
}
|
|
1173
1273
|
return {
|
|
1174
1274
|
file: fileId,
|
|
@@ -2438,7 +2538,10 @@ var nodeLocalFetch = async (request) => {
|
|
|
2438
2538
|
})() : null
|
|
2439
2539
|
};
|
|
2440
2540
|
};
|
|
2441
|
-
/**
|
|
2541
|
+
/**
|
|
2542
|
+
* Contact services open on loopback ports, by `<peer>/<service>`, while this process runs: each as soon as it starts
|
|
2543
|
+
* opening, so a second `service open` meanwhile answers the same one. A server that could not open is taken out.
|
|
2544
|
+
*/
|
|
2442
2545
|
var open$1 = /* @__PURE__ */ new Map();
|
|
2443
2546
|
var MAX_RESPONSE_BYTES = 33554432;
|
|
2444
2547
|
/** Cookie names an opened service may set and have passed back (browsers keep about 180 per host). */
|
|
@@ -2713,7 +2816,7 @@ var SERVICE_METHODS = {
|
|
|
2713
2816
|
max: 65535,
|
|
2714
2817
|
whole: true
|
|
2715
2818
|
});
|
|
2716
|
-
const already = open$1.get(key);
|
|
2819
|
+
const already = await open$1.get(key)?.catch(() => void 0);
|
|
2717
2820
|
if (already) {
|
|
2718
2821
|
const on = already.server.address().port;
|
|
2719
2822
|
if (port && port !== on) throw new CliError("busy", `That service is open here on port ${on}: ghostly service close ${link.id} ${service} first, or leave out --port`);
|
|
@@ -2725,10 +2828,13 @@ var SERVICE_METHODS = {
|
|
|
2725
2828
|
}
|
|
2726
2829
|
if (!link.peerServices?.some((s) => s.id === service)) throw new CliError("not_found", `The contact shares no service ${service} (or is not live)`);
|
|
2727
2830
|
const peer = link.peerPubKeyZ32;
|
|
2728
|
-
|
|
2831
|
+
if (open$1.has(key)) return SERVICE_METHODS["service.open"](ctx, params);
|
|
2832
|
+
const opening = openServiceServer((request) => node(ctx).request(peer, service, request), port).catch((error) => {
|
|
2833
|
+
if (open$1.get(key) === opening) open$1.delete(key);
|
|
2729
2834
|
throw portError(error, port);
|
|
2730
2835
|
});
|
|
2731
|
-
open$1.set(key,
|
|
2836
|
+
open$1.set(key, opening);
|
|
2837
|
+
const opened = await opening;
|
|
2732
2838
|
return {
|
|
2733
2839
|
chat: link.id,
|
|
2734
2840
|
service,
|
|
@@ -2737,9 +2843,10 @@ var SERVICE_METHODS = {
|
|
|
2737
2843
|
},
|
|
2738
2844
|
async "service.close"(ctx, params) {
|
|
2739
2845
|
const key = `${chatOf(ctx, params).peerPubKeyZ32}/${str(params, "service", true)}`;
|
|
2740
|
-
const
|
|
2741
|
-
if (!entry) throw new CliError("not_found", "That service is not open here");
|
|
2846
|
+
const pending = open$1.get(key);
|
|
2742
2847
|
open$1.delete(key);
|
|
2848
|
+
const entry = await pending?.catch(() => void 0);
|
|
2849
|
+
if (!entry) throw new CliError("not_found", "That service is not open here");
|
|
2743
2850
|
await new Promise((resolve) => {
|
|
2744
2851
|
entry.server.close(() => resolve());
|
|
2745
2852
|
entry.server.closeAllConnections();
|
|
@@ -3233,6 +3340,18 @@ var WALLET_REFUSALS = [
|
|
|
3233
3340
|
[/^The faucet did not pay: This wallet has no test mint\b/, "unavailable"],
|
|
3234
3341
|
[/^Ghostly cannot ask this wallet's faucet by itself\b/, "unavailable"]
|
|
3235
3342
|
];
|
|
3343
|
+
/**
|
|
3344
|
+
* `chat pay` or `chat request` refused for want of a Cashu wallet of that network at all: the engine says the wallet
|
|
3345
|
+
* is short of sats, or that no mint could make an invoice, and names nothing to do. `refused` with the command that
|
|
3346
|
+
* makes one, as a contact with no wallet is told; `details.reason` `no_wallet`. With a wallet, the engine's own words.
|
|
3347
|
+
*/
|
|
3348
|
+
function noWalletOf(ctx, n, error) {
|
|
3349
|
+
if ((state(ctx).wallet.wallets ?? []).some((w) => w.type === "cashu" && w.network === n)) return error;
|
|
3350
|
+
return new CliError("refused", `You have no ${n === "mainnet" ? "Mainnet" : "Testnet"} Cashu wallet: ghostly wallet create cashu${n === "mainnet" ? " --network mainnet" : ""}`, { reason: "no_wallet" });
|
|
3351
|
+
}
|
|
3352
|
+
var engineCode = (error) => error instanceof Error ? error.engineCode : void 0;
|
|
3353
|
+
/** What the engine says to a Cashu request it has no mint for: no mint for the invoice, or none to name for ecash. */
|
|
3354
|
+
var NO_MINT = /^(No mint could create an invoice: No mint configured|You have no (Mainnet|Testnet) Cashu wallet: create one in Wallet → New)$/;
|
|
3236
3355
|
function walletRefusal(error) {
|
|
3237
3356
|
if (!(error instanceof Error) || error instanceof CliError) return error;
|
|
3238
3357
|
const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
|
|
@@ -3475,6 +3594,8 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3475
3594
|
network: n,
|
|
3476
3595
|
...memo ? { memo } : {},
|
|
3477
3596
|
...real(params)
|
|
3597
|
+
}).catch((error) => {
|
|
3598
|
+
throw engineCode(error) === "notEnoughSats" ? noWalletOf(ctx, n, error) : error;
|
|
3478
3599
|
});
|
|
3479
3600
|
return {
|
|
3480
3601
|
chat: link.id,
|
|
@@ -3490,15 +3611,18 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
3490
3611
|
const method = params.method === void 0 ? void 0 : oneOf(params, "method", PAY_METHODS, "cashu");
|
|
3491
3612
|
const rail = params.rail === void 0 ? void 0 : oneOf(params, "rail", ["cashu", "lightning"], "cashu");
|
|
3492
3613
|
await federationsOpen(ctx);
|
|
3614
|
+
const n = network(params);
|
|
3493
3615
|
const { paymentId } = await node(ctx).requestPayment({
|
|
3494
3616
|
linkId: link.id,
|
|
3495
3617
|
amount,
|
|
3496
3618
|
timestamp: sentAt(),
|
|
3497
|
-
network:
|
|
3619
|
+
network: n,
|
|
3498
3620
|
...memo ? { memo } : {},
|
|
3499
3621
|
...method ? { method } : {},
|
|
3500
3622
|
...rail ? { rail } : {},
|
|
3501
3623
|
...str(params, "card") ? { card: str(params, "card") } : {}
|
|
3624
|
+
}).catch((error) => {
|
|
3625
|
+
throw (!method || method === "cashu") && error instanceof Error && NO_MINT.test(error.message) ? noWalletOf(ctx, n, error) : error;
|
|
3502
3626
|
});
|
|
3503
3627
|
return {
|
|
3504
3628
|
chat: link.id,
|
|
@@ -3714,7 +3838,8 @@ var inviteShown = /* @__PURE__ */ new WeakMap();
|
|
|
3714
3838
|
/**
|
|
3715
3839
|
* Refuses DHT only (a hold, `chat transport dht`) while a call is on in the chat. A call's signals cross the live
|
|
3716
3840
|
* link: off it, the call talked on over its own connection, and a hang-up from either side never reached the other
|
|
3717
|
-
* (that call ended only when its media stalled out, 16 s later).
|
|
3841
|
+
* (that call ended only when its media stalled out, 16 s later). Removing the chat (`chat remove`) is refused the same
|
|
3842
|
+
* way: the call talked on in a chat gone from this device, and its hang-up had no chat left to cross.
|
|
3718
3843
|
*/
|
|
3719
3844
|
function noCallOn(ctx, linkId, then) {
|
|
3720
3845
|
const call = ctx.calls.list().find((c) => c.chat === linkId);
|
|
@@ -3784,7 +3909,8 @@ var METHODS = {
|
|
|
3784
3909
|
protocol: s.transport.protocol,
|
|
3785
3910
|
relays: s.transport.relays
|
|
3786
3911
|
},
|
|
3787
|
-
events: { lastSeq: ctx.hub.lastSeq }
|
|
3912
|
+
events: { lastSeq: ctx.hub.lastSeq },
|
|
3913
|
+
...ctx.listen && { listen: true }
|
|
3788
3914
|
};
|
|
3789
3915
|
},
|
|
3790
3916
|
async "profile.get"(ctx) {
|
|
@@ -4255,8 +4381,10 @@ var METHODS = {
|
|
|
4255
4381
|
},
|
|
4256
4382
|
async "chat.remove"(ctx, params) {
|
|
4257
4383
|
const link = chatNotGroup(ctx, params, "group forget", "--yes");
|
|
4258
|
-
if (!bool(params, "yes")) throw new CliError("confirm", "Removing a chat deletes its keys and history on this device; pass yes (
|
|
4384
|
+
if (!bool(params, "yes")) throw new CliError("confirm", "Removing a chat deletes its keys and history on this device; pass --yes (yes: true over the socket) to go on");
|
|
4385
|
+
noCallOn(ctx, link.id, "remove the chat");
|
|
4259
4386
|
await node(ctx).removeLink({ linkId: link.id });
|
|
4387
|
+
ctx.calls.forgetChat(link.id);
|
|
4260
4388
|
return { removed: link.id };
|
|
4261
4389
|
},
|
|
4262
4390
|
async "chat.transport"(ctx, params) {
|
|
@@ -4265,6 +4393,7 @@ var METHODS = {
|
|
|
4265
4393
|
const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
|
|
4266
4394
|
if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
|
|
4267
4395
|
if (transport === "dht") noCallOn(ctx, link.id, "put the chat on DHT only");
|
|
4396
|
+
else if (transport !== "auto") transportOffered(link, transport);
|
|
4268
4397
|
await node(ctx).setChatTransport({
|
|
4269
4398
|
linkId: link.id,
|
|
4270
4399
|
transport
|
|
@@ -4487,7 +4616,7 @@ var METHODS = {
|
|
|
4487
4616
|
max: 600
|
|
4488
4617
|
});
|
|
4489
4618
|
if (!typing && seconds) throw new CliError("bad_request", "for keeps typing on: not with stop");
|
|
4490
|
-
if (typing && group.status !== "active") throw new CliError("
|
|
4619
|
+
if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? "You are not in this group");
|
|
4491
4620
|
const target = { groupId: group.id };
|
|
4492
4621
|
endTyping(ctx, target, false);
|
|
4493
4622
|
sayTyping(ctx, target, typing, word);
|
|
@@ -4507,7 +4636,7 @@ var METHODS = {
|
|
|
4507
4636
|
},
|
|
4508
4637
|
async "group.leave"(ctx, params) {
|
|
4509
4638
|
const group = groupOf(ctx, params);
|
|
4510
|
-
if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass yes (
|
|
4639
|
+
if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass --yes (yes: true over the socket) to go on");
|
|
4511
4640
|
const { admin } = await node(ctx).leaveGroup({ groupId: group.id });
|
|
4512
4641
|
const next = admin ? group.members.find((m) => m.key === admin) : void 0;
|
|
4513
4642
|
return {
|
|
@@ -4520,7 +4649,7 @@ var METHODS = {
|
|
|
4520
4649
|
},
|
|
4521
4650
|
async "group.forget"(ctx, params) {
|
|
4522
4651
|
const group = groupOf(ctx, params, "chat remove <chat> --yes");
|
|
4523
|
-
if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass yes (
|
|
4652
|
+
if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass --yes (yes: true over the socket) to go on");
|
|
4524
4653
|
await node(ctx).forgetGroup({ groupId: group.id });
|
|
4525
4654
|
return { forgotten: group.id };
|
|
4526
4655
|
},
|
|
@@ -4545,7 +4674,8 @@ var METHODS = {
|
|
|
4545
4674
|
setTimeout(() => ctx.stop(), 10);
|
|
4546
4675
|
return {
|
|
4547
4676
|
stopping: true,
|
|
4548
|
-
pid: process.pid
|
|
4677
|
+
pid: process.pid,
|
|
4678
|
+
...ctx.listen && { listen: true }
|
|
4549
4679
|
};
|
|
4550
4680
|
},
|
|
4551
4681
|
async "engine.call"(ctx, params) {
|
|
@@ -4573,7 +4703,9 @@ var METHODS = {
|
|
|
4573
4703
|
const target = node(ctx)[method];
|
|
4574
4704
|
if (typeof target !== "function") throw new CliError("not_found", `The engine has no call ${method}`);
|
|
4575
4705
|
try {
|
|
4576
|
-
|
|
4706
|
+
const result = await target.call(node(ctx), args) ?? null;
|
|
4707
|
+
if (method === "removeLink") ctx.calls.forgetChat(str(args ?? {}, "linkId", true));
|
|
4708
|
+
return result;
|
|
4577
4709
|
} catch (error) {
|
|
4578
4710
|
if (error instanceof TypeError && BAD_VALUE.test(error.message)) throw wrong("a parameter of the wrong kind", error.message);
|
|
4579
4711
|
throw error;
|
|
@@ -4755,10 +4887,6 @@ async function connectWithin(ctx, link, ms) {
|
|
|
4755
4887
|
const shown = /^[\w.:-]+$/.test(link.label ?? "") ? link.label : link.id;
|
|
4756
4888
|
throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact did not answer. ${ctx.mode === "one-shot" ? "Try again later, or keep this profile online with `ghostly daemon --detach`: it reconnects by itself" : `It reconnects by itself while this profile is online; ghostly chat wait ${shown} --until live waits for it`}`, { chat: link.id });
|
|
4757
4889
|
}
|
|
4758
|
-
/**
|
|
4759
|
-
* A page of a chat's or a group's history. Without `after` only that page is read from the store (the newest, or those
|
|
4760
|
-
* before `before`), so a long chat's is as quick as a short one's; with `after` the whole history is read and cut.
|
|
4761
|
-
*/
|
|
4762
4890
|
async function saveMark(ctx, params, remove) {
|
|
4763
4891
|
const target = chatOrGroup(ctx, str(params, "chat", true)), messageId = str(params, "message", true);
|
|
4764
4892
|
const result = await node(ctx).saveMessage({
|
|
@@ -4774,28 +4902,29 @@ async function saveMark(ctx, params, remove) {
|
|
|
4774
4902
|
saved: !remove
|
|
4775
4903
|
};
|
|
4776
4904
|
}
|
|
4905
|
+
/**
|
|
4906
|
+
* A page of a chat's or a group's history: only that page is read from the store (the newest, those before `before`,
|
|
4907
|
+
* or the oldest after `after`), so a long chat's is as quick as a short one's.
|
|
4908
|
+
*/
|
|
4777
4909
|
async function historyOf(ctx, chat, params, json = messageJson) {
|
|
4778
|
-
if (params.after !== void 0 && params.after !== null) {
|
|
4779
|
-
const whole = await node(ctx).getMessages(chat), { messages, more } = history(whole, params);
|
|
4780
|
-
const originals = await originalsNow(ctx, chat, messages, whole);
|
|
4781
|
-
return {
|
|
4782
|
-
messages: messages.map((m) => quoteChecked(json(m), m, originals)),
|
|
4783
|
-
more
|
|
4784
|
-
};
|
|
4785
|
-
}
|
|
4786
4910
|
const limit = num(params, "limit", 50, {
|
|
4787
4911
|
min: 1,
|
|
4788
4912
|
max: 1e4,
|
|
4789
4913
|
whole: true
|
|
4790
4914
|
});
|
|
4791
|
-
const
|
|
4792
|
-
|
|
4915
|
+
const bound = (side) => {
|
|
4916
|
+
const value = params[side] ?? void 0;
|
|
4917
|
+
if (value !== void 0 && typeof value !== "number" && typeof value !== "string") throw new CliError("bad_request", `${side} must be a timestamp or a message id`);
|
|
4918
|
+
return value;
|
|
4919
|
+
};
|
|
4920
|
+
const before = bound("before"), after = bound("after");
|
|
4793
4921
|
const page = await node(ctx).messagePage({
|
|
4794
4922
|
linkId: chat,
|
|
4795
4923
|
limit,
|
|
4796
|
-
before
|
|
4924
|
+
before,
|
|
4925
|
+
...after !== void 0 && { after }
|
|
4797
4926
|
}).catch((error) => {
|
|
4798
|
-
throw error instanceof Error && error.message === `No message ${
|
|
4927
|
+
throw error instanceof Error && [before, after].some((id) => error.message === `No message ${id}`) ? new CliError("not_found", error.message) : error;
|
|
4799
4928
|
});
|
|
4800
4929
|
const originals = await originalsNow(ctx, chat, page.messages);
|
|
4801
4930
|
return {
|
|
@@ -4847,31 +4976,6 @@ function quoteChecked(json, message, originals) {
|
|
|
4847
4976
|
}
|
|
4848
4977
|
};
|
|
4849
4978
|
}
|
|
4850
|
-
function history(messages, params) {
|
|
4851
|
-
const limit = num(params, "limit", 50, {
|
|
4852
|
-
min: 1,
|
|
4853
|
-
max: 1e4,
|
|
4854
|
-
whole: true
|
|
4855
|
-
});
|
|
4856
|
-
const before = params.before;
|
|
4857
|
-
const after = params.after;
|
|
4858
|
-
const sorted = messages.slice().sort((a, b) => a.timestamp - b.timestamp);
|
|
4859
|
-
const bound = (value, side) => {
|
|
4860
|
-
if (value === void 0 || value === null) return;
|
|
4861
|
-
if (typeof value === "number") return (m) => side === "before" ? m.timestamp < value : m.timestamp > value;
|
|
4862
|
-
if (typeof value !== "string") throw new CliError("bad_request", `${side} must be a timestamp or a message id`);
|
|
4863
|
-
const index = sorted.findIndex((m) => m.id === value);
|
|
4864
|
-
if (index === -1) throw new CliError("not_found", `No message ${value}`);
|
|
4865
|
-
return (_, at) => side === "before" ? at < index : at > index;
|
|
4866
|
-
};
|
|
4867
|
-
const bounds = [bound(before, "before"), bound(after, "after")].filter((b) => b !== void 0);
|
|
4868
|
-
const list = sorted.filter((m, at) => bounds.every((within) => within(m, at)));
|
|
4869
|
-
const more = after !== void 0 && after !== null ? list.length > limit : list.length > limit;
|
|
4870
|
-
return {
|
|
4871
|
-
messages: after !== void 0 && after !== null ? list.slice(0, limit) : list.slice(-limit),
|
|
4872
|
-
more
|
|
4873
|
-
};
|
|
4874
|
-
}
|
|
4875
4979
|
var API_METHODS = Object.keys(METHODS);
|
|
4876
4980
|
/** Runs one method of the API: one the table lists itself (`constructor`, which every object has, is none). */
|
|
4877
4981
|
async function callApi(ctx, method, params = {}) {
|
|
@@ -4883,4 +4987,4 @@ async function callApi(ctx, method, params = {}) {
|
|
|
4883
4987
|
//#endregion
|
|
4884
4988
|
export { flushCardUpdates as _, hideStateSecrets as a, paymentJson as c, nodeLocalFetch as d, chatJson as f, resumeHolds as g, groupMessageJson as h, groupSendRefused as i, reportAppFrames as l, groupJson as m, SETTABLE as n, mentionsFor as o, chatMessageJson as p, callApi as r, redactSettings as s, API_METHODS as t, servedApps as u };
|
|
4885
4989
|
|
|
4886
|
-
//# sourceMappingURL=api-
|
|
4990
|
+
//# sourceMappingURL=api-I_KbuXHa.js.map
|