@elefunc/send 0.1.30 → 0.1.31
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/package.json +1 -1
- package/src/core/session.ts +17 -6
- package/src/tui/app.ts +24 -3
package/package.json
CHANGED
package/src/core/session.ts
CHANGED
|
@@ -103,6 +103,7 @@ interface IncomingDiskState {
|
|
|
103
103
|
offset: number
|
|
104
104
|
error: string
|
|
105
105
|
closed: boolean
|
|
106
|
+
overwrite: boolean
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
export interface PeerSnapshot {
|
|
@@ -445,7 +446,7 @@ export class SendSession {
|
|
|
445
446
|
|
|
446
447
|
private autoAcceptIncoming: boolean
|
|
447
448
|
private autoSaveIncoming: boolean
|
|
448
|
-
private
|
|
449
|
+
private overwriteIncoming: boolean
|
|
449
450
|
private readonly reconnectSocket: boolean
|
|
450
451
|
private iceServers: RTCIceServer[]
|
|
451
452
|
private extraTurnServers: RTCIceServer[]
|
|
@@ -683,6 +684,14 @@ export class SendSession {
|
|
|
683
684
|
return saved
|
|
684
685
|
}
|
|
685
686
|
|
|
687
|
+
setOverwriteIncoming(enabled: boolean) {
|
|
688
|
+
const next = !!enabled
|
|
689
|
+
if (next === this.overwriteIncoming) return false
|
|
690
|
+
this.overwriteIncoming = next
|
|
691
|
+
this.notify()
|
|
692
|
+
return true
|
|
693
|
+
}
|
|
694
|
+
|
|
686
695
|
cancelPendingOffers() {
|
|
687
696
|
let cancelled = 0
|
|
688
697
|
for (const transfer of this.transfers.values()) {
|
|
@@ -848,8 +857,9 @@ export class SendSession {
|
|
|
848
857
|
}
|
|
849
858
|
|
|
850
859
|
private async createIncomingDiskState(fileName: string): Promise<IncomingDiskState> {
|
|
851
|
-
const
|
|
852
|
-
|
|
860
|
+
const overwrite = this.overwriteIncoming
|
|
861
|
+
const finalPath = await incomingOutputPath(this.saveDir, fileName || "download", overwrite, this.reservedSavePaths)
|
|
862
|
+
if (!overwrite) this.reservedSavePaths.add(finalPath)
|
|
853
863
|
for (let attempt = 0; ; attempt += 1) {
|
|
854
864
|
const tempPath = `${finalPath}.part.${uid(6)}${attempt ? `.${attempt}` : ""}`
|
|
855
865
|
try {
|
|
@@ -862,10 +872,11 @@ export class SendSession {
|
|
|
862
872
|
offset: 0,
|
|
863
873
|
error: "",
|
|
864
874
|
closed: false,
|
|
875
|
+
overwrite,
|
|
865
876
|
}
|
|
866
877
|
} catch (error) {
|
|
867
878
|
if ((error as NodeJS.ErrnoException | undefined)?.code === "EEXIST") continue
|
|
868
|
-
if (!
|
|
879
|
+
if (!overwrite) this.reservedSavePaths.delete(finalPath)
|
|
869
880
|
throw error
|
|
870
881
|
}
|
|
871
882
|
}
|
|
@@ -935,12 +946,12 @@ export class SendSession {
|
|
|
935
946
|
disk.closed = true
|
|
936
947
|
await disk.handle.close()
|
|
937
948
|
}
|
|
938
|
-
if (!
|
|
949
|
+
if (!disk.overwrite && await pathExists(finalPath)) {
|
|
939
950
|
this.reservedSavePaths.delete(finalPath)
|
|
940
951
|
finalPath = await uniqueOutputPath(this.saveDir, transfer.name || "download", this.reservedSavePaths)
|
|
941
952
|
this.reservedSavePaths.add(finalPath)
|
|
942
953
|
}
|
|
943
|
-
if (
|
|
954
|
+
if (disk.overwrite) await replaceOutputPath(disk.tempPath, finalPath)
|
|
944
955
|
else await rename(disk.tempPath, finalPath)
|
|
945
956
|
transfer.savedPath = finalPath
|
|
946
957
|
transfer.savedAt ||= Date.now()
|
package/src/tui/app.ts
CHANGED
|
@@ -117,6 +117,7 @@ export interface TuiActions {
|
|
|
117
117
|
toggleAutoOffer: TuiAction
|
|
118
118
|
toggleAutoAccept: TuiAction
|
|
119
119
|
toggleAutoSave: TuiAction
|
|
120
|
+
toggleOverwrite: TuiAction
|
|
120
121
|
setDraftInput: (value: string, cursor?: number) => void
|
|
121
122
|
addDrafts: TuiAction
|
|
122
123
|
removeDraft: (draftId: string) => void
|
|
@@ -151,7 +152,7 @@ const ABOUT_BULLETS = [
|
|
|
151
152
|
"• Join a room, see who is there, and filter or select exactly which peers to target before offering files.",
|
|
152
153
|
"• File data does not travel through the signaling service; Send uses lightweight signaling to discover peers and negotiate WebRTC, then transfers directly peer-to-peer when possible, with TURN relay when needed.",
|
|
153
154
|
"• Incoming transfers can be auto-accepted and auto-saved, and same-name files can either stay as numbered copies or overwrite the original when that mode is enabled.",
|
|
154
|
-
"• The CLI streams incoming saves straight to disk in the current save directory, with overwrite available through the CLI flag.",
|
|
155
|
+
"• The CLI streams incoming saves straight to disk in the current save directory, with overwrite available through the CLI flag and the TUI Ctrl+O shortcut.",
|
|
155
156
|
"• Other features include copyable web and CLI invites, rendered-peer filtering and selection, TURN sharing, and live connection insight like signaling state, RTT, data state, and path labels.",
|
|
156
157
|
] as const
|
|
157
158
|
const TRANSFER_DIRECTION_ARROW = {
|
|
@@ -293,6 +294,7 @@ export const createNoopTuiActions = (): TuiActions => ({
|
|
|
293
294
|
toggleAutoOffer: noop,
|
|
294
295
|
toggleAutoAccept: noop,
|
|
295
296
|
toggleAutoSave: noop,
|
|
297
|
+
toggleOverwrite: noop,
|
|
296
298
|
setDraftInput: noop,
|
|
297
299
|
addDrafts: noop,
|
|
298
300
|
removeDraft: noop,
|
|
@@ -1261,8 +1263,12 @@ const renderEventsCard = (state: TuiState, actions: TuiActions) => denseSection(
|
|
|
1261
1263
|
]),
|
|
1262
1264
|
])
|
|
1263
1265
|
|
|
1266
|
+
const footerKeycapWidth = (keycap: string) => keycap.length + 2
|
|
1267
|
+
|
|
1264
1268
|
const renderFooterHint = (id: string, keycap: string, label: string) => ui.row({ id, gap: 0, items: "center" }, [
|
|
1265
|
-
ui.
|
|
1269
|
+
ui.box({ id: `${id}-keycap`, width: footerKeycapWidth(keycap), border: "none" }, [
|
|
1270
|
+
ui.kbd(keycap),
|
|
1271
|
+
]),
|
|
1266
1272
|
ui.text(` ${label}`, { style: { dim: true } }),
|
|
1267
1273
|
])
|
|
1268
1274
|
|
|
@@ -1273,7 +1279,7 @@ const renderFooter = (state: TuiState) => ui.statusBar({
|
|
|
1273
1279
|
ui.toolbar({ id: "footer-hints", gap: 3 }, [
|
|
1274
1280
|
renderFooterHint("footer-hint-tab", "tab", "focus/accept"),
|
|
1275
1281
|
renderFooterHint("footer-hint-enter", "enter", "accept/add"),
|
|
1276
|
-
renderFooterHint("footer-hint-
|
|
1282
|
+
renderFooterHint("footer-hint-ctrl-o", "ctrl+o", "overwrite"),
|
|
1277
1283
|
renderFooterHint("footer-hint-ctrlc", "ctrl+c", "quit"),
|
|
1278
1284
|
]),
|
|
1279
1285
|
],
|
|
@@ -1822,6 +1828,15 @@ export const startTui = async (initialConfig: SessionConfig, launchOptions: TuiL
|
|
|
1822
1828
|
error => commit(current => withNotice(current, { text: `${error}`, variant: "error" })),
|
|
1823
1829
|
)
|
|
1824
1830
|
},
|
|
1831
|
+
toggleOverwrite: () => {
|
|
1832
|
+
const next = !state.overwriteIncoming
|
|
1833
|
+
state.session.setOverwriteIncoming(next)
|
|
1834
|
+
commit(current => withNotice({
|
|
1835
|
+
...current,
|
|
1836
|
+
overwriteIncoming: next,
|
|
1837
|
+
sessionSeed: { ...current.sessionSeed, overwriteIncoming: next },
|
|
1838
|
+
}, { text: next ? "Overwrite on." : "Overwrite off.", variant: next ? "success" : "warning" }))
|
|
1839
|
+
},
|
|
1825
1840
|
setDraftInput: (value, cursor) => updateDraftInput(value, cursor),
|
|
1826
1841
|
addDrafts,
|
|
1827
1842
|
removeDraft: draftId => commit(current => withNotice({ ...current, drafts: current.drafts.filter(draft => draft.id !== draftId) }, { text: "Draft removed.", variant: "warning" })),
|
|
@@ -1971,6 +1986,12 @@ export const startTui = async (initialConfig: SessionConfig, launchOptions: TuiL
|
|
|
1971
1986
|
commit(current => ({ ...current, filePreview: moveFilePreviewSelection(current.filePreview, 1) }))
|
|
1972
1987
|
},
|
|
1973
1988
|
},
|
|
1989
|
+
"ctrl+o": {
|
|
1990
|
+
description: "Toggle overwrite mode",
|
|
1991
|
+
handler: () => {
|
|
1992
|
+
actions.toggleOverwrite()
|
|
1993
|
+
},
|
|
1994
|
+
},
|
|
1974
1995
|
enter: {
|
|
1975
1996
|
description: "Commit focused input",
|
|
1976
1997
|
when: ctx => ctx.focusedId === ROOM_INPUT_ID || ctx.focusedId === NAME_INPUT_ID || ctx.focusedId === DRAFT_INPUT_ID,
|