Skip to content

Commit

Permalink
Publish API bonjour service as Planet or Croptop on 8086 (the new def…
Browse files Browse the repository at this point in the history
…ault port)
  • Loading branch information
livid committed Dec 15, 2023
1 parent 649935e commit 786acdb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
9 changes: 7 additions & 2 deletions Planet/API/PlanetAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ class PlanetAPIService: NSObject, NetServiceDelegate {
}
}

private func setupService(_ port: Int = 9191) {
private func setupService(_ port: Int = 8086) {
// Initialize NetService object with domain, service type, name, and port.
var serviceName = "Planet API Server"
var serviceName: String
if Bundle.main.executableURL?.lastPathComponent == "Croptop" {
serviceName = "Croptop"
} else {
serviceName = "Planet"
}
if let hostname = getHostname() {
serviceName = serviceName + " on \(hostname)"
}
Expand Down
2 changes: 1 addition & 1 deletion Planet/Entities/MyArticleModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MyArticleModel: ArticleModel, Codable {
if apiEnabled {
let apiPort =
UserDefaults
.standard.string(forKey: String.settingsAPIPort) ?? "9191"
.standard.string(forKey: String.settingsAPIPort) ?? "8086"
return URL(
string:
"http://127.0.0.1:\(apiPort)/v0/planets/my/\(planet.id.uuidString)/public/\(id.uuidString)/index.html"
Expand Down
2 changes: 1 addition & 1 deletion Planet/Entities/MyPlanetModel+Aggregate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension MyPlanetModel {
article.delete()
}
}
tags = consolidateTags()
self.tags = self.consolidateTags()
try? save()
try? await savePublic()
Task { @MainActor in
Expand Down
10 changes: 8 additions & 2 deletions Planet/PlanetAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ actor PlanetAPIHelper {
server = HttpServer()
let defaults = UserDefaults.standard
if defaults.value(forKey: .settingsAPIPort) == nil {
defaults.set("9191", forKey: .settingsAPIPort)
defaults.set("8086", forKey: .settingsAPIPort)
}
if defaults.value(forKey: .settingsAPIEnabled) == nil {
defaults.set(false, forKey: .settingsAPIEnabled)
Expand Down Expand Up @@ -121,7 +121,13 @@ actor PlanetAPIHelper {
}
if let portString = UserDefaults.standard.string(forKey: .settingsAPIPort), let port = Int(portString) {
try server.start(in_port_t(port), forceIPv4: false, priority: .utility)
debugPrint("Planet API server started: port=\(portString)")
var serviceName: String
if Bundle.main.executableURL?.lastPathComponent == "Croptop" {
serviceName = "Croptop"
} else {
serviceName = "Planet"
}
debugPrint("\(serviceName) API server started: port=\(portString)")

if self.bonjourService == nil {
self.bonjourService = PlanetAPIService(port)
Expand Down
10 changes: 5 additions & 5 deletions Planet/Settings/PlanetSettingsAPIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import SwiftUI


struct PlanetSettingsAPIView: View {

@AppStorage(String.settingsAPIEnabled) private var apiEnabled: Bool =
UserDefaults.standard.bool(forKey: String.settingsAPIEnabled)
@AppStorage(String.settingsAPIUsesPasscode) private var apiUsesPasscode: Bool = UserDefaults.standard.bool(forKey: String.settingsAPIUsesPasscode)
@AppStorage(String.settingsAPIUsername) private var apiUsername: String = UserDefaults.standard.string(forKey: String.settingsAPIUsername) ?? "Planet"
@AppStorage(String.settingsAPIPort) private var apiPort: String = UserDefaults
.standard.string(forKey: String.settingsAPIPort) ?? "9191"
.standard.string(forKey: String.settingsAPIPort) ?? "8086"

@State private var apiPasscode: String = ""
@State private var isShowingPasscode: Bool = false

Expand Down Expand Up @@ -111,7 +111,7 @@ struct PlanetSettingsAPIView: View {
}
}
}

private func updatePasscode(_ passcode: String) {
guard passcode != "" else { return }
do {
Expand All @@ -120,7 +120,7 @@ struct PlanetSettingsAPIView: View {
debugPrint("failed to save passcode to keychain: \(error)")
}
}

private func reloadAPIServer() {
Task {
do {
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 1824
CURRENT_PROJECT_VERSION = 1828

0 comments on commit 786acdb

Please sign in to comment.