diff --git a/NewLife.YuQue/YuqueClient.cs b/NewLife.YuQue/YuqueClient.cs
index 3a08d5d..2463a66 100644
--- a/NewLife.YuQue/YuqueClient.cs
+++ b/NewLife.YuQue/YuqueClient.cs
@@ -56,7 +56,8 @@ namespace NewLife.YuQue
var sb = new StringBuilder();
foreach (var item in args.ToDictionary())
{
- sb.AppendJoin('&', item.Key, "=", item.Value);
+ if (sb.Length > 0) sb.Append('&');
+ sb.AppendFormat("{0}={1}", item.Key, item.Value);
}
if (sb.Length > 0) url += "?" + sb;
}
diff --git a/NewLife.YuqueWeb/Areas/Yuque/Controllers/BookController.cs b/NewLife.YuqueWeb/Areas/Yuque/Controllers/BookController.cs
index 4607948..43b7ed1 100644
--- a/NewLife.YuqueWeb/Areas/Yuque/Controllers/BookController.cs
+++ b/NewLife.YuqueWeb/Areas/Yuque/Controllers/BookController.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using NewLife.Cube;
using NewLife.Web;
+using NewLife.YuQue;
using NewLife.YuQueWeb.Entity;
using XCode.Membership;
@@ -25,7 +26,7 @@ namespace NewLife.YuqueWeb.Areas.Yuque.Controllers
/// <summary>同步知识库</summary>
/// <returns></returns>
[EntityAuthorize(PermissionFlags.Update)]
- public ActionResult SyncRepo()
+ public async Task<ActionResult> SyncRepo()
{
var count = 0;
var ids = GetRequest("keys").SplitAsInt();
@@ -40,5 +41,73 @@ namespace NewLife.YuqueWeb.Areas.Yuque.Controllers
return JsonRefresh($"共刷新[{count}]个知识库");
}
+
+ /// <summary>扫描全部知识库</summary>
+ /// <returns></returns>
+ [EntityAuthorize(PermissionFlags.Insert)]
+ public async Task<ActionResult> ScanAll()
+ {
+ var count = 0;
+
+ // 获取令牌
+ var p = Parameter.GetOrAdd(0, "Yuque", "Token");
+ if (p.Value.IsNullOrEmpty())
+ {
+ if (p.Remark.IsNullOrEmpty())
+ {
+ p.Remark = "访问语雀的令牌,账户设置/Token,https://www.yuque.com/settings/tokens";
+ p.Update();
+ }
+
+ throw new Exception("未设置令牌![系统管理/字典参数/Yuque/Token]");
+ }
+
+ var client = new YuqueClient { Token = p.Value };
+ var user = await client.GetUser();
+
+ var list = Book.FindAll();
+ var offset = 0;
+ while (true)
+ {
+ var repos = await client.GetRepos(user.Id, "all", offset);
+ if (repos.Length == 0) break;
+
+ foreach (var repo in repos)
+ {
+ var book = list.FirstOrDefault(e => e.Id == repo.Id || e.Slug == repo.Slug);
+ if (book == null)
+ {
+ book = new Book
+ {
+ Id = repo.Id,
+ Name = repo.Name,
+ Slug = repo.Slug,
+ Code = repo.Slug,
+ Enable = true
+ };
+ book.Insert();
+
+ list.Add(book);
+ }
+
+ book.Name = repo.Name;
+ book.Type = repo.Type;
+ book.UserName = repo.User?.Name;
+ book.Docs = repo.Items;
+ book.Likes = repo.Likes;
+ book.Watches = repo.Watches;
+ book.Namespace = repo.Namespace;
+ book.Remark = repo.Description;
+ book.SyncTime = DateTime.Now;
+
+ book.Update();
+ }
+
+ count += repos.Length;
+ offset += repos.Length;
+ }
+
+ return JsonRefresh($"共扫描[{count}]个知识库");
+ }
}
}
\ No newline at end of file
diff --git a/NewLife.YuqueWeb/Areas/Yuque/Views/Book/_List_Toolbar_Batch.cshtml b/NewLife.YuqueWeb/Areas/Yuque/Views/Book/_List_Toolbar_Batch.cshtml
index 4518135..d0ea3c4 100644
--- a/NewLife.YuqueWeb/Areas/Yuque/Views/Book/_List_Toolbar_Batch.cshtml
+++ b/NewLife.YuqueWeb/Areas/Yuque/Views/Book/_List_Toolbar_Batch.cshtml
@@ -13,4 +13,7 @@
<button type="button" class="btn btn-purple btn-sm" data-action="action" data-url="@Url.Action("SyncRepo")" data-fields="keys" disabled>
同步知识库
</button>
+ <button type="button" class="btn btn-purple btn-sm" data-action="action" data-url="@Url.Action("ScanAll")" >
+ 扫描全部知识库
+ </button>
}
\ No newline at end of file
diff --git a/NewLife.YuqueWeb/YuqueService.cs b/NewLife.YuqueWeb/YuqueService.cs
index a917b39..2f2759e 100644
--- a/NewLife.YuqueWeb/YuqueService.cs
+++ b/NewLife.YuqueWeb/YuqueService.cs
@@ -1,9 +1,7 @@
using System.Reflection;
-using NewLife.Common;
using NewLife.Cube;
using NewLife.Log;
using NewLife.YuqueWeb.Areas.Yuque;
-using XCode.DataAccessLayer;
namespace NewLife.YuQueWeb;
diff --git a/YqWeb/Properties/launchSettings.json b/YqWeb/Properties/launchSettings.json
index b8521f2..7cf3620 100644
--- a/YqWeb/Properties/launchSettings.json
+++ b/YqWeb/Properties/launchSettings.json
@@ -1,25 +1,10 @@
{
- "iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
- "iisExpress": {
- "applicationUrl": "http://localhost:33992",
- "sslPort": 0
- }
- },
"profiles": {
- "YQWeb": {
+ "YqWeb": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
- "applicationUrl": "http://localhost:5153",
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
- },
- "IIS Express": {
- "commandName": "IISExpress",
- "launchBrowser": true,
+ "applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}