mirror of
https://codeberg.org/ashley/poke.git
synced 2025-06-10 08:13:03 -04:00
owo
This commit is contained in:
parent
f431111611
commit
72143fede3
100 changed files with 12438 additions and 0 deletions
46
core/LightTube/Database/ChannelManager.cs
Normal file
46
core/LightTube/Database/ChannelManager.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System.Threading.Tasks;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace LightTube.Database
|
||||
{
|
||||
public class ChannelManager
|
||||
{
|
||||
private static IMongoCollection<LTChannel> _channelCacheCollection;
|
||||
|
||||
public ChannelManager(IMongoCollection<LTChannel> channelCacheCollection)
|
||||
{
|
||||
_channelCacheCollection = channelCacheCollection;
|
||||
}
|
||||
|
||||
public LTChannel GetChannel(string id)
|
||||
{
|
||||
LTChannel res = _channelCacheCollection.FindSync(x => x.ChannelId == id).FirstOrDefault();
|
||||
return res ?? new LTChannel
|
||||
{
|
||||
Name = "Unknown Channel",
|
||||
ChannelId = id,
|
||||
IconUrl = "",
|
||||
Subscribers = ""
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<LTChannel> UpdateChannel(string id, string name, string subscribers, string iconUrl)
|
||||
{
|
||||
LTChannel channel = new()
|
||||
{
|
||||
ChannelId = id,
|
||||
Name = name,
|
||||
Subscribers = subscribers,
|
||||
IconUrl = iconUrl
|
||||
};
|
||||
if (channel.IconUrl is null && !string.IsNullOrWhiteSpace(GetChannel(id).IconUrl))
|
||||
channel.IconUrl = GetChannel(id).IconUrl;
|
||||
if (await _channelCacheCollection.CountDocumentsAsync(x => x.ChannelId == id) > 0)
|
||||
await _channelCacheCollection.ReplaceOneAsync(x => x.ChannelId == id, channel);
|
||||
else
|
||||
await _channelCacheCollection.InsertOneAsync(channel);
|
||||
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue