Initial scaffold — NASBackup iOS app
Full project scaffold: XcodeGen project.yml, Core models/protocols/errors,
SMBService (kishikawakatsumi/SMBClient), SFTPService (Citadel 0.9.2),
PhotoLibraryService, LANMonitor, BackupEngine, BackgroundTaskManager,
all feature UIs (Login, Connect, Browse, Backup, History, Settings),
Shared components and theme. Builds clean with zero errors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 17:05:04 +03:00
|
|
|
import Foundation
|
|
|
|
|
import NIO
|
|
|
|
|
import Citadel
|
|
|
|
|
|
|
|
|
|
final class SFTPService: NASTransferProtocol {
|
|
|
|
|
private var client: SSHClient?
|
|
|
|
|
private var sftp: SFTPClient?
|
|
|
|
|
private(set) var isConnected: Bool = false
|
|
|
|
|
|
|
|
|
|
func connect(to host: String, port: Int, username: String, password: String) async throws {
|
|
|
|
|
do {
|
|
|
|
|
let c = try await SSHClient.connect(
|
|
|
|
|
host: host,
|
|
|
|
|
port: port,
|
|
|
|
|
authenticationMethod: .passwordBased(username: username, password: password),
|
|
|
|
|
hostKeyValidator: .acceptAnything(),
|
|
|
|
|
reconnect: .never
|
|
|
|
|
)
|
|
|
|
|
let sftpClient = try await c.openSFTP()
|
|
|
|
|
self.client = c
|
|
|
|
|
self.sftp = sftpClient
|
|
|
|
|
self.isConnected = true
|
|
|
|
|
} catch {
|
|
|
|
|
throw BackupError.connectionFailed(host)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func disconnect() {
|
|
|
|
|
Task {
|
|
|
|
|
try? await sftp?.close()
|
|
|
|
|
client = nil
|
|
|
|
|
}
|
|
|
|
|
sftp = nil
|
|
|
|
|
isConnected = false
|
|
|
|
|
}
|
|
|
|
|
|
fix: SMB share enumeration, BrowseView polish, sign out, Login branding
- Fix "Bad Network Name": BrowseView at root "/" for SMB now calls
listShares() instead of listDirectory with empty share name.
SMBClient.listShares() filters IPC/admin/hidden ($) shares.
- Add listShares() to NASTransferProtocol; implement in SMB (filters
ipc/special/$-suffix) and SFTP (returns []).
- BrowseView: premium error state (wifi.exclamationmark icon + Retry
button with ScaleButtonStyle), empty state, safeAreaInset bottom bar
replacing toolbar bottomBar (shows current path chip + compact Select
button), proper disabled state for root selection on SMB.
- FolderRow: replace hardcoded .white with AppTheme.inkInverse for dark
mode correctness; use folder.fill icon; ScaleButtonStyle for tap feedback.
- LoginView: larger logo (80pt), bolder "Kisani" wordmark (32pt bold),
tagline, staggered spring entrance animations (0.08-0.36s delay).
- SettingsView: Sign Out button in ACCOUNT section with
confirmationDialog (destructive, clears connection + resets session).
- ConnectionStore: signOut() resets isSessionActive, onboardingPhotoShown,
and clears savedConnection (triggers Keychain delete).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 16:41:16 +03:00
|
|
|
func listShares() async throws -> [String] { [] }
|
|
|
|
|
|
Initial scaffold — NASBackup iOS app
Full project scaffold: XcodeGen project.yml, Core models/protocols/errors,
SMBService (kishikawakatsumi/SMBClient), SFTPService (Citadel 0.9.2),
PhotoLibraryService, LANMonitor, BackupEngine, BackgroundTaskManager,
all feature UIs (Login, Connect, Browse, Backup, History, Settings),
Shared components and theme. Builds clean with zero errors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 17:05:04 +03:00
|
|
|
func listDirectory(at path: String) async throws -> [NASItem] {
|
|
|
|
|
guard let sftp else { throw BackupError.connectionFailed("Not connected") }
|
|
|
|
|
do {
|
|
|
|
|
let batches = try await sftp.listDirectory(atPath: path)
|
|
|
|
|
// listDirectory returns [SFTPMessage.Name]; each Name contains multiple SFTPPathComponent
|
|
|
|
|
let components = batches.flatMap { $0.components }
|
|
|
|
|
return components.compactMap { component -> NASItem? in
|
|
|
|
|
guard component.filename != "." && component.filename != ".." else { return nil }
|
|
|
|
|
let fullPath = path.hasSuffix("/")
|
|
|
|
|
? "\(path)\(component.filename)"
|
|
|
|
|
: "\(path)/\(component.filename)"
|
|
|
|
|
let isDir = component.attributes.permissions.map { ($0 & 0o170000) == 0o040000 } ?? false
|
|
|
|
|
return NASItem(
|
|
|
|
|
name: component.filename,
|
|
|
|
|
path: fullPath,
|
|
|
|
|
isDirectory: isDir,
|
|
|
|
|
size: Int64(component.attributes.size ?? 0),
|
|
|
|
|
modifiedDate: nil
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
throw BackupError.directoryListFailed(path)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createDirectory(at path: String) async throws {
|
|
|
|
|
guard let sftp else { throw BackupError.connectionFailed("Not connected") }
|
|
|
|
|
do {
|
|
|
|
|
try await sftp.createDirectory(atPath: path)
|
|
|
|
|
} catch {
|
|
|
|
|
throw BackupError.directoryCreateFailed(path)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fileExists(at remotePath: String) async throws -> Bool {
|
|
|
|
|
guard let sftp else { throw BackupError.connectionFailed("Not connected") }
|
|
|
|
|
do {
|
|
|
|
|
_ = try await sftp.getAttributes(at: remotePath)
|
|
|
|
|
return true
|
|
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: Kisani UI overhaul — brand identity, gallery, visual polish
- Rename app to Kisani (CFBundleDisplayName, xcodeproj → Kisani.xcodeproj)
- BackupView: kisani. wordmark + SwiftUI-drawn server logo mark (no asset,
adaptive ink/bg), 206pt progress ring with active-state glow, 4-page
swipeable ring (progress/pending/failed/uploaded), 4-metric stats strip,
friendly NAS card (Home Server label), hamburger → AppMenuView sheet
- GalleryView: new NAS + local photo grid with source picker chip, 3-col
lazy grid, ThumbnailCache, sync-status dots (green = backed up)
- MainTabView: Browse tab → Gallery tab; tab bar uses ultraThinMaterial
blur background (systemGray3 icons, 9.5pt labels)
- All app icon sizes regenerated from 1024pt source via sips
- LANMonitor: nasReachable Bool?, checkNASReachability(host:port:) TCP ping
- project.yml: photo library usage description updated to Kisani branding
Co-Authored-By: Kutesir <kutesir@provoc.ug>
Co-Authored-By: Sentry <sentry@provoc.ug>
2026-05-17 11:17:13 +03:00
|
|
|
func downloadData(at remotePath: String) async throws -> Data {
|
|
|
|
|
guard let sftp else { throw BackupError.connectionFailed("Not connected") }
|
|
|
|
|
return try await sftp.withFile(filePath: remotePath, flags: [.read]) { file in
|
|
|
|
|
let buf = try await file.readAll()
|
|
|
|
|
return Data(buf.readableBytesView)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Initial scaffold — NASBackup iOS app
Full project scaffold: XcodeGen project.yml, Core models/protocols/errors,
SMBService (kishikawakatsumi/SMBClient), SFTPService (Citadel 0.9.2),
PhotoLibraryService, LANMonitor, BackupEngine, BackgroundTaskManager,
all feature UIs (Login, Connect, Browse, Backup, History, Settings),
Shared components and theme. Builds clean with zero errors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 17:05:04 +03:00
|
|
|
func upload(localURL: URL, remotePath: String, progress: @escaping (Int64, Int64) -> Void) async throws {
|
|
|
|
|
guard let sftp else { throw BackupError.connectionFailed("Not connected") }
|
|
|
|
|
let filename = localURL.lastPathComponent
|
|
|
|
|
do {
|
|
|
|
|
let data = try Data(contentsOf: localURL)
|
|
|
|
|
let total = Int64(data.count)
|
|
|
|
|
progress(0, total)
|
|
|
|
|
try await sftp.withFile(
|
|
|
|
|
filePath: remotePath,
|
|
|
|
|
flags: [.write, .create, .truncate]
|
|
|
|
|
) { file in
|
2026-05-16 10:55:54 +03:00
|
|
|
let buffer = ByteBuffer(data: data)
|
Initial scaffold — NASBackup iOS app
Full project scaffold: XcodeGen project.yml, Core models/protocols/errors,
SMBService (kishikawakatsumi/SMBClient), SFTPService (Citadel 0.9.2),
PhotoLibraryService, LANMonitor, BackupEngine, BackgroundTaskManager,
all feature UIs (Login, Connect, Browse, Backup, History, Settings),
Shared components and theme. Builds clean with zero errors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 17:05:04 +03:00
|
|
|
try await file.write(buffer, at: 0)
|
|
|
|
|
}
|
|
|
|
|
progress(total, total)
|
|
|
|
|
} catch {
|
|
|
|
|
throw BackupError.uploadFailed(filename, underlying: error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|