Home telegram - mediaResource
Post
Cancel

telegram - mediaResource

MediaResource

protocol MediaResourceFetchTag

protocol MediaResourceFetchInfo

struct MediaResourceFetchParameters

1
2
let tag: MediaResourceFetchTag?
let info: MediaResourceFetchInfo?

protocol MediaResourceId

1
2
var uniqueId: String { get }
var hashValue: Int { get }

protocol MediaResource

1
2
3
4
var id: MediaResourceId { get }
var size: Int? { get }
var streamable: Bool { get }
var headerSize: Int32 { get }

TelegramMediaResource

protoco TelegramMediaResource : MediaResource

MultipartFetchableResource

protocol TelegramMultipartFetchableResource: TelegramMediaResource

1
var datacenterId: Int { get }

TelegramCloudMediaResource

protocol TelegramCloudMediaResource: TelegramMediaResource

1
func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation?

TelegramCloudMediaResourceWithFileReference

protocol TelegramCloudMediaResourceWithFileReference

1
var fileReference: Data? { get }

CloudFileMediaResource

struct CloudFileMediaResourceId: MediaResourceId

1
2
3
4
5
6
7
8
let datacenterId: Int
let volumeId: Int64
let localId: Int32
let secret: Int64

public var uniqueId: String {
    return "telegram-cloud-file-\(self.datacenterId)-\(self.volumeId)-\(self.localId)-\(self.secret)"
}

class CloudFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public let datacenterId: Int
public let volumeId: Int64
public let localId: Int32
public let secret: Int64
public let size: Int?
public let fileReference: Data?

public var id: MediaResourceId {
    return CloudFileMediaResourceId(datacenterId: self.datacenterId, volumeId: self.volumeId, localId: self.localId, secret: self.secret)
}

func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? {
        return Api.InputFileLocation.inputFileLocation(volumeId: self.volumeId, localId: self.localId, secret: self.secret, fileReference: Buffer(data: fileReference ?? Data()))
    }

CloudPhotoSizeMediaResource

struct CloudPhotoSizeMediaResourceId: MediaResourceId

1
2
3
4
5
6
7
let datacenterId: Int32
let photoId: Int64
let sizeSpec: String

public var uniqueId: String {
    return "telegram-cloud-photo-size-\(self.datacenterId)-\(self.photoId)-\(self.sizeSpec)"
}

class CloudPhotoSizeMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public let datacenterId: Int
public let photoId: Int64
public let accessHash: Int64
public let sizeSpec: String
public let volumeId: Int64
public let localId: Int32
public let fileReference: Data?

public var id: MediaResourceId {
    return CloudPhotoSizeMediaResourceId(datacenterId: Int32(self.datacenterId), photoId: self.photoId, sizeSpec: self.sizeSpec)
}

func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? {
    return Api.InputFileLocation.inputPhotoFileLocation(id: self.photoId, accessHash: self.accessHash, fileReference: Buffer(data: fileReference ?? Data()), thumbSize: self.sizeSpec)
}

CloudDocumentSizeMediaResource

struct CloudDocumentSizeMediaResourceId: MediaResourceId

1
2
3
4
5
6
7
let datacenterId: Int32
let documentId: Int64
let sizeSpec: String

public var uniqueId: String {
    return "telegram-cloud-document-size-\(self.datacenterId)-\(self.documentId)-\(self.sizeSpec)"
}

class CloudDocumentSizeMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let datacenterId: Int
let documentId: Int64
let accessHash: Int64
let sizeSpec: String
let volumeId: Int64
let localId: Int32
let fileReference: Data?

public var id: MediaResourceId {
    return CloudDocumentSizeMediaResourceId(datacenterId: Int32(self.datacenterId), documentId: self.documentId, sizeSpec: self.sizeSpec)
}

func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? {
    return Api.InputFileLocation.inputDocumentFileLocation(id: self.documentId, accessHash: self.accessHash, fileReference: Buffer(data: fileReference ?? Data()), thumbSize: self.sizeSpec)
}

CloudPeerPhotoSizeMediaResource

enum CloudPeerPhotoSizeSpec

1
2
case small
case fullSize

struct CloudPeerPhotoSizeMediaResourceId: MediaResourceId

1
2
3
4
5
6
7
8
let datacenterId: Int32
let sizeSpec: CloudPeerPhotoSizeSpec
let volumeId: Int64
let localId: Int32

public var uniqueId: String {
    return "telegram-peer-photo-size-\(self.datacenterId)-\(self.sizeSpec.rawValue)-\(self.volumeId)-\(self.localId)"
}

class CloudPeerPhotoSizeMediaResource: TelegramMultipartFetchableResource

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public let datacenterId: Int
let sizeSpec: CloudPeerPhotoSizeSpec
let volumeId: Int64
let localId: Int32

public var id: MediaResourceId {
    return CloudPeerPhotoSizeMediaResourceId(datacenterId: Int32(self.datacenterId), sizeSpec: self.sizeSpec, volumeId: self.volumeId, localId: self.localId)
}

func apiInputLocation(peerReference: PeerReference) -> Api.InputFileLocation? {
    let flags: Int32
    switch self.sizeSpec {
        case .small:
            flags = 0
        case .fullSize:
            flags = 1 << 0
    }
    return Api.InputFileLocation.inputPeerPhotoFileLocation(flags: flags, peer: peerReference.inputPeer, volumeId: self.volumeId, localId: self.localId)
}

