优化
This commit is contained in:
@@ -35,7 +35,7 @@ namespace dy.net.Controllers
|
||||
public async Task<IActionResult> UpdatePwd(UpdatePwdRequest user)
|
||||
{
|
||||
var (code, erro) = await _userService.UpdatePwd(user);
|
||||
return Ok(new { code, erro });
|
||||
return ApiResult.Success("", erro);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace dy.net.Controllers
|
||||
public async Task<IActionResult> GetUserAvatar()
|
||||
{
|
||||
var user = await _userService.GetUser();
|
||||
return Ok(new { code = 0, error = "", data = new { user?.Avatar, user?.Id, user?.UserName } });
|
||||
return ApiResult.Success(new { user?.Avatar, user?.Id, user?.UserName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,7 +64,7 @@ namespace dy.net.Controllers
|
||||
long maxFileSize = 5 * 1024 * 1024; // 限制文件大小为5MB
|
||||
if (file.Length > maxFileSize)
|
||||
{
|
||||
return Ok(new { code = -1, erro = "文件最大只能上传5M" });
|
||||
return ApiResult.Fail("文件最大只能上传5M");
|
||||
}
|
||||
var fileName = $"{IdGener.GetGuid()}_{file.FileName}";
|
||||
var filePath = webHostEnvironment.IsProduction() ?
|
||||
@@ -86,15 +86,16 @@ namespace dy.net.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Error($"delete file error ,{ex.Message}");
|
||||
return ApiResult.Fail(ex.Message);
|
||||
}
|
||||
var update = await _userService.UpdateAvatar(fileName);
|
||||
|
||||
return Ok(new { code = update ? 0 : -1, erro = update ? "" : "上传失败", data = update ? fileName : "" });
|
||||
return ApiResult.SuccOrFail(update , update ? fileName : "", update ? "" : "上传失败");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(new { code = -1, erro = "空文件" });
|
||||
return ApiResult.Fail("无效的文件");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ namespace dy.net.Controllers
|
||||
{
|
||||
if (loginUserInfo == null)
|
||||
{
|
||||
return Ok(new { code = -1, erro = "参数不能为空" });
|
||||
return ApiResult.Fail("参数不能为空");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -118,7 +119,7 @@ namespace dy.net.Controllers
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return Ok(new { code = -1, erro = "用户名或密码不正确" });
|
||||
return ApiResult.Fail("用户名或密码不正确");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -126,12 +127,11 @@ namespace dy.net.Controllers
|
||||
{
|
||||
|
||||
var tokenString = GenerateJwtToken(user.UserName);
|
||||
|
||||
return Ok(new { code = 0, erro = "", token = tokenString, expires = 24 * 60 * 60 * 1000,data=user.UserName });
|
||||
return Ok(new { code = 0, erro = "", token = tokenString, expires = 24 * 60 * 60 * 1000, data = user.UserName });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(new { code = -1, erro = "用户名或密码不正确" });
|
||||
return ApiResult.Fail("用户名或密码不正确");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace dy.net.Controllers
|
||||
cookies = await douyinCookieService.GetAllAsync()
|
||||
};
|
||||
|
||||
return Ok(new { code = 0, data = dto });
|
||||
return ApiResult.Success(dto);
|
||||
|
||||
}
|
||||
|
||||
@@ -64,40 +64,38 @@ namespace dy.net.Controllers
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importConf")]
|
||||
public async Task<IActionResult> ImportConf(AppConfigImportDto dto)
|
||||
public async Task<IActionResult> ImportConf(AppConfigImportDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
return BadRequest("json数据为空");
|
||||
if (dto == null)
|
||||
return ApiResult.Fail("json数据为空");
|
||||
|
||||
var follows = dto.follows;
|
||||
if (follows != null && follows.Count > 0)
|
||||
{
|
||||
var add = await douyinFollowService.AddHandFollows(follows);
|
||||
if (add)
|
||||
Serilog.Log.Debug("关注列表导入成功");
|
||||
}
|
||||
var follows = dto.follows;
|
||||
if (follows != null && follows.Count > 0)
|
||||
{
|
||||
var add = await douyinFollowService.AddHandFollows(follows);
|
||||
if (add)
|
||||
Serilog.Log.Debug("关注列表导入成功");
|
||||
}
|
||||
|
||||
var conf = dto.conf;
|
||||
if (conf != null)
|
||||
{
|
||||
var update = await commonService.UpdateConfig(conf);
|
||||
if (update)
|
||||
Serilog.Log.Debug("系统配置导入成功");
|
||||
}
|
||||
var conf = dto.conf;
|
||||
if (conf != null)
|
||||
{
|
||||
var update = await commonService.UpdateConfig(conf);
|
||||
if (update)
|
||||
Serilog.Log.Debug("系统配置导入成功");
|
||||
}
|
||||
var cookies = dto.cookies;
|
||||
|
||||
if (cookies != null && cookies.Count > 0)
|
||||
{
|
||||
var importCookies=await douyinCookieService.ImportCookies(cookies);
|
||||
var importCookies = await douyinCookieService.ImportCookies(cookies);
|
||||
if (importCookies)
|
||||
{
|
||||
Serilog.Log.Debug("抖音Cookie配置导入成功");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Ok(new {code=0,data=true});
|
||||
return ApiResult.Success();
|
||||
}
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
@@ -108,18 +106,13 @@ namespace dy.net.Controllers
|
||||
PageRequestDto dto)
|
||||
{
|
||||
var (list, totalCount) = await dyCookieService.GetPagedAsync(dto.PageIndex, dto.PageSize);
|
||||
return Ok(new
|
||||
return ApiResult.Success(new
|
||||
{
|
||||
code = 0,
|
||||
data = new
|
||||
{
|
||||
data = list,
|
||||
total = totalCount,
|
||||
pageIndex = dto.PageIndex,
|
||||
pageSize = dto.PageSize
|
||||
}
|
||||
}
|
||||
);
|
||||
data = list,
|
||||
total = totalCount,
|
||||
pageIndex = dto.PageIndex,
|
||||
pageSize = dto.PageSize
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +124,7 @@ namespace dy.net.Controllers
|
||||
public async Task<IActionResult> GetAllList()
|
||||
{
|
||||
var follows = await douyinFollowService.GetGroupByCookieAsync();
|
||||
return Ok(new { code = 0, data = follows });
|
||||
return ApiResult.Success(follows);
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增用户Cookie
|
||||
@@ -143,10 +136,10 @@ namespace dy.net.Controllers
|
||||
var result = await dyCookieService.Add(dyUserCookies);
|
||||
if (result)
|
||||
{
|
||||
await ReStartJob();
|
||||
return Ok(new { code = 0 });
|
||||
ReStartJob();
|
||||
return ApiResult.Success();
|
||||
}
|
||||
return BadRequest(new { code = -1, message = "添加失败" });
|
||||
return ApiResult.Fail("添加失败");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,20 +155,20 @@ namespace dy.net.Controllers
|
||||
var result = await dyCookieService.Add(dyUserCookies);
|
||||
if (result)
|
||||
{
|
||||
await ReStartJob();
|
||||
return Ok(new { code = 0 });
|
||||
ReStartJob();
|
||||
return ApiResult.Success();
|
||||
}
|
||||
return BadRequest(new { code = -1, message = "添加失败" });
|
||||
return ApiResult.Fail("添加失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await dyCookieService.UpdateAsync(dyUserCookies);
|
||||
if (result)
|
||||
{
|
||||
await ReStartJob();
|
||||
return Ok(new { code = 0 });
|
||||
ReStartJob();
|
||||
return ApiResult.Success();
|
||||
}
|
||||
return BadRequest(new { code = -1, message = "更新失败" });
|
||||
return ApiResult.Fail("更新失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -189,16 +182,16 @@ namespace dy.net.Controllers
|
||||
var count = await dyCookieService.DeleteByIdsAsync(new List<string> { id });
|
||||
if (count > 0)
|
||||
{
|
||||
await ReStartJob();
|
||||
ReStartJob();
|
||||
}
|
||||
return Ok(new { code = 0, deletedCount = count });
|
||||
return ApiResult.Success(count);
|
||||
}
|
||||
|
||||
[HttpGet("GetConfig")]
|
||||
public IActionResult GetConfig()
|
||||
{
|
||||
var data = commonService.GetConfig();
|
||||
return Ok(new { code = 0, data = data });
|
||||
return ApiResult.Success(data);
|
||||
}
|
||||
|
||||
[HttpPost("UpdateConfig")]
|
||||
@@ -207,9 +200,9 @@ namespace dy.net.Controllers
|
||||
var data = await commonService.UpdateConfig(config);
|
||||
if (data)
|
||||
{
|
||||
await ReStartJob();
|
||||
ReStartJob();
|
||||
}
|
||||
return Ok(new { code = 0, data = data });
|
||||
return ApiResult.Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -223,11 +216,11 @@ namespace dy.net.Controllers
|
||||
var config = commonService.GetConfig();
|
||||
if (config != null)
|
||||
await quartzJobService.InitOrReStartAllJobs(config.Cron.ToString());
|
||||
return Ok(new { code = 0, error = "" });
|
||||
return ApiResult.Success();
|
||||
}
|
||||
|
||||
|
||||
private async Task ReStartJob()
|
||||
private void ReStartJob()
|
||||
{
|
||||
var config = commonService.GetConfig();
|
||||
if (config != null)
|
||||
@@ -241,7 +234,7 @@ namespace dy.net.Controllers
|
||||
[HttpGet("mytag")]
|
||||
public async Task<IActionResult> GetMyTag()
|
||||
{
|
||||
return Ok(new { code = 0, data = Appsettings.Get("tagName") });
|
||||
return ApiResult.Success(Appsettings.Get("tagName"));
|
||||
}
|
||||
|
||||
[HttpGet("checktag")]
|
||||
@@ -255,7 +248,7 @@ namespace dy.net.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(new { code = -1, message = "请求失败" });
|
||||
return ApiResult.Fail("请求失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,25 +34,17 @@ namespace dy.net.Controllers
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dto.MySelfId))
|
||||
{
|
||||
return Ok(new
|
||||
{
|
||||
code = 0,
|
||||
data = new { }
|
||||
});
|
||||
return ApiResult.Success(new { });
|
||||
}
|
||||
var (list, totalCount) = await _douyinFollowService.GetPagedAsync(dto);
|
||||
return Ok(new
|
||||
|
||||
return ApiResult.Success(new
|
||||
{
|
||||
code = 0,
|
||||
data = new
|
||||
{
|
||||
data = list,
|
||||
total = totalCount,
|
||||
pageIndex = dto.PageIndex,
|
||||
pageSize = dto.PageSize
|
||||
}
|
||||
}
|
||||
);
|
||||
data = list,
|
||||
total = totalCount,
|
||||
pageIndex = dto.PageIndex,
|
||||
pageSize = dto.PageSize
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 重新同步-单次
|
||||
@@ -64,13 +56,13 @@ namespace dy.net.Controllers
|
||||
//后台异步
|
||||
_douyinQuartzJobService.StartFollowJobOnceAsync();
|
||||
await Task.Delay(1000);
|
||||
return Ok(new { code = 0 });
|
||||
return ApiResult.Success();
|
||||
}
|
||||
[HttpPost("add")]
|
||||
public async Task<IActionResult> AddFollow(DouyinFollowed followed)
|
||||
{
|
||||
var res = await _douyinFollowService.AddAsync(followed);
|
||||
return Ok(new { code = res ? 0 : -1, msg = res ? "" : "添加失败,或者已存在相同secuid和uid" });
|
||||
return ApiResult.SuccOrFail(res,"", res ? "" : "添加失败,或者已存在相同secuid和uid");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,29 +80,17 @@ namespace dy.net.Controllers
|
||||
{
|
||||
if (!DouyinFileNameHelper.IsValidWithoutSpecialChars(dto.SavePath))
|
||||
{
|
||||
return Ok(new
|
||||
{
|
||||
code = -1,
|
||||
msg = "请输入有效文件夹名称(字母数字中文简体)"
|
||||
});
|
||||
return ApiResult.Fail("请输入有效文件夹名称(字母数字中文简体)");
|
||||
}
|
||||
|
||||
if (dto.SavePath.Length > 15)
|
||||
{
|
||||
return Ok(new
|
||||
{
|
||||
code = -1,
|
||||
msg = "请输入有效文件夹名称(最长15)"
|
||||
});
|
||||
return ApiResult.Fail("请输入有效文件夹名称(最长15)");
|
||||
}
|
||||
}
|
||||
}
|
||||
var result= await _douyinFollowService.OpenOrCloseSync(dto);
|
||||
return Ok(new
|
||||
{
|
||||
code = result ? 0 : -1,
|
||||
data = result
|
||||
});
|
||||
return ApiResult.SuccOrFail(result, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +109,7 @@ namespace dy.net.Controllers
|
||||
public async Task<IActionResult> DeleteFollow(FollowUpdateDto dto)
|
||||
{
|
||||
var result= await _douyinFollowService.DeleteFollow(dto);
|
||||
return Ok(new { code = result ? 0 : -1, data = result });
|
||||
return ApiResult.SuccOrFail(result, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ namespace dy.net.Controllers
|
||||
{
|
||||
var _logDirectory = Path.Combine(Directory.GetCurrentDirectory(), "logs");
|
||||
var files = logInfoService.GetLogFiles(_logDirectory);
|
||||
return Ok(new {code=0,data=files});
|
||||
return ApiResult.Success(files);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new { message = "获取日志列表失败", error = ex.Message });
|
||||
return ApiResult.Fail("获取日志列表失败," + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,16 +28,12 @@ namespace dy.net.Controllers
|
||||
public async Task<IActionResult> GetPagedAsync(DouyinVideoPageRequestDto dto)
|
||||
{
|
||||
var (list, totalCount) = await douyinVideoService.GetPagedAsync(dto);
|
||||
return Ok(new
|
||||
return ApiResult.Success(new
|
||||
{
|
||||
code = 0,
|
||||
data = new
|
||||
{
|
||||
data = list,
|
||||
total = totalCount,
|
||||
pageIndex = dto.PageIndex,
|
||||
pageSize = dto.PageSize
|
||||
}
|
||||
data = list,
|
||||
total = totalCount,
|
||||
pageIndex = dto.PageIndex,
|
||||
pageSize = dto.PageSize
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,11 +46,7 @@ namespace dy.net.Controllers
|
||||
public async Task<IActionResult> GetStaticsAsync()
|
||||
{
|
||||
var data = await douyinVideoService.GetStatics();
|
||||
return Ok(new
|
||||
{
|
||||
code = 0,
|
||||
data
|
||||
});
|
||||
return ApiResult.Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,13 +64,13 @@ namespace dy.net.Controllers
|
||||
|
||||
if (viedo == null)
|
||||
{
|
||||
return NotFound($"视频不存在:{vid}");
|
||||
return ApiResult.Fail($"视频不存在:{vid}");
|
||||
}
|
||||
return PlayViedo(viedo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"视频加载失败:{ex.Message}");
|
||||
return ApiResult.Fail($"视频加载失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +83,7 @@ namespace dy.net.Controllers
|
||||
// 2. 验证文件是否存在
|
||||
if (!System.IO.File.Exists(videoFullPath))
|
||||
{
|
||||
return NotFound($"视频文件不存在:{videoFullPath}");
|
||||
return ApiResult.Fail($"视频文件不存在:{videoFullPath}");
|
||||
}
|
||||
|
||||
// 3. 获取文件信息(大小、类型)
|
||||
@@ -141,20 +133,20 @@ namespace dy.net.Controllers
|
||||
|
||||
if (viedo == null)
|
||||
{
|
||||
return NotFound($"视频不存在:{vid}");
|
||||
return ApiResult.Fail($"视频不存在:{vid}");
|
||||
}
|
||||
|
||||
var expectedKey = (viedo.FileHash + viedo.AuthorId).Md5();
|
||||
if (expectedKey != k)
|
||||
{
|
||||
return NotFound($"视频地址无效");
|
||||
return ApiResult.Fail($"视频地址无效");
|
||||
}
|
||||
|
||||
return PlayViedo(viedo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"视频加载失败:{ex.Message}");
|
||||
return ApiResult.Fail($"视频加载失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,18 +179,18 @@ namespace dy.net.Controllers
|
||||
{
|
||||
if (dto == null)
|
||||
{
|
||||
return Ok(new { code = -1, data = false });
|
||||
return ApiResult.Fail("参数错误");
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await douyinVideoService.ReDownloadViedoAsync(dto);
|
||||
if (result)
|
||||
{
|
||||
return Ok(new { code = 0, data = true });
|
||||
return ApiResult.Success(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(new { code = -1, data = false });
|
||||
return ApiResult.Fail("错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,14 +204,14 @@ namespace dy.net.Controllers
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(vid))
|
||||
{
|
||||
return Ok(new { code = -1, data = false });
|
||||
return ApiResult.Fail("参数错误");
|
||||
}
|
||||
else
|
||||
{
|
||||
var video = await douyinVideoService.GetById(vid);
|
||||
if (video == null)
|
||||
{
|
||||
return Ok(new { code = -1, data = false });
|
||||
return ApiResult.Fail("请求失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -233,13 +225,13 @@ namespace dy.net.Controllers
|
||||
VideoTitle = video.VideoTitle,
|
||||
VideoSavePath = video.VideoSavePath
|
||||
});
|
||||
Serilog.Log.Debug($"前面的日志,你错了,这条视频是永久删除..哈哈--{video.VideoTitle}");
|
||||
|
||||
return Ok(new { code = 0, data = true });
|
||||
Serilog.Log.Debug($"前面的日志,你错了,这条视频是永久删除..哈哈--{video.VideoTitle}");
|
||||
return ApiResult.Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(new { code = -1, data = false });
|
||||
return ApiResult.Fail();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -254,7 +246,7 @@ namespace dy.net.Controllers
|
||||
[HttpGet("vdelete/get")]
|
||||
public async Task<IActionResult> GetDeleteVideo()
|
||||
{
|
||||
return Ok(new { code = 0, data = await douyinCommonService.GetDouyinDeleteVideos() });
|
||||
return ApiResult.Success(await douyinCommonService.GetDouyinDeleteVideos());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,11 +255,9 @@ namespace dy.net.Controllers
|
||||
/// <param name="top"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("top{top}")]
|
||||
public async Task<IActionResult> GetLast([FromRoute]int top = 5)
|
||||
public async Task<IActionResult> GetLastSyncTop([FromRoute]int top = 5)
|
||||
{
|
||||
var data =await douyinVideoService.GetLastTop(top);
|
||||
|
||||
return Ok(new { code = 0, data = data });
|
||||
return ApiResult.Success(await douyinVideoService.GetLastSyncTop(top));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user