mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Use media DC for uploads
This commit is contained in:
parent
3f1d4eba92
commit
f495f59bc8
|
|
@ -33,6 +33,7 @@ namespace WTelegram
|
||||||
/// <returns>an <see cref="InputFile"/> or <see cref="InputFileBig"/> than can be used in various requests</returns>
|
/// <returns>an <see cref="InputFile"/> or <see cref="InputFileBig"/> than can be used in various requests</returns>
|
||||||
public async Task<InputFileBase> UploadFileAsync(Stream stream, string filename, ProgressCallback progress = null)
|
public async Task<InputFileBase> UploadFileAsync(Stream stream, string filename, ProgressCallback progress = null)
|
||||||
{
|
{
|
||||||
|
var client = await GetClientForDC(-_dcSession.DcID, true);
|
||||||
using (stream)
|
using (stream)
|
||||||
{
|
{
|
||||||
bool hasLength = stream.CanSeek;
|
bool hasLength = stream.CanSeek;
|
||||||
|
|
@ -65,9 +66,9 @@ namespace WTelegram
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (isBig)
|
if (isBig)
|
||||||
await this.Upload_SaveBigFilePart(file_id, file_part, file_total_parts, bytes);
|
await client.Upload_SaveBigFilePart(file_id, file_part, file_total_parts, bytes);
|
||||||
else
|
else
|
||||||
await this.Upload_SaveFilePart(file_id, file_part, bytes);
|
await client.Upload_SaveFilePart(file_id, file_part, bytes);
|
||||||
lock (tasks) { transmitted += bytes.Length; tasks.Remove(file_part); }
|
lock (tasks) { transmitted += bytes.Length; tasks.Remove(file_part); }
|
||||||
progress?.Invoke(transmitted, length);
|
progress?.Invoke(transmitted, length);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ namespace WTelegram
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Auth_ExportedAuthorization exported = null;
|
Auth_ExportedAuthorization exported = null;
|
||||||
if (_session.UserId != 0 && IsMainDC && altSession.UserId != _session.UserId)
|
if (_session.UserId != 0 && IsMainDC && altSession.UserId != _session.UserId && altSession.DcID != _dcSession.DcID)
|
||||||
exported = await this.Auth_ExportAuthorization(Math.Abs(dcId));
|
exported = await this.Auth_ExportAuthorization(Math.Abs(dcId));
|
||||||
await altSession.Client.ConnectAsync();
|
await altSession.Client.ConnectAsync();
|
||||||
if (exported != null)
|
if (exported != null)
|
||||||
|
|
|
||||||
|
|
@ -525,7 +525,7 @@ namespace TL
|
||||||
partial class Document
|
partial class Document
|
||||||
{
|
{
|
||||||
public override long ID => id;
|
public override long ID => id;
|
||||||
public override string ToString() => Filename is string filename ? base.ToString() + ": " + filename : base.ToString();
|
public override string ToString() => $"{Filename ?? $"Document {mime_type}"} {size:N0} bytes";
|
||||||
public string Filename => GetAttribute<DocumentAttributeFilename>()?.file_name;
|
public string Filename => GetAttribute<DocumentAttributeFilename>()?.file_name;
|
||||||
protected override InputDocument ToInputDocument() => new() { id = id, access_hash = access_hash, file_reference = file_reference };
|
protected override InputDocument ToInputDocument() => new() { id = id, access_hash = access_hash, file_reference = file_reference };
|
||||||
public InputDocumentFileLocation ToFileLocation(PhotoSizeBase thumbSize = null) => new() { id = id, access_hash = access_hash, file_reference = file_reference, thumb_size = thumbSize?.Type };
|
public InputDocumentFileLocation ToFileLocation(PhotoSizeBase thumbSize = null) => new() { id = id, access_hash = access_hash, file_reference = file_reference, thumb_size = thumbSize?.Type };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue