mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 12:01:13 +00:00
Some hosts (e.g. NAS/Synology root) expose SSH but not the SFTP subsystem. Add hybrid SCP mode: shell-backed list/manage and OpenSSH scp -t/-f transfers behind the existing SFTP UI, transfer queue, and sftp.* AI/CLI/MCP tools. Hosts can choose Auto (SFTP then SCP), SFTP only, or force SCP. Include unit tests and optional env-gated real OpenSSH integration tests.
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import type { SftpFileEntry, SftpFilenameEncoding } from "../../../domain/models";
|
|
|
|
export interface SharedRemoteHostCacheEntry {
|
|
path: string;
|
|
homeDir: string;
|
|
files: SftpFileEntry[];
|
|
filenameEncoding: SftpFilenameEncoding;
|
|
updatedAt: number;
|
|
}
|
|
|
|
const SHARED_REMOTE_HOST_CACHE_TTL_MS = 60_000;
|
|
|
|
const sharedRemoteHostCache = new Map<string, SharedRemoteHostCacheEntry>();
|
|
|
|
/**
|
|
* Build a cache key that includes connection details so that the same host ID
|
|
* with different session-time overrides (port, protocol) uses separate entries.
|
|
*/
|
|
export const buildCacheKey = (
|
|
hostId: string,
|
|
hostname?: string,
|
|
port?: number,
|
|
protocol?: string,
|
|
sftpSudo?: boolean,
|
|
username?: string,
|
|
sftpFileProtocol?: string,
|
|
): string => {
|
|
const fileProto = sftpFileProtocol && sftpFileProtocol !== "auto" ? sftpFileProtocol : "";
|
|
return `${hostId}:${hostname ?? ''}:${port ?? ''}:${protocol ?? ''}:${sftpSudo ? 'sudo' : ''}:${username ?? ''}:${fileProto}`;
|
|
};
|
|
|
|
export const getSharedRemoteHostCache = (
|
|
cacheKey: string,
|
|
): SharedRemoteHostCacheEntry | null => {
|
|
const entry = sharedRemoteHostCache.get(cacheKey);
|
|
if (!entry) return null;
|
|
|
|
if (Date.now() - entry.updatedAt > SHARED_REMOTE_HOST_CACHE_TTL_MS) {
|
|
sharedRemoteHostCache.delete(cacheKey);
|
|
return null;
|
|
}
|
|
|
|
return entry;
|
|
};
|
|
|
|
export const setSharedRemoteHostCache = (
|
|
cacheKey: string,
|
|
entry: Omit<SharedRemoteHostCacheEntry, "updatedAt">,
|
|
): void => {
|
|
sharedRemoteHostCache.set(cacheKey, {
|
|
...entry,
|
|
updatedAt: Date.now(),
|
|
});
|
|
};
|