Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/StreamAttachments/CDNClient/CDNClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public class StreamCDNClient: CDNClient, @unchecked Sendable {
return
}

let data = multipartFormData.getMultipartFormData()
urlRequest.addValue("multipart/form-data; boundary=\(MultipartFormData.boundary)", forHTTPHeaderField: "Content-Type")
let data = multipartFormData.encode()
urlRequest.addValue("multipart/form-data; boundary=\(multipartFormData.boundary)", forHTTPHeaderField: "Content-Type")
urlRequest.addValue("stream-feeds-swift-v0.0.1", forHTTPHeaderField: "X-Stream-Client") // TODO: fix this.
urlRequest.httpBody = data

Expand Down
45 changes: 0 additions & 45 deletions Sources/StreamAttachments/CDNClient/MultipartFormData.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/StreamAttachments/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>0.9.0</string>
<string>0.10.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamCore/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>0.9.0</string>
<string>0.10.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
14 changes: 12 additions & 2 deletions Sources/StreamCore/Logger/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright © 2026 Stream.io Inc. All rights reserved.
//

import Combine
import Foundation

public var log: Logger {
Expand Down Expand Up @@ -226,7 +227,7 @@
}
}

private static let _state = AllocatedUnfairLock<State>(State())

Check warning on line 230 in Sources/StreamCore/Logger/Logger.swift

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this constant "_state" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-core-swift&issues=AZ-SfPMXJGa7AJGVxgQf&open=AZ-SfPMXJGa7AJGVxgQf&pullRequest=71

/// Identifier for the logger. Defaults to empty.
public static var identifier: String {
Expand All @@ -251,9 +252,17 @@
$0.level = newValue
$0.invalidateLogger()
}
Self.levelSubject.send(newValue)
}
}


private nonisolated(unsafe) static let levelSubject = CurrentValueSubject<LogLevel, Never>(_state.value.level)

/// Publishes the current log level and all subsequent changes.
public static var levelPublisher: AnyPublisher<LogLevel, Never> {
levelSubject.eraseToAnyPublisher()
}

/// Date formatter for the logger. Defaults to ISO8601
public static var dateFormatter: DateFormatter {
get {
Expand Down Expand Up @@ -432,11 +441,12 @@

static func reset() {
_state.withLock { $0 = State() }
levelSubject.send(level)
}
}

/// Entity used for logging messages.
open class Logger {
open class Logger: @unchecked Sendable {
/// Identifier of the Logger. Will be visible if a destination has `showIdentifiers` enabled.
public let identifier: String

Expand Down
12 changes: 9 additions & 3 deletions Sources/StreamCore/Utils/DisposableBag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public final class DisposableBag: @unchecked Sendable {
}
}

func remove(_ key: String) {
func remove(_ key: String, cancel: Bool) {
queue.sync {
storage[key]?.cancel()
if cancel {
storage[key]?.cancel()
}
storage[key] = nil
}
}
Expand All @@ -53,14 +55,18 @@ public final class DisposableBag: @unchecked Sendable {
}

public func remove(_ key: String) {
storage.remove(key)
storage.remove(key, cancel: true)
}

public func removeAll() {
storage.removeAll()
}

public var isEmpty: Bool { storage.isEmpty }

public func completed(_ key: String) {
storage.remove(key, cancel: false)
}
}

extension AnyCancellable {
Expand Down
53 changes: 53 additions & 0 deletions Sources/StreamCore/Utils/MultipartFormData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Copyright © 2026 Stream.io Inc. All rights reserved.
//

import Foundation

/// Encodes a file as multipart form data.
public struct MultipartFormData: Sendable {
private static let crlf = "\r\n"

@usableFromInline static let defaultBoundary: String = String(
format: "chat-%08x%08x",
UInt32.random(in: 0...UInt32.max),
UInt32.random(in: 0...UInt32.max)
)

private let data: Data
private let fileName: String
private let mimeType: String?

/// The boundary used to separate multipart form data parts.
public let boundary: String

/// Creates multipart form data for a file.
public init(_ data: Data, fileName: String, mimeType: String? = nil, boundary: String = Self.defaultBoundary) {
self.data = data
self.fileName = fileName
self.mimeType = mimeType
self.boundary = boundary
}

/// Encodes the file as a multipart form data body.
public func encode() -> Data {
var data = "--\(boundary)\(Self.crlf)".data(using: .utf8, allowLossyConversion: false)!
data.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(fileName)\"\(Self.crlf)")

if let mimeType {
data.append("Content-Type: \(mimeType)\(Self.crlf)")
}

data.append(Self.crlf)
data.append(self.data)
data.append("\(Self.crlf)--\(boundary)--\(Self.crlf)")

return data
}
}

private extension Data {
mutating func append(_ string: String, encoding: String.Encoding = .utf8) {
append(string.data(using: encoding, allowLossyConversion: false)!)
}
}
2 changes: 1 addition & 1 deletion Sources/StreamCore/Utils/SystemEnvironment+Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import Foundation

enum SystemEnvironment {
/// A Stream Core version.
public static let version: String = "0.9.0"
public static let version: String = "0.10.0"
}
Loading
Loading