mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
• Rolled back the change to stop replicating the current user profile into the database (and the various attempted fixes that came as a result) • Added env variable handling for "shortenFileTTL" • Made some improvements to the libSession build script and error handling • Fixed an issue where the reupload job would always extend to the max TTL regardless of the "shorten TTL" dev setting • Fixed an issue where setting the profile name before setting the display pic could result in the old display pic being used (even when setting to the same value - bug in libSession needs to be fixed to handle this case) • Fixed an issue where profile updates coming from libSession wouldn't be saved correctly in some cases
90 lines
3.1 KiB
Swift
90 lines
3.1 KiB
Swift
// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
|
|
//
|
|
// stringlint:disable
|
|
|
|
import Foundation
|
|
import SessionUtilitiesKit
|
|
|
|
private typealias FileServer = Network.FileServer
|
|
private typealias Endpoint = Network.FileServer.Endpoint
|
|
|
|
public extension Network.FileServer {
|
|
static func preparedUpload(
|
|
data: Data,
|
|
requestAndPathBuildTimeout: TimeInterval? = nil,
|
|
using dependencies: Dependencies
|
|
) throws -> Network.PreparedRequest<FileUploadResponse> {
|
|
var headers: [HTTPHeader: String] = [:]
|
|
|
|
if dependencies[feature: .shortenFileTTL] {
|
|
headers = [.fileCustomTTL: "60"]
|
|
}
|
|
|
|
return try Network.PreparedRequest(
|
|
request: Request<Data, Endpoint>(
|
|
endpoint: .file,
|
|
destination: .serverUpload(
|
|
server: FileServer.server(using: dependencies),
|
|
headers: headers,
|
|
x25519PublicKey: FileServer.x25519PublicKey(using: dependencies),
|
|
fileName: nil
|
|
),
|
|
body: data
|
|
),
|
|
responseType: FileUploadResponse.self,
|
|
requestTimeout: Network.fileUploadTimeout,
|
|
requestAndPathBuildTimeout: requestAndPathBuildTimeout,
|
|
using: dependencies
|
|
)
|
|
}
|
|
|
|
static func preparedDownload(
|
|
url: URL,
|
|
using dependencies: Dependencies
|
|
) throws -> Network.PreparedRequest<Data> {
|
|
let strippedUrl: URL = try url.strippingQueryAndFragment ?? { throw NetworkError.invalidURL }()
|
|
|
|
return try Network.PreparedRequest(
|
|
request: Request<NoBody, Endpoint>(
|
|
endpoint: .directUrl(strippedUrl),
|
|
destination: .serverDownload(
|
|
url: strippedUrl,
|
|
x25519PublicKey: FileServer.x25519PublicKey(for: url, using: dependencies),
|
|
fileName: nil
|
|
)
|
|
),
|
|
responseType: Data.self,
|
|
requestTimeout: Network.fileDownloadTimeout,
|
|
using: dependencies
|
|
)
|
|
}
|
|
|
|
static func preparedExtend(
|
|
url: URL,
|
|
customTtl: TimeInterval?,
|
|
using dependencies: Dependencies
|
|
) throws -> Network.PreparedRequest<ExtendExpirationResponse> {
|
|
let strippedUrl: URL = try url.strippingQueryAndFragment ?? { throw NetworkError.invalidURL }()
|
|
|
|
var headers: [HTTPHeader: String] = [:]
|
|
|
|
if let ttl: TimeInterval = customTtl {
|
|
headers = [.fileCustomTTL: "\(Int(floor(ttl)))"]
|
|
}
|
|
|
|
return try Network.PreparedRequest(
|
|
request: Request<NoBody, Endpoint>(
|
|
endpoint: .extendUrl(strippedUrl),
|
|
destination: .server(
|
|
method: .post,
|
|
url: strippedUrl,
|
|
headers: headers,
|
|
x25519PublicKey: FileServer.x25519PublicKey(for: url, using: dependencies)
|
|
)
|
|
),
|
|
responseType: ExtendExpirationResponse.self,
|
|
using: dependencies
|
|
)
|
|
}
|
|
}
|