Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Go 可直接提供构建后的 SPA,也可由 nginx / 静态服务器提供 `we
| 研究印象 | `/impression/` 或顶栏 | 最长 4000 字,按当前账号保存 |
| 账号 | `/login` | 本地登录、邀请注册、恢复、FastCAS、Research 导入及持续连接 |

arXiv 导读默认打开最近有预印本的采集日。`GET /api/news?source=arxiv` 与 `source=security` 分别返回对应范围的最近非空日期及内容;指定 `date` 时保留该日期,即使该范围当天为空。不指定来源时保留总览使用的全部资讯行为。

原 `/index.html`、各栏目 `/index.html`、`/auth/login`、`/auth/account` 和 `?date=YYYY-MM-DD` 继续可用。原 `top-conf/data/report/`、`secnews/data/report/` 下的 HTML/PDF 地址保持;`?download=1` 返回附件。前端已重构为 FastUI 工作台:分组导航面板、页签报告库和手机导航弹窗;旧自定义 CSS 已全部删除。视觉与控件直接使用 FastUI,宿主布局使用 UnoCSS 工具类,论文筛选条件随 URL 保存。实现约定见 [FastUI 接入说明](docs/FASTUI.md)。

研究趋势使用已有 arXiv 采集档案,不请求外部模型。`GET /api/trend?scope=ai&days=30` 按 UTC 采集日比较相邻等长窗口,以档案最新论文日为统计终点。按 arXiv ID 去重,覆盖现有 AI/NLP、安全和软件工程订阅及其中的交叉分类,不代表全量 arXiv 或引用影响力。
Expand Down
6 changes: 5 additions & 1 deletion internal/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (c *Catalog) Papers() ([]Paper, error) {
return nil, e
}
for _, r := range rows {
if !strings.Contains(strings.ToLower(Str(r, "source")), "arxiv") {
if !IsArxivSource(Str(r, "source")) {
continue
}
id := First(Str(r, "_id"), Str(r, "link"))
Expand All @@ -239,6 +239,10 @@ func (c *Catalog) Papers() ([]Paper, error) {
return append([]Paper(nil), out...), nil
}

func IsArxivSource(source string) bool {
return strings.Contains(strings.ToLower(source), "arxiv")
}

var nonTitle = regexp.MustCompile(`[^a-z0-9]+`)
var paperNumberRE = regexp.MustCompile(`(?i)\s*\(paper\s+\d+\)\s*`)

Expand Down
30 changes: 27 additions & 3 deletions internal/httpapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,38 @@ func (s *Server) catalogHTTP(w http.ResponseWriter, r *http.Request, p string) e
}
reply(w, r, 200, map[string]any{"reports": v})
case "/api/news":
source := r.URL.Query().Get("source")
if source != "" && source != "all" && source != "arxiv" && source != "security" {
return store.Fail(400, "资讯来源范围无效")
}
selectRows := func(rows []map[string]any) []map[string]any {
if source == "" || source == "all" {
return rows
}
selected := []map[string]any{}
for _, row := range rows {
if catalog.IsArxivSource(catalog.Str(row, "source")) == (source == "arxiv") {
selected = append(selected, row)
}
}
return selected
}
day := r.URL.Query().Get("date")
if day == "" {
days, e := s.Catalog.Dates()
if e != nil {
return e
}
if len(days) > 0 {
day = days[0]
for _, candidate := range days {
rows, err := s.Catalog.News(candidate)
if err != nil {
return err
}
rows = selectRows(rows)
if source == "" || source == "all" || len(rows) > 0 {
reply(w, r, 200, map[string]any{"date": candidate, "articles": rows})
return nil
}
}
}
if day == "" {
Expand All @@ -282,7 +306,7 @@ func (s *Server) catalogHTTP(w http.ResponseWriter, r *http.Request, p string) e
if e != nil {
return e
}
reply(w, r, 200, map[string]any{"date": day, "articles": v})
reply(w, r, 200, map[string]any{"date": day, "articles": selectRows(v)})
default:
papers, e := s.Catalog.Papers()
if e != nil {
Expand Down
40 changes: 40 additions & 0 deletions internal/httpapi/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,46 @@ func TestGenerationPreservesExplicitImpressionWhileDefaultingOmittedField(t *tes
}
}

func TestNewsScopeSelectsLatestPopulatedArchiveDate(t *testing.T) {
h := fixture(t)
directory := filepath.Join(h.app.Config.Root, "secnews/data/articles")
files := map[string]string{
"2026-11-20": `{"_id":"news","title":"Security news","source":"bleepingcomputer"}`,
"2026-11-18": `{"_id":"paper","title":"Research paper","source":"arxiv_cs_se"}`,
}
for day, content := range files {
if err := os.WriteFile(filepath.Join(directory, day+".jsonl"), []byte(content), 0600); err != nil {
t.Fatal(err)
}
}
for _, test := range []struct {
query, date, id string
count int
}{
{"", "2026-11-20", "news", 1},
{"?source=arxiv", "2026-11-18", "paper", 1},
{"?source=security", "2026-11-20", "news", 1},
{"?source=arxiv&date=2026-11-20", "2026-11-20", "", 0},
{"?source=security&date=2026-11-18", "2026-11-18", "", 0},
} {
status, result, _ := h.request(t, "GET", "/api/news"+test.query, nil, "", false)
if status != 200 || result["date"] != test.date {
t.Fatal(test.query, status, result)
}
articles := result["articles"].([]any)
if len(articles) != test.count {
t.Fatal(test.query, articles)
}
if test.count > 0 && articles[0].(map[string]any)["_id"] != test.id {
t.Fatal(test.query, articles)
}
}
status, _, _ := h.request(t, "GET", "/api/news?source=unknown", nil, "", false)
if status != 400 {
t.Fatal("unknown archive scope accepted", status)
}
}

func TestReleaseSymlinkAndReportAssets(t *testing.T) {
h := fixture(t)
link := filepath.Join(t.TempDir(), "current")
Expand Down
5 changes: 0 additions & 5 deletions web/src/news.ts

This file was deleted.

25 changes: 17 additions & 8 deletions web/src/pages/Arxiv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { useSearchParams } from 'react-router-dom'
import { EmptyState, Select, Toolbar } from '@fastrd/ui-react'
import { api, message } from '../api'
import { useApp } from '../context'
import { isArxiv } from '../news'
import type { NewsArticle } from '../types'
import { Busy, ErrorMessage, PageHeading, Pagination, Panel, PaperCard } from '../components/Common'

export default function Arxiv() {
const { catalog } = useApp()
const [params, setParams] = useSearchParams()
const date = params.get('date') || catalog?.dates[0] || ''
const requestedDate = params.get('date') || ''
const [resolvedDate, setResolvedDate] = useState('')
const date = requestedDate || resolvedDate
const category = params.get('category') || ''
const requestedPage = Math.max(1, Math.floor(Number(params.get('page')) || 1))
const [articles, setArticles] = useState<NewsArticle[]>([])
Expand All @@ -27,23 +28,28 @@ export default function Arxiv() {
})
}
useEffect(() => {
if (!date) return
const abort = new AbortController()
setBusy(true)
setError('')
setArticles([])
api<{ articles: NewsArticle[] }>(`api/news?${new URLSearchParams({ date })}`, {
signal: abort.signal,
})
.then((value) => setArticles(value.articles.filter(isArxiv)))
api<{ date: string; articles: NewsArticle[] }>(
`api/news?${new URLSearchParams({ source: 'arxiv', ...(requestedDate ? { date: requestedDate } : {}) })}`,
{
signal: abort.signal,
},
)
.then((value) => {
setResolvedDate(value.date)
setArticles(value.articles)
})
.catch((error) => {
if (!abort.signal.aborted) setError(message(error))
})
.finally(() => {
if (!abort.signal.aborted) setBusy(false)
})
return () => abort.abort()
}, [date])
}, [requestedDate])
const categories = [...new Set(articles.flatMap((article) => article.categories || []))].sort()
const filtered = articles.filter((article) => !category || article.categories?.includes(category))
const page = Math.min(requestedPage, Math.max(1, Math.ceil(filtered.length / 12)))
Expand All @@ -62,6 +68,9 @@ export default function Arxiv() {
value={date}
onChange={(event) => filter('date', event.target.value)}
>
<option value="" disabled>
选择采集日期
</option>
{(catalog?.dates || []).map((day) => (
<option key={day}>{day}</option>
))}
Expand Down
48 changes: 27 additions & 21 deletions web/src/pages/News.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@fastrd/ui-react'
import { ChevronLeft, ChevronRight, ExternalLink } from 'lucide-react'
import { api, message, safeURL } from '../api'
import { isArxiv } from '../news'
import { useApp } from '../context'
import type { NewsArticle } from '../types'
import { Busy, ErrorMessage, PageHeading, Panel, ReportList } from '../components/Common'
Expand All @@ -35,31 +34,38 @@ function score(a: NewsArticle) {
export default function News() {
const { catalog } = useApp()
const [params, setParams] = useSearchParams()
const date = params.get('date') || catalog?.dates[0] || ''
const requestedDate = params.get('date') || ''
const [resolvedDate, setResolvedDate] = useState('')
const date = requestedDate || resolvedDate
const [month, setMonth] = useState(''),
[articles, setArticles] = useState<NewsArticle[]>([]),
[busy, setBusy] = useState(false),
[error, setError] = useState(''),
[kind, setKind] = useState('all'),
[showAll, setShowAll] = useState(false)
useEffect(() => {
if (date) {
setMonth(date.slice(0, 7))
const abort = new AbortController()
setBusy(true)
setError('')
setShowAll(false)
api<{ articles: NewsArticle[] }>(`api/news?date=${date}`, { signal: abort.signal })
.then((v) => setArticles(v.articles.filter((article) => !isArxiv(article))))
.catch((e) => {
if (!abort.signal.aborted) setError(message(e))
})
.finally(() => {
if (!abort.signal.aborted) setBusy(false)
})
return () => abort.abort()
}
}, [date])
const abort = new AbortController()
setBusy(true)
setError('')
setArticles([])
setShowAll(false)
api<{ date: string; articles: NewsArticle[] }>(
`api/news?${new URLSearchParams({ source: 'security', ...(requestedDate ? { date: requestedDate } : {}) })}`,
{ signal: abort.signal },
)
.then((v) => {
setResolvedDate(v.date)
setMonth(v.date.slice(0, 7))
setArticles(v.articles)
})
.catch((e) => {
if (!abort.signal.aborted) setError(message(e))
})
.finally(() => {
if (!abort.signal.aborted) setBusy(false)
})
return () => abort.abort()
}, [requestedDate])
const available = useMemo(() => new Set(catalog?.dates || []), [catalog])
const first = new Date(
`${month || date.slice(0, 7) || new Date().toISOString().slice(0, 7)}-01T00:00:00`,
Expand Down Expand Up @@ -122,7 +128,7 @@ export default function News() {
<Button
key={day}
variant={day === date ? 'primary' : 'quiet'}
title={available.has(day) ? '当天有资讯' : '当天无资讯'}
title={available.has(day) ? '当天有采集档案' : '当天无采集档案'}
aria-label={day}
aria-pressed={day === date}
disabled={!available.has(day)}
Expand All @@ -133,7 +139,7 @@ export default function News() {
)
})}
</div>
<p className="text-[var(--fastui-muted)]">可选日期表示当天有资讯</p>
<p className="text-[var(--fastui-muted)]">可选日期为已归档的采集日</p>
</div>
</Panel>
<Panel title="安全资讯周报">
Expand Down
8 changes: 8 additions & 0 deletions web/tests/workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ test('arXiv navigation, dated corpus, fields, pagination and reading use real AP
if (info.project.name === 'mobile') await page.getByRole('button', { name: '打开导航' }).click()
await page.getByRole('link', { name: 'arXiv 导读', exact: true }).click()
await expect(page.getByRole('heading', { name: 'arXiv 最新导读', level: 1 })).toBeVisible()
const latestArxiv = await (await page.request.get(route(baseURL, 'api/news?source=arxiv'))).json()
await expect(page.getByLabel('采集日期', { exact: true })).toHaveValue(latestArxiv.date)
await page.getByLabel('采集日期', { exact: true }).selectOption(date)
await expect(page.getByTestId('paper-row')).toHaveCount(12)
await expect(page.getByTestId('paper-row').first()).toContainText(papers[0].title)
Expand Down Expand Up @@ -193,6 +195,12 @@ test('all old entries, real catalog, downloads, calendar, theme and responsive l
expect(response.status()).toBe(200)
expect(response.headers()['content-disposition']).toContain('attachment')
await visit(page, baseURL, 'secnews/')
const latestSecurity = await (
await page.request.get(route(baseURL, 'api/news?source=security'))
).json()
await expect(
page.getByRole('heading', { name: `${latestSecurity.date} · 每日资讯`, exact: true }),
).toBeVisible()
await expect(page.getByTestId('news-row').first()).toBeVisible()
await page.getByRole('button', { name: '上个月' }).click()
await expect(page.getByTestId('calendar')).toBeVisible()
Expand Down
Loading