Skip to content

Commit 29a9636

Browse files
committed
fix: solve some errors 🚑
1 parent f5ac352 commit 29a9636

4 files changed

Lines changed: 37 additions & 9 deletions

File tree

TelegramDownloader/Pages/Partials/SpeedChart.razor

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646

4747
private async Task UpdateChartData(bool isInitial = false)
4848
{
49-
var downloadData = tis.downloadSpeedsHistory
49+
var downloadHistory = tis.GetDownloadSpeedsHistoryCopy();
50+
var uploadHistory = tis.GetUploadSpeedsHistoryCopy();
51+
52+
var downloadData = downloadHistory
5053
.Select(x => new {
5154
time = x.time.ToString("HH:mm:ss"),
5255
datetime = x.time.ToString("dd/MM/yyyy HH:mm:ss"),
@@ -55,7 +58,7 @@
5558
})
5659
.ToList();
5760

58-
var uploadData = tis.uploadSpeedsHistory
61+
var uploadData = uploadHistory
5962
.Select(x => new {
6063
time = x.time.ToString("HH:mm:ss"),
6164
datetime = x.time.ToString("dd/MM/yyyy HH:mm:ss"),

TelegramDownloader/Pages/Partials/impl/FileManagerImpl.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
await LoadDataAsync();
101101
if (_initialized && fm != null)
102102
{
103+
fm.Path = "/";
103104
await fm.RefreshFilesAsync();
104105
}
105106
_initialized = true;
@@ -275,11 +276,11 @@
275276
{
276277
BsonFileManagerModel item = null;
277278
if (isShared)
278-
item = await fs.getSharedItemById(id: idFile, collection: id);
279+
item = await fs.getSharedItemById(id: idFile, collection: bsi.CollectionId);
279280
else
280281
item = await fs.getItemById(id, idFile);
281282
string localdir = MyNavigationManager.BaseUri;
282-
if (forcePreDownload || (HelperService.bytesToMegaBytes(size) <= GeneralConfigStatic.config.MaxPreloadFileSizeInMb && item.MessageId != null))
283+
if (forcePreDownload || (HelperService.bytesToMegaBytes(size) <= GeneralConfigStatic.config.MaxPreloadFileSizeInMb && item != null && item.MessageId != null))
283284
{
284285
return new System.Uri(Path.Combine(localdir, "api/file/GetFile", name).Replace("\\", "/") + $"?idChannel={(isShared ? bsi.ChannelId : id)}&idFile={item.MessageId}").AbsoluteUri;
285286
}

TelegramDownloader/Pages/Partials/impl/LocalFileManagerImpl.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
await LoadDataAsync();
8989
if (_initialized && FileManager != null)
9090
{
91+
FileManager.Path = "/";
9192
await FileManager.RefreshFilesAsync();
9293
}
9394
_initialized = true;

TelegramDownloader/Services/TransactionInfoService.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class TransactionInfoService
2525
public long bytesDownloaded = 0;
2626
public List<SpeedHistory> downloadSpeedsHistory = new List<SpeedHistory>();
2727
public List<SpeedHistory> uploadSpeedsHistory = new List<SpeedHistory>();
28+
private readonly object _speedHistoryLock = new object();
2829
private int speedHistoryCount = 0;
2930

3031
private static Mutex PendingDownloadMutex = new Mutex();
@@ -123,22 +124,44 @@ private void OnTimedEvent(Object source, ElapsedEventArgs e)
123124

124125
private bool canStopTimer()
125126
{
126-
return uploadSpeedsHistory.Sum(x => x.speed) + downloadSpeedsHistory.Sum(x => x.speed) == 0;
127+
lock (_speedHistoryLock)
128+
{
129+
return uploadSpeedsHistory.Sum(x => x.speed) + downloadSpeedsHistory.Sum(x => x.speed) == 0;
130+
}
127131
}
128132

129133
private void setHistorySpeed()
130134
{
131135
DateTime now = DateTime.Now;
132136
var activeDownloads = downloadModels.Where(x => x.state == StateTask.Working).Select(x => x.name).ToList();
133137
var activeUploads = uploadModels.Where(x => x.state == StateTask.Working).Select(x => x.name).ToList();
134-
downloadSpeedsHistory.Add(new SpeedHistory() { time = now, speed = bytesDownloaded, speedString = downloadSpeed, activeFiles = activeDownloads });
135-
uploadSpeedsHistory.Add(new SpeedHistory() { time = now, speed = bytesUploaded, speedString = uploadSpeed, activeFiles = activeUploads });
136-
downloadSpeedsHistory.RemoveAll(x => (now - x.time).TotalSeconds > MAX_SPEED_HISTORY_SECONDS);
137-
uploadSpeedsHistory.RemoveAll(x => (now - x.time).TotalSeconds > MAX_SPEED_HISTORY_SECONDS);
138+
lock (_speedHistoryLock)
139+
{
140+
downloadSpeedsHistory.Add(new SpeedHistory() { time = now, speed = bytesDownloaded, speedString = downloadSpeed, activeFiles = activeDownloads });
141+
uploadSpeedsHistory.Add(new SpeedHistory() { time = now, speed = bytesUploaded, speedString = uploadSpeed, activeFiles = activeUploads });
142+
downloadSpeedsHistory.RemoveAll(x => (now - x.time).TotalSeconds > MAX_SPEED_HISTORY_SECONDS);
143+
uploadSpeedsHistory.RemoveAll(x => (now - x.time).TotalSeconds > MAX_SPEED_HISTORY_SECONDS);
144+
}
138145
if (HistorykEventChanged != null)
139146
HistorykEventChanged.Invoke(this, EventArgs.Empty);
140147
}
141148

149+
public List<SpeedHistory> GetDownloadSpeedsHistoryCopy()
150+
{
151+
lock (_speedHistoryLock)
152+
{
153+
return downloadSpeedsHistory.ToList();
154+
}
155+
}
156+
157+
public List<SpeedHistory> GetUploadSpeedsHistoryCopy()
158+
{
159+
lock (_speedHistoryLock)
160+
{
161+
return uploadSpeedsHistory.ToList();
162+
}
163+
}
164+
142165
public async Task addDownloadBytes(long bytes)
143166
{
144167
DownloadBytesMutex.WaitOne();

0 commit comments

Comments
 (0)