CloudStickerPackThumbnailMediaResource

struct CloudStickerPackThumbnailMediaResourceId: MediaResourceId

1
2
3
4
5
6
7
let datacenterId: Int32
let volumeId: Int64
let localId: Int32

public var uniqueId: String {
    return "telegram-stickerpackthumbnail-\(self.datacenterId)-\(self.volumeId)-\(self.localId)"
}

class CloudStickerPackThumbnailMediaResource: TelegramMultipartFetchableResource

1
2
3
4
5
6
7
8
9
10
public let datacenterId: Int
let volumeId: Int64
let localId: Int32

public var id: MediaResourceId {
    return CloudStickerPackThumbnailMediaResourceId(datacenterId: Int32(self.datacenterId), volumeId: self.volumeId, localId: self.localId)
}
func apiInputLocation(packReference: StickerPackReference) -> Api.InputFileLocation? {
    return Api.InputFileLocation.inputStickerSetThumb(stickerset: packReference.apiInputStickerSet, volumeId: self.volumeId, localId: self.localId)
}

CloudDocumentMediaResource

struct CloudDocumentMediaResourceId: MediaResourceId

1
2
3
4
5
6
let datacenterId: Int
let fileId: Int64

public var uniqueId: String {
    return "telegram-cloud-document-\(self.datacenterId)-\(self.fileId)"
}

class CloudDocumentMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let datacenterId: Int
let fileId: Int64
let accessHash: Int64
let size: Int?
let fileReference: Data?
let fileName: String?

public var id: MediaResourceId {
    return CloudDocumentMediaResourceId(datacenterId: self.datacenterId, fileId: self.fileId)
}

func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? {
    return Api.InputFileLocation.inputDocumentFileLocation(id: self.fileId, accessHash: self.accessHash, fileReference: Buffer(data: fileReference ?? Data()), thumbSize: "")
}

LocalFileMediaResource

struct LocalFileMediaResourceId: MediaResourceId

1
2
3
4
public let fileId: Int64
public var uniqueId: String {
    return "telegram-local-file-\(self.fileId)"
}

class LocalFileMediaResource: TelegramMediaResource

1
2
3
4
5
6
let fileId: Int64
let size: Int?

public var id: MediaResourceId {
    return LocalFileMediaResourceId(fileId: self.fileId)
}

LocalFileReferenceMediaResource

struct LocalFileReferenceMediaResourceId: MediaResourceId

1
2
3
public var uniqueId: String {
    return "local-file-\(self.randomId)"
}

class LocalFileReferenceMediaResource: TelegramMediaResource

1
2
3
4
5
6
7
8
public let localFilePath: String
let randomId: Int64
let isUniquelyReferencedTemporaryFile: Bool
public let size: Int32?

public var id: MediaResourceId {
    return LocalFileReferenceMediaResourceId(randomId: self.randomId)
}

HttpReferenceMediaResource

struct HttpReferenceMediaResourceId: MediaResourceId

1
2
3
4
let url: String
public var uniqueId: String {
    return "http-\(persistentHash32(self.url))"
}

class HttpReferenceMediaResource: TelegramMediaResource

1
2
3
4
5
6
let url: String
let size: Int?

public var id: MediaResourceId {
    return HttpReferenceMediaResourceId(url: self.url)
}

WebFileReferenceMediaResource

struct WebFileReferenceMediaResourceId: MediaResourceId

1
2
3
4
5
6
7
let url: String
let accessHash: Int64
let size: Int32

public var uniqueId: String {
    return "proxy-\(persistentHash32(self.url))-\(size)-\(accessHash)"
}

class WebFileReferenceMediaResource : TelegramMediaResource

1
2
3
4
5
6
7
let url: String
let size: Int32
let accessHash: Int64

public var id: MediaResourceId {
    return WebFileReferenceMediaResourceId(url: self.url, accessHash: accessHash, size: self.size)
}

SecretFileMediaResource

struct SecretFileMediaResourceId : MediaResourceId

1
2
3
4
5
6
7
8
9
let fileId: Int64
let datacenterId: Int32
public var uniqueId: String {
    return "secret-file-\(self.fileId)-\(self.datacenterId)"
}

public var uniqueId: String {
    return "secret-file-\(self.fileId)-\(self.datacenterId)"
}

struct SecretFileMediaResource : TelegramCloudMediaResource , TelegramMultipartFetchableResource

1
2
3
4
5
6
7
8
9
10
11
12
let fileId: Int64
let accessHash: Int64
var size: Int? {
urn Int(self.decryptedSize)
let containerSize: Int32
let decryptedSize: Int32
let datacenterId: Int
let key: SecretFileEncryptionKey
  
public var id: MediaResourceId {
    return SecretFileMediaResourceId(fileId: self.fileId, datacenterId: Int32(self.datacenterId))
}  

EmptyMediaResource

struct EmptyMediaResourceId:MediaResourceId

1
2
3
4
5
6
7
public var uniqueId: String {
    return "empty-resource"
}

public var hashValue: Int {
    return 0
}

class EmptyMediaResource: TelegramMediaResource

1
2
3
public var id: MediaResourceId {
    return EmptyMediaResourceId()
}
This post is licensed under CC BY 4.0 by the author.