fix: v3.0.1 - 修复5个代码问题
修复内容: 1. Collection 模型唯一约束逻辑错误 - 修改约束从 (user_id, site_id, folder_id) 到 (user_id, site_id) - 防止用户多次收藏同一网站 2. 用户注册重复提交数据库 - 优化为只提交一次数据库操作 - 提升注册性能 3. JavaScript 未使用的变量 - 删除 updateCollectButton() 中未使用的 icon 变量 4. 文件夹计数逻辑缺失 - 为每个文件夹添加收藏数量计算 - 修复收藏列表页面显示 5. JavaScript 错误处理不完善 - 所有 fetch 调用添加 HTTP 状态码检查 - 改进网络错误提示 新增文件: - fix_collection_constraint.py - 数据库约束修复脚本 - BUGFIX_v3.0.1.md - 详细修复记录 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1578,7 +1578,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
function checkCollectionStatus() {
|
||||
fetch('/api/auth/status')
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (!data.logged_in || data.user_type !== 'user') {
|
||||
return; // 未登录或非普通用户,不检查收藏状态
|
||||
@@ -1586,7 +1589,10 @@ function checkCollectionStatus() {
|
||||
|
||||
// 已登录,检查收藏状态
|
||||
fetch(`/api/collections/status/${siteCode}`)
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json();
|
||||
})
|
||||
.then(data => {
|
||||
isCollected = data.is_collected;
|
||||
updateCollectButton();
|
||||
@@ -1598,7 +1604,6 @@ function checkCollectionStatus() {
|
||||
|
||||
function updateCollectButton() {
|
||||
const btn = document.getElementById('collectBtn');
|
||||
const icon = document.getElementById('collectIcon');
|
||||
const text = document.getElementById('collectText');
|
||||
|
||||
if (isCollected) {
|
||||
@@ -1613,7 +1618,10 @@ function updateCollectButton() {
|
||||
function toggleCollect() {
|
||||
// 先检查登录状态
|
||||
fetch('/api/auth/status')
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (!data.logged_in) {
|
||||
// 未登录,跳转到登录页
|
||||
@@ -1636,7 +1644,10 @@ function toggleCollect() {
|
||||
},
|
||||
body: JSON.stringify({ site_code: siteCode })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
isCollected = data.action === 'added';
|
||||
|
||||
Reference in New Issue
Block a user