public async Task <UserSnapshot> GetTokenInfoAsync(string token) { var key = RedisKeyGenerator.Concat(UserMapKey, token); var val = await database.StringGetAsync(key); return(val.Get <UserSnapshot>()); }
public async Task <string> LoginAsync(string connectId, string userName, string passwordHash) { var privateKey = await GetPrivateKeyAsync(connectId); if (privateKey is null) { return(null); } var val = RSAHelper.RSADecrypt(privateKey, passwordHash); if (string.IsNullOrEmpty(val)) { return(null); } var u = await userManager.FindByNameAsync(userName); var ok = await userManager.CheckPasswordAsync(u, val); if (ok) { var key = RedisKeyGenerator.Concat(RSAKey, connectId); await database.KeyDeleteAsync(key); var identity = new UserSnapshot { Email = u.Email, Id = u.Id, Name = u.NormalizedUserName }; var tk = await userIdentityService.SetIdentityAsync(identity); return(tk); } return(null); }
public async Task <AnfBookshelfItem> GetAsync(long bookshelfId, string address) { var key = RedisKeyGenerator.Concat(ReadingKey, bookshelfId, address); var entities = await database.HashGetAllAsync(key); return(ToBookselfItem(entities)); }
public async Task <IActionResult> GetEntity([FromQuery] string url) { if (string.IsNullOrEmpty(url)) { return(BadRequest()); } var key = RedisKeyGenerator.Concat(EntityKey, url); var res = memoryCache.Get <AnfComicEntityTruck>(key); if (res != null) { await comicRankService.AddScopeAsync(url); return(Ok(res)); } res = await rootFetcher.FetchEntityAsync(url); if (res != null) { await comicRankService.AddScopeAsync(url); memoryCache.Set(key, res, new MemoryCacheEntryOptions { SlidingExpiration = CacheTime }); } return(Ok(res)); }
public async Task <string> SetIdentityAsync(UserSnapshot snapshot) { var tk = Guid.NewGuid().ToString(); var key = RedisKeyGenerator.Concat(UserMapKey, tk); var bytes = JsonSerializer.SerializeToUtf8Bytes(snapshot); await database.StringSetAsync(key, bytes, ExpireTime); return(tk); }
private Task <IResourceLocker> CreateLockerAsync(string part) { if (resourceLockerFactory is null) { throw new NotSupportedException("The IResourceLockerFactory is not provided, the function is not support"); } var key = RedisKeyGenerator.Concat(FetckKey, part, Url); return(resourceLockerFactory.CreateLockerAsync(key)); }
private async Task <string> GetPrivateKeyAsync(string connectId) { var key = RedisKeyGenerator.Concat(RSAKey, connectId); var privateKeyValue = await database.StringGetAsync(key); if (!privateKeyValue.HasValue) { return(null); } return(privateKeyValue.ToString()); }
public async Task <RSAKeyIdentity> FlushRSAKey() { var rsaKey = RSAHelper.GenerateRSASecretKey(); var identity = Guid.NewGuid().ToString(); var key = RedisKeyGenerator.Concat(RSAKey, identity); await database.StringSetAsync(key, rsaKey.PrivateKey, RSAKeyCacheTime); return(new RSAKeyIdentity { Key = rsaKey.PublicKey, Identity = identity }); }
public async Task <AnfBookshelfItem[]> BatchGetAsync(ReadingIdentity[] identities) { var keys = identities.Select(x => RedisKeyGenerator.Concat(ReadingKey, x.BookshelfId, x.Address)); var batch = database.CreateBatch(); var tasks = keys.Select(x => batch.HashGetAllAsync(x)).ToArray(); batch.Execute(); var entities = await Task.WhenAll(tasks); return(entities.Where(x => x != null) .Select(x => ToBookselfItem(x)) .ToArray()); }
public async Task <IActionResult> Search([FromQuery] string provider, [FromQuery] string keyword, [FromQuery] int skip = 0, [FromQuery] int take = 20) { if (searchEngine.Count == 0) { return(base.Problem("The search engine nothing")); } var prov = searchEngine[0]; if (!string.IsNullOrEmpty(provider)) { prov = searchEngine.FirstOrDefault(x => x.Name == provider); if (prov is null) { prov = searchEngine[0]; } } var key = RedisKeyGenerator.Concat(SearchKey, provider, keyword); var ds = memoryCache.Get(key); if (ds != null) { await hotSearchService.AddSearch(keyword); return(Ok(ds)); } using var scope = searchEngine.ServiceScopeFactory.CreateScope(); var eng = (ISearchProvider)scope.ServiceProvider.GetService(prov); var data = await eng.SearchAsync(keyword, skip, take); await hotSearchService.AddSearch(keyword); var r = new EntityResult <SearchComicResult> { Data = data }; memoryCache.Set(key, r, new MemoryCacheEntryOptions { SlidingExpiration = CacheTime }); return(Ok(r)); }
public async Task <IActionResult> GetChapter([FromQuery] string url, [FromQuery] string entityUrl) { if (string.IsNullOrEmpty(url)) { return(BadRequest()); } var key = RedisKeyGenerator.Concat(ChapterKey, url); var res = memoryCache.Get <WithPageChapter>(key); if (res != null) { return(Ok(res)); } res = await rootFetcher.FetchChapterAsync(url, entityUrl); if (res != null) { memoryCache.Set(key, res, new MemoryCacheEntryOptions { SlidingExpiration = CacheTime }); } return(Ok(res)); }