Skip to content

Commit ce5c42e

Browse files
committed
fix: solve download multi part file for stream
1 parent 9761906 commit ce5c42e

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

TelegramDownloader/Controllers/FileController.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,29 @@ public async Task<IActionResult> GetFileByTfmId(string id, [FromQuery] string id
277277
{
278278
return new ObjectResult("") { StatusCode = (int)HttpStatusCode.NotFound };
279279
}
280-
var file = _fs.ExistFileIntempFolder($"{idChannel}-{dbFile.MessageId}-{id}");
280+
var file = _fs.ExistFileIntempFolder($"{idChannel}-{(dbFile.MessageId != null ? dbFile.MessageId.ToString() : dbFile.Id)}-{id}");
281281
if (file == null)
282282
{
283-
TL.Message idM = await _ts.getMessageFile(idChannel, Convert.ToInt32(dbFile.MessageId));
284-
ChatMessages cm = new ChatMessages();
285-
cm.message = idM;
286-
file = new FileStream(System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{idFile}-{id}"), FileMode.Create, FileAccess.ReadWrite);
287-
DownloadModel dm = new DownloadModel();
288-
dm.tis = _tis;
289-
dm.channelName = _ts.getChatName(Convert.ToInt64(idChannel));
290-
_tis.addToDownloadList(dm);
291-
await _ts.DownloadFileAndReturn(cm, file, model: dm);
292-
file.Position = 0;
283+
_fs.downloadFile(idChannel, new List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent> { dbFile.toFileManagerContent() }, System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{(dbFile.MessageId != null ? dbFile.MessageId.ToString() : dbFile.Id)}-{id}"));
284+
//TL.Message idM = await _ts.getMessageFile(idChannel, Convert.ToInt32(dbFile.MessageId));
285+
//ChatMessages cm = new ChatMessages();
286+
//cm.message = idM;
287+
//file = new FileStream(System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{idFile}-{id}"), FileMode.Create, FileAccess.ReadWrite);
288+
//DownloadModel dm = new DownloadModel();
289+
//dm.tis = _tis;
290+
//dm.channelName = _ts.getChatName(Convert.ToInt64(idChannel));
291+
//_tis.addToDownloadList(dm);
292+
//await _ts.DownloadFileAndReturn(cm, file, model: dm);
293+
//file.Position = 0;
293294
}
294295

295-
Response.Headers["Content-Disposition"] = $"inline; filename=\"{HttpUtility.UrlEncode(fileName)}\"";
296+
if (file == null)
297+
{
298+
return NotFound();
299+
}
296300

301+
Response.Headers["Content-Disposition"] = $"inline; filename=\"{HttpUtility.UrlEncode(fileName)}\"";
302+
297303
return new FileStreamResult(file, mimeType);
298304
}
299305

TelegramDownloader/Data/FileService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ public async Task<String> CreateStrmFiles(string path, string dbName, string hos
11901190
string contenido = Path.Combine(host, "api/file/GetFileStream", dbName, file.Id, "file" + file.Type).Replace("\\", "/");
11911191
if (GeneralConfigStatic.config.PreloadFilesOnStream || HelperService.bytesToMegaBytes(file.Size) < GeneralConfigStatic.config.MaxPreloadFileSizeInMb)
11921192
{
1193-
contenido = Path.Combine(host, "api/file/GetFile", Uri.EscapeDataString(file.Name)).Replace("\\", "/") + $"?idChannel={dbName}&idFile={file.Id}";
1193+
contenido = Path.Combine(host, "api/file/GetFileByTfmId", Uri.EscapeDataString(file.Name)).Replace("\\", "/") + $"?idChannel={dbName}&idFile={file.Id}";
11941194
}
11951195
string pattern = $@"\.({file.Type.Replace(".", "")})$";
11961196
File.WriteAllText(Regex.Replace(filePath, pattern, ".strm"), contenido);

0 commit comments

Comments
 (0)