mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-06-12 12:57:46 +02:00
Update Ghostgram features
This commit is contained in:
@@ -225,7 +225,8 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
||||
} else {
|
||||
if let result = (boxedResponse as! BoxedMessage).body as? Api.upload.WebFile {
|
||||
switch result {
|
||||
case .webFile(_, _, _, _, let bytes):
|
||||
case let .webFile(webFileData):
|
||||
let bytes = webFileData.bytes
|
||||
subscriber.putNext(bytes.makeData())
|
||||
}
|
||||
subscriber.putCompletion()
|
||||
@@ -278,7 +279,8 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
||||
} else {
|
||||
if let result = (boxedResponse as! BoxedMessage).body as? Api.upload.File {
|
||||
switch result {
|
||||
case let .file(_, _, bytes):
|
||||
case let .file(fileData):
|
||||
let bytes = fileData.bytes
|
||||
subscriber.putNext(bytes.makeData())
|
||||
case .fileCdnRedirect:
|
||||
break
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import SGSimpleSettings
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
@@ -388,9 +389,9 @@ private final class FetchImpl {
|
||||
}
|
||||
|
||||
if isStory {
|
||||
self.defaultPartSize = 512 * 1024
|
||||
self.defaultPartSize = getSGDownloadPartSize(512 * 1024, fileSize: self.size)
|
||||
} else {
|
||||
self.defaultPartSize = 128 * 1024
|
||||
self.defaultPartSize = getSGDownloadPartSize(128 * 1024, fileSize: self.size)
|
||||
}
|
||||
self.cdnPartSize = 128 * 1024
|
||||
|
||||
@@ -440,7 +441,7 @@ private final class FetchImpl {
|
||||
maxPartSize: 1 * 1024 * 1024,
|
||||
partAlignment: 4 * 1024,
|
||||
partDivision: 1 * 1024 * 1024,
|
||||
maxPendingParts: 6,
|
||||
maxPendingParts: getSGMaxPendingParts(6),
|
||||
decryptionState: decryptionState
|
||||
))
|
||||
}
|
||||
@@ -696,7 +697,7 @@ private final class FetchImpl {
|
||||
maxPartSize: self.cdnPartSize * 2,
|
||||
partAlignment: self.cdnPartSize,
|
||||
partDivision: 1 * 1024 * 1024,
|
||||
maxPendingParts: 6,
|
||||
maxPendingParts: getSGMaxPendingParts(6),
|
||||
decryptionState: nil
|
||||
))
|
||||
self.update()
|
||||
@@ -745,7 +746,7 @@ private final class FetchImpl {
|
||||
maxPartSize: self.defaultPartSize,
|
||||
partAlignment: 4 * 1024,
|
||||
partDivision: 1 * 1024 * 1024,
|
||||
maxPendingParts: 6,
|
||||
maxPendingParts: getSGMaxPendingParts(6),
|
||||
decryptionState: nil
|
||||
))
|
||||
|
||||
@@ -801,7 +802,8 @@ private final class FetchImpl {
|
||||
)
|
||||
|> map { result -> FilePartResult in
|
||||
switch result {
|
||||
case let .cdnFile(bytes):
|
||||
case let .cdnFile(cdnFileData):
|
||||
let bytes = cdnFileData.bytes
|
||||
if bytes.size == 0 {
|
||||
return .data(data: Data(), verifyPartHashData: nil)
|
||||
} else {
|
||||
@@ -819,7 +821,8 @@ private final class FetchImpl {
|
||||
verifyPartHashData: VerifyPartHashData(fetchRange: fetchRange, fetchedData: fetchedData)
|
||||
)
|
||||
}
|
||||
case let .cdnFileReuploadNeeded(requestToken):
|
||||
case let .cdnFileReuploadNeeded(cdnFileReuploadNeededData):
|
||||
let requestToken = cdnFileReuploadNeededData.requestToken
|
||||
return .cdnRefresh(cdnData: cdnData, refreshToken: requestToken.makeData())
|
||||
}
|
||||
}
|
||||
@@ -858,9 +861,11 @@ private final class FetchImpl {
|
||||
)
|
||||
|> map { result -> FilePartResult in
|
||||
switch result {
|
||||
case let .file(_, _, bytes):
|
||||
case let .file(fileData):
|
||||
let bytes = fileData.bytes
|
||||
return .data(data: bytes.makeData(), verifyPartHashData: nil)
|
||||
case let .fileCdnRedirect(dcId, fileToken, encryptionKey, encryptionIv, fileHashes):
|
||||
case let .fileCdnRedirect(fileCdnRedirectData):
|
||||
let (dcId, fileToken, encryptionKey, encryptionIv, fileHashes) = (fileCdnRedirectData.dcId, fileCdnRedirectData.fileToken, fileCdnRedirectData.encryptionKey, fileCdnRedirectData.encryptionIv, fileCdnRedirectData.fileHashes)
|
||||
let _ = fileHashes
|
||||
return .cdnRedirect(CdnData(
|
||||
id: Int(dcId),
|
||||
@@ -931,7 +936,7 @@ private final class FetchImpl {
|
||||
maxPartSize: self.cdnPartSize * 2,
|
||||
partAlignment: self.cdnPartSize,
|
||||
partDivision: 1 * 1024 * 1024,
|
||||
maxPendingParts: 6,
|
||||
maxPendingParts: getSGMaxPendingParts(6),
|
||||
decryptionState: nil
|
||||
))
|
||||
case let .cdnRefresh(cdnData, refreshToken):
|
||||
@@ -995,7 +1000,8 @@ private final class FetchImpl {
|
||||
var filledRange = RangeSet<Int64>()
|
||||
for hashItem in result {
|
||||
switch hashItem {
|
||||
case let .fileHash(offset, limit, hash):
|
||||
case let .fileHash(fileHashData):
|
||||
let (offset, limit, hash) = (fileHashData.offset, fileHashData.limit, fileHashData.hash)
|
||||
let rangeValue: Range<Int64> = offset ..< (offset + Int64(limit))
|
||||
filledRange.formUnion(RangeSet<Int64>(rangeValue))
|
||||
state.hashRanges[rangeValue.lowerBound] = HashRangeData(
|
||||
|
||||
@@ -197,7 +197,8 @@ private final class MultipartCdnHashSource {
|
||||
var parsedPartHashes: [Int64: Data] = [:]
|
||||
for part in partHashes {
|
||||
switch part {
|
||||
case let .fileHash(offset, limit, bytes):
|
||||
case let .fileHash(fileHashData):
|
||||
let (offset, limit, bytes) = (fileHashData.offset, fileHashData.limit, fileHashData.hash)
|
||||
assert(limit == 128 * 1024)
|
||||
parsedPartHashes[offset] = bytes.makeData()
|
||||
}
|
||||
@@ -361,17 +362,20 @@ private enum MultipartFetchSource {
|
||||
}
|
||||
|> mapToSignal { result, info -> Signal<(Data, NetworkResponseInfo), MultipartFetchDownloadError> in
|
||||
switch result {
|
||||
case let .file(_, _, bytes):
|
||||
case let .file(fileData):
|
||||
let bytes = fileData.bytes
|
||||
var resultData = bytes.makeData()
|
||||
if resultData.count > Int(limit) {
|
||||
resultData.count = Int(limit)
|
||||
}
|
||||
return .single((resultData, info))
|
||||
case let .fileCdnRedirect(dcId, fileToken, encryptionKey, encryptionIv, partHashes):
|
||||
case let .fileCdnRedirect(fileCdnRedirectData):
|
||||
let (dcId, fileToken, encryptionKey, encryptionIv, partHashes) = (fileCdnRedirectData.dcId, fileCdnRedirectData.fileToken, fileCdnRedirectData.encryptionKey, fileCdnRedirectData.encryptionIv, fileCdnRedirectData.fileHashes)
|
||||
var parsedPartHashes: [Int64: Data] = [:]
|
||||
for part in partHashes {
|
||||
switch part {
|
||||
case let .fileHash(offset, limit, bytes):
|
||||
case let .fileHash(fileHashData):
|
||||
let (offset, limit, bytes) = (fileHashData.offset, fileHashData.limit, fileHashData.hash)
|
||||
assert(limit == 128 * 1024)
|
||||
parsedPartHashes[offset] = bytes.makeData()
|
||||
}
|
||||
@@ -395,7 +399,8 @@ private enum MultipartFetchSource {
|
||||
}
|
||||
|> mapToSignal { result, info -> Signal<(Data, NetworkResponseInfo), MultipartFetchDownloadError> in
|
||||
switch result {
|
||||
case let .webFile(_, _, _, _, bytes):
|
||||
case let .webFile(webFileData):
|
||||
let bytes = webFileData.bytes
|
||||
var resultData = bytes.makeData()
|
||||
if resultData.count > Int(limit) {
|
||||
resultData.count = Int(limit)
|
||||
@@ -418,9 +423,11 @@ private enum MultipartFetchSource {
|
||||
}
|
||||
|> mapToSignal { result, info -> Signal<(Data, NetworkResponseInfo), MultipartFetchDownloadError> in
|
||||
switch result {
|
||||
case let .cdnFileReuploadNeeded(token):
|
||||
case let .cdnFileReuploadNeeded(cdnFileReuploadNeededData):
|
||||
let token = cdnFileReuploadNeededData.requestToken
|
||||
return .fail(.reuploadToCdn(masterDatacenterId: masterDatacenterId, token: token.makeData()))
|
||||
case let .cdnFile(bytes):
|
||||
case let .cdnFile(cdnFileData):
|
||||
let bytes = cdnFileData.bytes
|
||||
if bytes.size == 0 {
|
||||
return .single((bytes.makeData(), info))
|
||||
} else {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import SGSimpleSettings
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
@@ -479,7 +480,8 @@ func multipartUpload(network: Network, postbox: Postbox, source: MultipartUpload
|
||||
}
|
||||
}
|
||||
|
||||
let manager = MultipartUploadManager(headerSize: headerSize, data: dataSignal, encryptionKey: encryptionKey, hintFileSize: hintFileSize, hintFileIsLarge: hintFileIsLarge, forceNoBigParts: forceNoBigParts, useLargerParts: useLargerParts, increaseParallelParts: increaseParallelParts, uploadPart: { part in
|
||||
// TODO(swiftgram): Change other variables for uploadSpeedBoost
|
||||
let manager = MultipartUploadManager(headerSize: headerSize, data: dataSignal, encryptionKey: encryptionKey, hintFileSize: hintFileSize, hintFileIsLarge: hintFileIsLarge, forceNoBigParts: forceNoBigParts, useLargerParts: useLargerParts || SGSimpleSettings.shared.uploadSpeedBoost, increaseParallelParts: increaseParallelParts || SGSimpleSettings.shared.uploadSpeedBoost, uploadPart: { part in
|
||||
switch uploadInterface {
|
||||
case let .download(download):
|
||||
return download.uploadPart(fileId: part.fileId, index: part.index, data: part.data, asBigPart: part.bigPart, bigTotalParts: part.bigTotalParts, useCompression: useCompression, onFloodWaitError: onFloodWaitError)
|
||||
@@ -505,18 +507,18 @@ func multipartUpload(network: Network, postbox: Postbox, source: MultipartUpload
|
||||
})
|
||||
}
|
||||
if let _ = result.bigTotalParts {
|
||||
let inputFile = Api.InputEncryptedFile.inputEncryptedFileBigUploaded(id: result.id, parts: result.partCount, keyFingerprint: fingerprint)
|
||||
let inputFile = Api.InputEncryptedFile.inputEncryptedFileBigUploaded(.init(id: result.id, parts: result.partCount, keyFingerprint: fingerprint))
|
||||
subscriber.putNext(.inputSecretFile(inputFile, result.size, encryptionKey))
|
||||
} else {
|
||||
let inputFile = Api.InputEncryptedFile.inputEncryptedFileUploaded(id: result.id, parts: result.partCount, md5Checksum: result.md5Digest, keyFingerprint: fingerprint)
|
||||
let inputFile = Api.InputEncryptedFile.inputEncryptedFileUploaded(.init(id: result.id, parts: result.partCount, md5Checksum: result.md5Digest, keyFingerprint: fingerprint))
|
||||
subscriber.putNext(.inputSecretFile(inputFile, result.size, encryptionKey))
|
||||
}
|
||||
} else {
|
||||
if let _ = result.bigTotalParts {
|
||||
let inputFile = Api.InputFile.inputFileBig(id: result.id, parts: result.partCount, name: "file.jpg")
|
||||
let inputFile = Api.InputFile.inputFileBig(.init(id: result.id, parts: result.partCount, name: "file.jpg"))
|
||||
subscriber.putNext(.inputFile(inputFile))
|
||||
} else {
|
||||
let inputFile = Api.InputFile.inputFile(id: result.id, parts: result.partCount, name: "file.jpg", md5Checksum: result.md5Digest)
|
||||
let inputFile = Api.InputFile.inputFile(.init(id: result.id, parts: result.partCount, name: "file.jpg", md5Checksum: result.md5Digest))
|
||||
subscriber.putNext(.inputFile(inputFile))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// MARK: Swiftgram
|
||||
import SGSimpleSettings
|
||||
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
@@ -504,7 +507,6 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa
|
||||
}
|
||||
|
||||
let useTempAuthKeys: Bool = true
|
||||
|
||||
let context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: useTempAuthKeys)
|
||||
|
||||
if let networkSettings = networkSettings {
|
||||
@@ -899,10 +901,12 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
|
||||
let array = NSMutableArray()
|
||||
if let result = result {
|
||||
switch result {
|
||||
case let .cdnConfig(publicKeys):
|
||||
case let .cdnConfig(cdnConfigData):
|
||||
let publicKeys = cdnConfigData.publicKeys
|
||||
for key in publicKeys {
|
||||
switch key {
|
||||
case let .cdnPublicKey(dcId, publicKey):
|
||||
case let .cdnPublicKey(cdnPublicKeyData):
|
||||
let (dcId, publicKey) = (cdnPublicKeyData.dcId, cdnPublicKeyData.publicKey)
|
||||
if id == Int(dcId) {
|
||||
let dict = NSMutableDictionary()
|
||||
dict["key"] = publicKey
|
||||
|
||||
Reference in New Issue
Block a user