diff --git a/Danmu/Model/DataTable/DanmuTable.cs b/Danmu/Model/DataTable/DanmuTable.cs index 763da5a..7b702f7 100644 --- a/Danmu/Model/DataTable/DanmuTable.cs +++ b/Danmu/Model/DataTable/DanmuTable.cs @@ -12,23 +12,19 @@ public class DanmuTable /// /// Id /// - [Key] - [Column("Id")] + [Key, Column("Id")] public Guid Id { get; set; } = new Guid(); /// /// 弹幕所在视频 /// - [Column("Vid")] - [Required] - [MaxLength(36)] + [Column("Vid"), Required, MaxLength(36)] public string Vid { get; set; } /// /// 弹幕数据 /// - [Column("Data", TypeName = "jsonb")] - [Required] + [Column("Data", TypeName = "jsonb"), Required] public BaseDanmuData Data { get; set; } /// diff --git a/Danmu/Model/DataTable/HttpClientCacheTable.cs b/Danmu/Model/DataTable/HttpClientCacheTable.cs index eb75753..dcab5c3 100644 --- a/Danmu/Model/DataTable/HttpClientCacheTable.cs +++ b/Danmu/Model/DataTable/HttpClientCacheTable.cs @@ -6,9 +6,7 @@ namespace Danmu.Model.DataTable { public class HttpClientCacheTable { - [Key] - [Column("Id")] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key, Column("Id"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Required] diff --git a/Danmu/Model/DataTable/UserTable.cs b/Danmu/Model/DataTable/UserTable.cs index 94b0b3e..8f94d5c 100644 --- a/Danmu/Model/DataTable/UserTable.cs +++ b/Danmu/Model/DataTable/UserTable.cs @@ -12,24 +12,19 @@ public class UserTable /// /// 用户ID /// - [Key] - [Column("Id")] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key, Column("Id"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } /// /// 用户名 /// - [Required] - [MaxLength(16)] - [MinLength(4)] + [Required, MaxLength(16), MinLength(4)] public string Name { get; set; } /// /// 密码 /// - [Required] - [MinLength(6)] + [Required, MinLength(6)] public string PassWord { get; set; } /// @@ -41,8 +36,7 @@ public class UserTable /// /// 用户角色 /// - [Required] - [DefaultValue(UserRole.GeneralUser)] + [Required, DefaultValue(UserRole.GeneralUser)] public UserRole Role { get; set; } = UserRole.Guests; /// @@ -65,7 +59,7 @@ public class UserTable /// 修改时间 UTC /// [Column(TypeName = "timestamp(3)")] - public DateTime UpDateTime { get; set; } = DateTime.UtcNow; + public DateTime UpdateTime { get; set; } = DateTime.UtcNow; } public enum UserRole diff --git a/Danmu/Model/DataTable/VideoTable.cs b/Danmu/Model/DataTable/VideoTable.cs index 8fee18f..bdaf0ad 100644 --- a/Danmu/Model/DataTable/VideoTable.cs +++ b/Danmu/Model/DataTable/VideoTable.cs @@ -11,16 +11,13 @@ public class VideoTable /// /// 主键 自增ID /// - [Key] - [Column("Id")] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key, Column("Id"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } /// /// 视频VID /// - [Required] - [MaxLength(36)] + [Required, MaxLength(36)] public string Vid { get; set; } [Column(TypeName = "jsonb")] public Referer Referer { get; set; } diff --git a/Danmu/Model/DbContext/BaseContext.cs b/Danmu/Model/DbContext/BaseContext.cs index 91e9349..122d7c7 100644 --- a/Danmu/Model/DbContext/BaseContext.cs +++ b/Danmu/Model/DbContext/BaseContext.cs @@ -3,6 +3,8 @@ using System.Text.Json; using Danmu.Model.Config; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Debug; namespace Danmu.Model.DbContext { @@ -18,4 +20,4 @@ public BaseContext(DbContextOptions options) : base(options) Sql = settings.DanmuSql; } } -} \ No newline at end of file +} diff --git a/Danmu/Model/DbContext/DanmuContext.cs b/Danmu/Model/DbContext/DanmuContext.cs index 74379fc..eb67d01 100644 --- a/Danmu/Model/DbContext/DanmuContext.cs +++ b/Danmu/Model/DbContext/DanmuContext.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Danmu.Model.DataTable; using Microsoft.EntityFrameworkCore; @@ -19,5 +20,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().HasIndex(h => h.Key).HasMethod("hash"); } + + public async Task ClearTable(string tableName) + { + return await Database.ExecuteSqlRawAsync($"TRUNCATE \"{tableName}\" RESTART IDENTITY;"); + } } } diff --git a/Danmu/Model/DbContext/DbContextBuild.cs b/Danmu/Model/DbContext/DbContextBuild.cs index a14aaa8..345d965 100644 --- a/Danmu/Model/DbContext/DbContextBuild.cs +++ b/Danmu/Model/DbContext/DbContextBuild.cs @@ -1,7 +1,7 @@ -using System.IO; -using Danmu.Model.Config; using Danmu.Utils.Configuration; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Debug; namespace Danmu.Model.DbContext { @@ -13,6 +13,9 @@ public DbContextBuild(AppConfiguration config, DbContextOptionsBuilder option) sql.Port = sql.Port == 0 ? 5432 : sql.Port; option.UseNpgsql( $"Host={sql.Host};Port={sql.Port};Database={sql.DataBase};Username={sql.UserName};Password={sql.PassWord};"); +#if DEBUG + option.UseLoggerFactory(new LoggerFactory(new[] { new DebugLoggerProvider() })); +#endif } } } diff --git a/Danmu/Utils/BiliBili/BiliBiliHelp.cs b/Danmu/Utils/BiliBili/BiliBiliHelp.cs index f14f4f8..ff19121 100644 --- a/Danmu/Utils/BiliBili/BiliBiliHelp.cs +++ b/Danmu/Utils/BiliBili/BiliBiliHelp.cs @@ -6,7 +6,6 @@ using Danmu.Model.Danmu.BiliBili; using Danmu.Utils.Configuration; using Danmu.Utils.Dao; -using static Danmu.Utils.Global.VariableDictionary; namespace Danmu.Utils.BiliBili { diff --git a/Danmu/Utils/Dao/DbInitializer.cs b/Danmu/Utils/Dao/DbInitializer.cs index 5e85242..38e606c 100644 --- a/Danmu/Utils/Dao/DbInitializer.cs +++ b/Danmu/Utils/Dao/DbInitializer.cs @@ -3,6 +3,7 @@ using Danmu.Model.DataTable; using Danmu.Model.DbContext; using Danmu.Utils.Common; +using Microsoft.EntityFrameworkCore; namespace Danmu.Utils.Dao { @@ -12,6 +13,15 @@ public static void Initialize(DanmuContext context, AppSettings appSettings) { context.Database.EnsureCreated(); + //临时执行,修改以前的数据库 + context.Database.ExecuteSqlRaw( + "CREATE TABLE IF NOT EXISTS \"HttpClientCache\" (\"Id\" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1 ),\t\"Key\" TEXT COLLATE \"pg_catalog\".\"default\" NOT NULL, \"Value\" bytea, \"TimeStamp\" int8 NOT NULL,\tCONSTRAINT \"PK_HttpClientCache\" PRIMARY KEY ( \"Id\" ) );"); + context.Database.ExecuteSqlRaw( + "CREATE INDEX IF NOT EXISTS \"IX_HttpClientCache_Key\" ON \"HttpClientCache\" USING hash ( \"Key\" COLLATE \"pg_catalog\".\"default\" \"pg_catalog\".\"text_ops\" );"); + + + context.Database.ExecuteSqlRaw("DO $$ BEGIN IF EXISTS(SELECT * FROM information_schema.columns WHERE table_name='User' and column_name='UpDateTime') THEN ALTER TABLE \"User\" RENAME COLUMN \"UpDateTime\" TO \"UpdateTime\"; END IF; END $$;"); + if (!context.User.Any()) { var admin = appSettings.Admin; diff --git a/Danmu/Utils/Dao/HttpClientCacheDao.cs b/Danmu/Utils/Dao/HttpClientCacheDao.cs index c3bbd18..ac6d78e 100644 --- a/Danmu/Utils/Dao/HttpClientCacheDao.cs +++ b/Danmu/Utils/Dao/HttpClientCacheDao.cs @@ -43,12 +43,22 @@ public async Task GetOrCreateCache(string key, TimeSpan expireTime, Func var d = new HttpClientCacheTable { - Key = key, + Key = key, Value = await factory() }; await _con.HttpClientCache.AddAsync(d); await _con.SaveChangesAsync(); return d.Value; } + + /// + /// 清空缓存表 + /// + /// + public async Task ClearCacheAsync() + { + var r = _con.ClearTable(nameof(_con.HttpClientCache)); + return await r > 0; + } } } diff --git a/Danmu/Utils/Dao/UserDao.cs b/Danmu/Utils/Dao/UserDao.cs index 4744c29..355baa5 100644 --- a/Danmu/Utils/Dao/UserDao.cs +++ b/Danmu/Utils/Dao/UserDao.cs @@ -99,7 +99,7 @@ public async Task ChangePasswordAsync(int id, string oldP, string newP) var r2 = await r1.FirstOrDefaultAsync(); r2.PassWord = Md5.GetMd5(newP, salt1); r2.Salt = salt1; - r2.UpDateTime = DateTime.UtcNow; + r2.UpdateTime = DateTime.UtcNow; _con.User.Update(r2); return await _con.SaveChangesAsync() > 0; } @@ -131,7 +131,7 @@ public async Task ChangeUserInfoAsync(int id, string name = null, string e r.Name = name ?? r.Name; r.Email = email ?? r.Email; r.PhoneNumber = phoneNumber ?? r.PhoneNumber; - r.UpDateTime = DateTime.UtcNow; + r.UpdateTime = DateTime.UtcNow; _con.User.Update(r); return await _con.SaveChangesAsync() > 0; } @@ -167,7 +167,7 @@ public async Task UserInfoAsync(int id) Email = s.Email, PhoneNumber = s.PhoneNumber, CreateTime = s.CreateTime, - UpDateTime = s.UpDateTime, + UpdateTime = s.UpdateTime, Role = s.Role }).FirstOrDefaultAsync(); } diff --git a/Danmu/clientapp/src/api/admin/account.js b/Danmu/clientapp/src/api/admin/account.js index 9c07f4f..7793c0d 100644 --- a/Danmu/clientapp/src/api/admin/account.js +++ b/Danmu/clientapp/src/api/admin/account.js @@ -11,8 +11,8 @@ export function logout() { window.location.href = apiPrefix + baseUrl + '/logout' } -export function getUserInfo(id) { - return request.get(baseUrl + '/user/user', { params: { id } }).then(({ data }) => data.data) +export function getUserInfo(uid) { + return request.get(baseUrl + '/user/user', { params: { uid } }).then(({ data }) => data.data) } export function changePwd({ uid, oldP, newP }) { diff --git a/Danmu/clientapp/src/store/modules/user.js b/Danmu/clientapp/src/store/modules/user.js index d7cc4ad..f9ee674 100644 --- a/Danmu/clientapp/src/store/modules/user.js +++ b/Danmu/clientapp/src/store/modules/user.js @@ -2,7 +2,7 @@ import cookie from 'js-cookie' import { cookieRoleKey } from '@/config' import { login, logout } from '@/api/admin/account' import { createMutations, isEmpty } from '@/utils' -import { getUser, setUser } from '@/utils/sessionStorage' +import { getUser, setUser, removeUser } from '@/utils/sessionStorage' //刷新时从本地存储中获取用户信息 const user = getUser() @@ -41,6 +41,7 @@ const actions = { return new Promise((resolve, reject) => { if (state.prepareLogout) return Promise.reject() commit('setPrepareLogout', true) + removeUser() logout() /*logout(state.token) .then(() => { diff --git a/Danmu/clientapp/src/utils/sessionStorage.js b/Danmu/clientapp/src/utils/sessionStorage.js index e2ec507..556c5ec 100644 --- a/Danmu/clientapp/src/utils/sessionStorage.js +++ b/Danmu/clientapp/src/utils/sessionStorage.js @@ -24,6 +24,6 @@ export function setUser(user) { sessionStorage.setItem(sessionUserKey, JSON.stringify(user)) } -function removeUser() { +export function removeUser() { sessionStorage.removeItem(sessionUserKey) } diff --git a/Danmu/clientapp/src/views/app/login.vue b/Danmu/clientapp/src/views/app/login.vue index f16aae8..afe0e67 100644 --- a/Danmu/clientapp/src/views/app/login.vue +++ b/Danmu/clientapp/src/views/app/login.vue @@ -76,7 +76,7 @@ }) }, success() { - elSuccess('登陆成功') + elSuccess('登录成功') let redirect = this.$route.query.redirect || '/' window.location.href = routerMode === 'history' ? redirect : '/#' + redirect } diff --git a/Danmu/clientapp/src/views/user/components/ChangePwd.vue b/Danmu/clientapp/src/views/user/components/ChangePwd.vue index 28ca6de..0627af7 100644 --- a/Danmu/clientapp/src/views/user/components/ChangePwd.vue +++ b/Danmu/clientapp/src/views/user/components/ChangePwd.vue @@ -1,78 +1,97 @@ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1d1d862..efdbe81 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -47,7 +47,6 @@ steps: CLI_VERSION=`git describe --tags` sed -i "s/false/true/g" $(Build.SourcesDirectory)/Danmu/Danmu.csproj sed -i "s/1.0.0/`echo ${CLI_VERSION}`/g" $(Build.SourcesDirectory)/CommandLine/Danmu.CommandLine.csproj - cat $(Build.SourcesDirectory)/CommandLine/Danmu.CommandLine.csproj - task: DotNetCoreCLI@2 inputs: