Skip to content

Commit cdf565c

Browse files
committed
1.3.0
1 parent 9515a3b commit cdf565c

35 files changed

+1444
-322
lines changed

.vscode/settings.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
{
2-
"dotnet.defaultSolution": "sscms.gather.sln"
2+
"dotnet.defaultSolution": "sscms.gather.sln",
3+
"editor.tabSize": 4,
4+
"[csharp]": {
5+
"editor.tabSize": 4
6+
},
7+
"[html]": {
8+
"editor.tabSize": 2
9+
},
10+
"[javascript]": {
11+
"editor.tabSize": 2
12+
},
13+
"[json]": {
14+
"editor.tabSize": 2
15+
},
16+
"editor.insertSpaces": true
317
}

Abstractions/IGatherManager.cs

+2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ public interface IGatherManager
1616
Task ExportAsync(Rule rule, string filePath);
1717

1818
Task ImportAsync(int siteId, string filePath, bool overwrite);
19+
20+
Task GatherChannelsAsync(int adminId, int siteId, int ruleId, string guid);
1921
}
2022
}

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.3.0
2+
* 兼容 SSCMS 7.3.0
3+
* 新增单页采集通过从相似网址采集功能
4+
5+
## 1.2.4
6+
* 对设置为已审核的采集规则,采集完成后将生成内容及栏目页面
7+
* 新增定时任务功能,可添加定时执行采集任务 #3626 #3649
8+
* 新增批量采集功能,可一键采集多个规则 #3721
9+
110
## 1.2.3
211
* 兼容 SSCMS 7.2.2
312

Controllers/Admin/ListController.Delete.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ public async Task<ActionResult<DeleteResult>> Delete([FromBody] DeleteRequest re
1414
return Unauthorized();
1515
}
1616

17-
await _ruleRepository.DeleteAsync(request.RuleId);
17+
foreach (var ruleId in request.RuleIds)
18+
{
19+
await _ruleRepository.DeleteAsync(ruleId);
20+
}
1821

1922
var rules = await _ruleRepository.GetRulesAsync(request.SiteId);
2023
foreach (var rule in rules)

Controllers/Admin/ListController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class GetResult
4848

4949
public class DeleteRequest : SiteRequest
5050
{
51-
public int RuleId { get; set; }
51+
public List<int> RuleIds { get; set; }
5252
}
5353

5454
public class DeleteResult

Controllers/Admin/SingleController.Submit.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@ public async Task<ActionResult<StringResult>> Submit([FromBody] SubmitRequest re
2626

2727
await _ruleRepository.UpdateAsync(rule);
2828

29-
var urls = ListUtils.GetStringList(request.Urls, '\n');
29+
var urls = GatherUtils.GetGatherUrlList(
30+
request.GatherUrlIsCollection,
31+
request.GatherUrlIsSerialize,
32+
request.GatherUrlCollection,
33+
request.GatherUrlSerialize,
34+
request.SerializeFrom,
35+
request.SerializeTo,
36+
request.SerializeInterval,
37+
request.SerializeIsOrderByDesc,
38+
request.SerializeIsAddZero
39+
);
40+
41+
// var urls = ListUtils.GetStringList(request.Urls, '\n');
3042
var items = urls.Select(x => new Item
3143
{
3244
Url = x,

Controllers/Admin/SingleController.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ public class SubmitRequest
5454
public int RuleId { get; set; }
5555
public int ChannelId { get; set; }
5656
public bool IsChecked { get; set; }
57-
public string Urls { get; set; }
57+
public bool GatherUrlIsCollection { get; set; }
58+
public bool GatherUrlIsSerialize { get; set; }
59+
public string GatherUrlCollection { get; set; }
60+
public string GatherUrlSerialize { get; set; }
61+
public int SerializeFrom { get; set; }
62+
public int SerializeTo { get; set; }
63+
public int SerializeInterval { get; set; }
64+
public bool SerializeIsOrderByDesc { get; set; }
65+
public bool SerializeIsAddZero { get; set; }
5866
}
5967

6068
public class GatherRequest : SiteRequest

Controllers/Admin/StartController.Gather.cs

-27
This file was deleted.

Controllers/Admin/StartController.Status.cs

-25
This file was deleted.

Controllers/Admin/StartController.Submit.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
using Microsoft.AspNetCore.Mvc;
44
using SSCMS.Dto;
55
using SSCMS.Gather.Core;
6-
using SSCMS.Utils;
76

87
namespace SSCMS.Gather.Controllers.Admin
98
{
109
public partial class StartController
1110
{
1211
[HttpPost, Route(Route)]
13-
public async Task<ActionResult<StringResult>> Submit([FromBody] SubmitRequest request)
12+
public async Task<ActionResult<BoolResult>> Submit([FromBody] SubmitRequest request)
1413
{
1514
if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsList))
1615
{
@@ -35,9 +34,9 @@ public async Task<ActionResult<StringResult>> Submit([FromBody] SubmitRequest re
3534

3635
await _ruleRepository.UpdateAsync(rule);
3736

38-
return new StringResult
37+
return new BoolResult
3938
{
40-
Value = StringUtils.Guid()
39+
Value = true
4140
};
4241
}
4342
}

Controllers/Admin/StartController.cs

+1-23
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using SSCMS.Configuration;
55
using SSCMS.Gather.Abstractions;
66
using SSCMS.Dto;
7-
using SSCMS.Gather.Core;
87
using SSCMS.Gather.Models;
98
using SSCMS.Repositories;
109
using SSCMS.Services;
11-
using SSCMS.Utils;
1210

1311
namespace SSCMS.Gather.Controllers.Admin
1412
{
@@ -17,20 +15,16 @@ namespace SSCMS.Gather.Controllers.Admin
1715
public partial class StartController : ControllerBase
1816
{
1917
private const string Route = "gather/start";
20-
private const string RouteActionsGather = "gather/start/actions/gather";
21-
private const string RouteActionsStatus = "gather/start/actions/status";
2218

2319
private readonly IAuthManager _authManager;
24-
private readonly IGatherManager _gatherManager;
2520
private readonly IRuleRepository _ruleRepository;
2621
private readonly ISiteRepository _siteRepository;
2722
private readonly IChannelRepository _channelRepository;
2823
private readonly IContentRepository _contentRepository;
2924

30-
public StartController(IAuthManager authManager, IGatherManager gatherManager, IRuleRepository ruleRepository, ISiteRepository siteRepository, IChannelRepository channelRepository, IContentRepository contentRepository)
25+
public StartController(IAuthManager authManager, IRuleRepository ruleRepository, ISiteRepository siteRepository, IChannelRepository channelRepository, IContentRepository contentRepository)
3126
{
3227
_authManager = authManager;
33-
_gatherManager = gatherManager;
3428
_ruleRepository = ruleRepository;
3529
_siteRepository = siteRepository;
3630
_channelRepository = channelRepository;
@@ -66,21 +60,5 @@ public class SubmitRequest
6660
public bool SerializeIsOrderByDesc { get; set; }
6761
public bool SerializeIsAddZero { get; set; }
6862
}
69-
70-
public class GatherRequest : SiteRequest
71-
{
72-
public int RuleId { get; set; }
73-
public string Guid { get; set; }
74-
}
75-
76-
public class StatusRequest : SiteRequest
77-
{
78-
public string Guid { get; set; }
79-
}
80-
81-
public class StatusResult
82-
{
83-
public ProgressCache Cache { get; set; }
84-
}
8563
}
8664
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Mvc;
4+
using SSCMS.Gather.Core;
5+
using SSCMS.Gather.Models;
6+
using SSCMS.Utils;
7+
8+
namespace SSCMS.Gather.Controllers.Admin
9+
{
10+
public partial class StatusController
11+
{
12+
[HttpGet, Route(Route)]
13+
public async Task<ActionResult<GetResult>> Get([FromQuery] GetRequest request)
14+
{
15+
if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsList))
16+
{
17+
return Unauthorized();
18+
}
19+
20+
var rules = new List<Rule>();
21+
foreach (var ruleId in ListUtils.GetIntList(request.RuleIds))
22+
{
23+
var rule = await _ruleRepository.GetAsync(ruleId);
24+
var channel = await _channelRepository.GetAsync(rule.ChannelId);
25+
26+
if (channel == null || channel.SiteId != rule.SiteId)
27+
{
28+
rule.Set("error", "采集错误,请设置需要采集到的栏目!");
29+
}
30+
else
31+
{
32+
_gatherManager.Start(_authManager.AdminId, request.SiteId, ruleId, rule.Guid);
33+
}
34+
35+
rule.Set("cache", new {});
36+
rule.Set("percentage", new {});
37+
rules.Add(rule);
38+
}
39+
40+
return new GetResult
41+
{
42+
Rules = rules
43+
};
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Mvc;
4+
using SSCMS.Gather.Core;
5+
using SSCMS.Utils;
6+
7+
namespace SSCMS.Gather.Controllers.Admin
8+
{
9+
public partial class StatusController
10+
{
11+
[HttpPost, Route(Route)]
12+
public async Task<ActionResult<SubmitResult>> Submit([FromBody] SubmitRequest request)
13+
{
14+
if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsList))
15+
{
16+
return Unauthorized();
17+
}
18+
19+
var caches = new List<ProgressCache>();
20+
foreach (var ruleId in ListUtils.GetIntList(request.RuleIds))
21+
{
22+
var rule = await _ruleRepository.GetAsync(ruleId);
23+
var cache = _gatherManager.GetCache(rule.Guid);
24+
caches.Add(cache);
25+
}
26+
27+
return new SubmitResult
28+
{
29+
Caches = caches
30+
};
31+
}
32+
}
33+
}

Controllers/Admin/StatusController.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Collections.Generic;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Mvc;
4+
using SSCMS.Configuration;
5+
using SSCMS.Gather.Abstractions;
6+
using SSCMS.Dto;
7+
using SSCMS.Gather.Core;
8+
using SSCMS.Services;
9+
using SSCMS.Gather.Models;
10+
using SSCMS.Repositories;
11+
12+
namespace SSCMS.Gather.Controllers.Admin
13+
{
14+
[Authorize(Roles = Types.Roles.Administrator)]
15+
[Route(Constants.ApiAdminPrefix)]
16+
public partial class StatusController : ControllerBase
17+
{
18+
private const string Route = "gather/status";
19+
20+
private readonly IAuthManager _authManager;
21+
private readonly IGatherManager _gatherManager;
22+
private readonly IRuleRepository _ruleRepository;
23+
private readonly IChannelRepository _channelRepository;
24+
25+
public StatusController(IAuthManager authManager, IGatherManager gatherManager, IRuleRepository ruleRepository, IChannelRepository channelRepository)
26+
{
27+
_authManager = authManager;
28+
_gatherManager = gatherManager;
29+
_ruleRepository = ruleRepository;
30+
_channelRepository = channelRepository;
31+
}
32+
33+
public class GetRequest : SiteRequest
34+
{
35+
public string RuleIds { get; set; }
36+
}
37+
38+
public class GetResult
39+
{
40+
public List<Rule> Rules { get; set; }
41+
}
42+
43+
public class SubmitRequest : SiteRequest
44+
{
45+
public string RuleIds { get; set; }
46+
}
47+
48+
public class SubmitResult
49+
{
50+
public List<ProgressCache> Caches { get; set; }
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc;
3+
using SSCMS.Dto;
4+
using SSCMS.Gather.Core;
5+
6+
namespace SSCMS.Gather.Controllers.Admin
7+
{
8+
public partial class TasksController
9+
{
10+
[HttpPost, Route(RouteDelete)]
11+
public async Task<ActionResult<BoolResult>> Delete([FromBody] IdRequest request)
12+
{
13+
if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsTasks))
14+
{
15+
return Unauthorized();
16+
}
17+
18+
await _scheduledTaskRepository.DeleteAsync(request.Id);
19+
20+
return new BoolResult
21+
{
22+
Value = true
23+
};
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)