Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Service/APIService/APIService.swift

55 lines
1.4 KiB
Swift
Raw Permalink Normal View History

2021-01-28 09:10:30 +01:00
//
// APIService.swift
// Mastodon
//
// Created by sxiaojian on 2021/1/27.
//
import os.log
import Foundation
import Combine
import CoreData
import CoreDataStack
import MastodonSDK
import AlamofireImage
import AlamofireNetworkActivityIndicator
final class APIService {
var disposeBag = Set<AnyCancellable>()
// internal
let session: URLSession
// input
let backgroundManagedObjectContext: NSManagedObjectContext
2021-02-03 09:01:08 +01:00
// output
let error = PassthroughSubject<APIError, Never>()
2021-01-28 09:10:30 +01:00
init(backgroundManagedObjectContext: NSManagedObjectContext) {
self.backgroundManagedObjectContext = backgroundManagedObjectContext
self.session = URLSession(configuration: .default)
// 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
NetworkActivityIndicatorManager.shared.isEnabled = true
NetworkActivityIndicatorManager.shared.startDelay = 0.2
NetworkActivityIndicatorManager.shared.completionDelay = 0.5
}
}
extension APIService {
2021-04-01 08:39:15 +02:00
public static let onceRequestStatusMaxCount = 100
public static let onceRequestUserMaxCount = 100
2021-04-29 09:51:52 +02:00
public static let onceRequestDomainBlocksMaxCount = 100
}
2021-01-28 09:10:30 +01:00
extension APIService {
public enum Persist { }
public enum CoreData { }
}