NewLife/YuQue

支持批量刷新文章
大石头 authored at 2022-04-14 14:51:57
8ae70bd
Tree
1 Parent(s) c560ac0
Summary: 5 changed files with 55 additions and 3 deletions.
Modified +27 -1
Added +10 -0
Added +16 -0
Modified +0 -2
Modified +2 -0
Modified +27 -1
diff --git a/NewLife.YuqueWeb/Areas/Yuque/Controllers/DocumentController.cs b/NewLife.YuqueWeb/Areas/Yuque/Controllers/DocumentController.cs
index 068c6dd..c69e2c1 100644
--- a/NewLife.YuqueWeb/Areas/Yuque/Controllers/DocumentController.cs
+++ b/NewLife.YuqueWeb/Areas/Yuque/Controllers/DocumentController.cs
@@ -1,7 +1,9 @@
-using NewLife.Cube;
+using Microsoft.AspNetCore.Mvc;
+using NewLife.Cube;
 using NewLife.Cube.ViewModels;
 using NewLife.Web;
 using NewLife.YuqueWeb.Entity;
+using NewLife.YuqueWeb.Services;
 using XCode.Membership;
 
 namespace NewLife.YuqueWeb.Areas.Yuque.Controllers
@@ -13,6 +15,14 @@ namespace NewLife.YuqueWeb.Areas.Yuque.Controllers
     [Menu(80)]
     public class DocumentController : EntityController<Document>
     {
+        private readonly BookService _bookService;
+
+        /// <summary>
+        /// 实例化知识库管理
+        /// </summary>
+        /// <param name="bookService"></param>
+        public DocumentController(BookService bookService) => _bookService = bookService;
+
         static DocumentController()
         {
             LogOnChange = true;
@@ -50,5 +60,21 @@ namespace NewLife.YuqueWeb.Areas.Yuque.Controllers
 
             return Document.Search(null, null, bookId, start, end, p["Q"], p);
         }
+
+        /// <summary>同步知识库</summary>
+        /// <returns></returns>
+        [EntityAuthorize(PermissionFlags.Update)]
+        public async Task<ActionResult> SyncAll()
+        {
+            var count = 0;
+            var ids = GetRequest("keys").SplitAsInt();
+            foreach (var id in ids.OrderBy(e => e))
+            {
+                var doc = Document.FindById(id);
+                if (doc != null) count += await _bookService.Sync(doc);
+            }
+
+            return JsonRefresh($"共刷新[{count}]篇文章");
+        }
     }
 }
\ No newline at end of file
Added +10 -0
diff --git a/NewLife.YuqueWeb/Areas/Yuque/Views/Document/_List_Search.cshtml b/NewLife.YuqueWeb/Areas/Yuque/Views/Document/_List_Search.cshtml
new file mode 100644
index 0000000..d102a79
--- /dev/null
+++ b/NewLife.YuqueWeb/Areas/Yuque/Views/Document/_List_Search.cshtml
@@ -0,0 +1,10 @@
+@using NewLife;
+@using NewLife.Web;
+@using NewLife.Cube;
+@using XCode;
+@{
+    var fact = ViewBag.Factory as IEntityFactory;
+    var page = ViewBag.Page as Pager;
+}
+@await Html.PartialAsync("_Enable", "")
+@await Html.PartialAsync("_DateRange")
\ No newline at end of file
Added +16 -0
diff --git a/NewLife.YuqueWeb/Areas/Yuque/Views/Document/_List_Toolbar_Batch.cshtml b/NewLife.YuqueWeb/Areas/Yuque/Views/Document/_List_Toolbar_Batch.cshtml
new file mode 100644
index 0000000..81130f5
--- /dev/null
+++ b/NewLife.YuqueWeb/Areas/Yuque/Views/Document/_List_Toolbar_Batch.cshtml
@@ -0,0 +1,16 @@
+@using NewLife.Common;
+@using NewLife
+@using NewLife.Cube
+@using NewLife.Reflection
+@using NewLife.Web
+@using XCode
+@using XCode.Membership
+@{
+    var set = ViewBag.PageSetting as PageSetting;
+}
+@if (set.EnableSelect)
+{
+    <button type="button" class="btn btn-purple btn-sm" data-action="action" data-url="@Url.Action("SyncAll")" data-fields="keys" disabled>
+        批量同步
+    </button>
+}
\ No newline at end of file
Modified +0 -2
diff --git a/NewLife.YuqueWeb/Controllers/YuqueController.cs b/NewLife.YuqueWeb/Controllers/YuqueController.cs
index ed5485a..4346db9 100644
--- a/NewLife.YuqueWeb/Controllers/YuqueController.cs
+++ b/NewLife.YuqueWeb/Controllers/YuqueController.cs
@@ -168,8 +168,6 @@ namespace NewLife.YuqueWeb.Controllers
             var att = Attachment.FindById(id.ToLong());
             if (att == null) return NotFound();
 
-            var set = NewLife.Cube.Setting.Current;
-
             // 如果附件不存在,则抓取
             var filePath = att.GetFilePath();
             if (filePath.IsNullOrEmpty() || !System.IO.File.Exists(filePath))
Modified +2 -0
diff --git a/NewLife.YuqueWeb/Services/BookService.cs b/NewLife.YuqueWeb/Services/BookService.cs
index 301e4b8..0e9f4ff 100644
--- a/NewLife.YuqueWeb/Services/BookService.cs
+++ b/NewLife.YuqueWeb/Services/BookService.cs
@@ -400,12 +400,14 @@ public class BookService
         var url = att.Source;
         if (url.IsNullOrEmpty()) return 0;
 
+        using var span = _tracer.NewSpan(nameof(FetchAttachment), url);
         try
         {
             await att.Fetch(url);
         }
         catch (Exception ex)
         {
+            span.SetError(ex, att);
             XTrace.WriteException(ex);
 
             return 0;