2021-01-28 09:10:30 +01:00
|
|
|
//
|
|
|
|
// APIService.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/1/27.
|
|
|
|
//
|
|
|
|
|
2022-05-17 16:09:43 +02:00
|
|
|
import UIKit
|
2021-01-28 09:10:30 +01:00
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import MastodonSDK
|
|
|
|
import AlamofireImage
|
2022-09-30 13:28:09 +02:00
|
|
|
// import AlamofireNetworkActivityIndicator
|
2021-01-28 09:10:30 +01:00
|
|
|
|
2022-09-30 13:28:09 +02:00
|
|
|
public final class APIService {
|
|
|
|
|
|
|
|
public static let callbackURLScheme = "mastodon"
|
|
|
|
public static let oauthCallbackURL = "mastodon://joinmastodon.org/oauth"
|
2021-01-28 09:10:30 +01:00
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
// internal
|
|
|
|
let session: URLSession
|
|
|
|
|
|
|
|
// input
|
2022-10-31 13:41:19 +01:00
|
|
|
public let backgroundManagedObjectContext: NSManagedObjectContext
|
2021-01-28 09:10:30 +01:00
|
|
|
|
2021-02-03 09:01:08 +01:00
|
|
|
// output
|
2022-10-08 07:43:06 +02:00
|
|
|
public let error = PassthroughSubject<APIError, Never>()
|
2021-01-28 09:10:30 +01:00
|
|
|
|
2022-09-30 13:28:09 +02:00
|
|
|
public init(backgroundManagedObjectContext: NSManagedObjectContext) {
|
2021-01-28 09:10:30 +01:00
|
|
|
self.backgroundManagedObjectContext = backgroundManagedObjectContext
|
2024-03-19 16:16:42 +01:00
|
|
|
|
|
|
|
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
|
|
|
|
let configuration = URLSessionConfiguration.default
|
|
|
|
configuration.httpAdditionalHeaders = ["User-Agent" : "mastodon-ios/" + appVersion]
|
|
|
|
self.session = URLSession(configuration: configuration)
|
|
|
|
|
2021-01-28 09:10:30 +01:00
|
|
|
// setup cache. 10MB RAM + 50MB Disk
|
|
|
|
URLCache.shared = URLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 50 * 1024 * 1024, diskPath: nil)
|
|
|
|
|
|
|
|
// enable network activity manager for AlamofireImage
|
2022-09-30 13:28:09 +02:00
|
|
|
// NetworkActivityIndicatorManager.shared.isEnabled = true
|
|
|
|
// NetworkActivityIndicatorManager.shared.startDelay = 0.2
|
|
|
|
// NetworkActivityIndicatorManager.shared.completionDelay = 0.5
|
2022-05-17 16:09:43 +02:00
|
|
|
|
|
|
|
UIImageView.af.sharedImageDownloader = ImageDownloader(downloadPrioritization: .lifo)
|
2021-01-28 09:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-18 05:49:24 +01:00
|
|
|
extension APIService {
|
2021-04-01 08:39:15 +02:00
|
|
|
public static let onceRequestStatusMaxCount = 100
|
2021-02-18 05:49:24 +01:00
|
|
|
public static let onceRequestUserMaxCount = 100
|
2021-04-29 09:51:52 +02:00
|
|
|
public static let onceRequestDomainBlocksMaxCount = 100
|
2021-02-18 05:49:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 09:10:30 +01:00
|
|
|
extension APIService {
|
|
|
|
public enum Persist { }
|
|
|
|
public enum CoreData { }
|
|
|
|
}
|