2 Commits

Author SHA1 Message Date
44077796f8 feat: 翻译记录添加不共享开关功能
- Translation 模型新增 no_share 字段
- 管理后台翻译记录页面添加共享状态列和切换按钮
- 不共享的翻译不会被其他用户使用缓存
- 缓存匹配时检查是否有 no_share 标记
2026-04-16 19:06:43 +08:00
504fed6c3e fix: 修复网站配置保存问题
- 保存配置时 key 不再加 site_ 前缀,与读取时一致
- 修正:site_site_name -> site_name
- 修正:site_site_footer -> site_footer
2026-04-16 18:49:03 +08:00
4 changed files with 72 additions and 10 deletions

View File

@@ -255,6 +255,28 @@ def delete_translation(trans_id):
return jsonify({'success': True}) return jsonify({'success': True})
@admin_bp.route('/translation/<int:trans_id>/toggle-share', methods=['POST'])
@admin_required
def toggle_translation_share(trans_id):
"""切换翻译共享状态"""
translation = Translation.query.get_or_404(trans_id)
translation.no_share = not translation.no_share
db.session.commit()
# 记录日志
log = OperationLog(
user_id=session.get('user_id'),
username='admin',
action='toggle_translation_share',
target=f'翻译#{trans_id}',
detail=f'设置共享状态为: {not translation.no_share}'
)
db.session.add(log)
db.session.commit()
return jsonify({'success': True, 'no_share': translation.no_share})
# ==================== 缓存管理 ==================== # ==================== 缓存管理 ====================
@admin_bp.route('/cache') @admin_bp.route('/cache')
@admin_required @admin_required
@@ -341,14 +363,14 @@ def save_site_settings():
"""保存网站基础配置""" """保存网站基础配置"""
data = request.json data = request.json
# 保存每个配置项 # 保存每个配置项key 直接使用,不带 site_ 前缀)
for key, value in data.items(): for key, value in data.items():
if key in ['max_file_size', 'cache_expire_days']: if key in ['max_file_size', 'cache_expire_days']:
DynamicConfig.set(f'site_{key}', int(value), category='site', value_type='int', user_id=session.get('user_id')) DynamicConfig.set(key, int(value), category='site', value_type='int', user_id=session.get('user_id'))
elif key in ['enable_email_notify', 'enable_cache', 'enable_guest']: elif key in ['enable_email_notify', 'enable_cache', 'enable_guest']:
DynamicConfig.set(f'site_{key}', bool(value), category='site', value_type='bool', user_id=session.get('user_id')) DynamicConfig.set(key, bool(value), category='site', value_type='bool', user_id=session.get('user_id'))
else: else:
DynamicConfig.set(f'site_{key}', value, category='site', user_id=session.get('user_id')) DynamicConfig.set(key, value, category='site', user_id=session.get('user_id'))
# 记录日志 # 记录日志
log = OperationLog( log = OperationLog(

7
app.py
View File

@@ -365,8 +365,11 @@ def upload_pdf():
cache_path = cache_service.get_cache(file_hash) cache_path = cache_service.get_cache(file_hash)
from_cache = False from_cache = False
if cache_path and ENABLE_CACHE and not instruction: # 检查是否有用户设置了不共享此文件
# 有缓存且无特殊翻译要求,直接使用缓存 no_share_check = Translation.query.filter_by(file_hash=file_hash, no_share=True).first()
if cache_path and ENABLE_CACHE and not instruction and not no_share_check:
# 有缓存且无特殊翻译要求且无不共享标记,直接使用缓存
from_cache = True from_cache = True
output_path = cache_path output_path = cache_path
else: else:

View File

@@ -178,6 +178,9 @@ class Translation(db.Model):
# 是否来自缓存 # 是否来自缓存
from_cache = db.Column(db.Boolean, default=False) from_cache = db.Column(db.Boolean, default=False)
# 不共享缓存
no_share = db.Column(db.Boolean, default=False) # 不共享此翻译给其他用户
# 重译信息 # 重译信息
retranslate_request = db.Column(db.Text, nullable=True) # 重译要求 retranslate_request = db.Column(db.Text, nullable=True) # 重译要求
parent_id = db.Column(db.Integer, db.ForeignKey('translations.id'), nullable=True) # 原翻译ID parent_id = db.Column(db.Integer, db.ForeignKey('translations.id'), nullable=True) # 原翻译ID
@@ -190,6 +193,7 @@ class Translation(db.Model):
'status': self.status, 'status': self.status,
'progress': self.progress, 'progress': self.progress,
'from_cache': self.from_cache, 'from_cache': self.from_cache,
'no_share': self.no_share,
'file_size': self.file_size, 'file_size': self.file_size,
'created_at': self.created_at.isoformat() if self.created_at else None, 'created_at': self.created_at.isoformat() if self.created_at else None,
'completed_at': self.completed_at.isoformat() if self.completed_at else None, 'completed_at': self.completed_at.isoformat() if self.completed_at else None,

View File

@@ -69,13 +69,14 @@
<th>大小</th> <th>大小</th>
<th>状态</th> <th>状态</th>
<th>缓存</th> <th>缓存</th>
<th>共享</th>
<th>时间</th> <th>时间</th>
<th>操作</th> <th>操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for t in translations.items %} {% for t in translations.items %}
<tr> <tr id="trans-row-{{ t.id }}">
<td>{{ t.id }}</td> <td>{{ t.id }}</td>
<td>{{ t.original_filename[:25] }}{% if t.original_filename|length > 25 %}...{% endif %}</td> <td>{{ t.original_filename[:25] }}{% if t.original_filename|length > 25 %}...{% endif %}</td>
<td>{% if t.user_id %}ID:{{ t.user_id }}{% else %}访客{% endif %}</td> <td>{% if t.user_id %}ID:{{ t.user_id }}{% else %}访客{% endif %}</td>
@@ -87,14 +88,26 @@
</span> </span>
</td> </td>
<td>{% if t.from_cache %}<i class="bi bi-check-circle text-success"></i>{% else %}-{% endif %}</td> <td>{% if t.from_cache %}<i class="bi bi-check-circle text-success"></i>{% else %}-{% endif %}</td>
<td>
{% if t.no_share %}
<span class="badge bg-secondary" id="share-badge-{{ t.id }}">不共享</span>
{% else %}
<span class="badge bg-success" id="share-badge-{{ t.id }}">共享</span>
{% endif %}
</td>
<td>{{ t.created_at.strftime('%m-%d %H:%M') }}</td> <td>{{ t.created_at.strftime('%m-%d %H:%M') }}</td>
<td> <td>
<a href="{{ url_for('admin.translation_detail', trans_id=t.id) }}" class="btn btn-sm btn-outline-primary"><i class="bi bi-eye"></i></a> <div class="d-flex gap-1">
<button class="btn btn-sm btn-outline-danger" onclick="deleteTrans({{ t.id }})"><i class="bi bi-trash"></i></button> <button class="btn btn-sm btn-outline-{% if t.no_share %}success{% else %}warning{% endif %}" onclick="toggleShare({{ t.id }})" title="切换共享状态">
<i class="bi bi-share{% if t.no_share %}-fill{% endif %}"></i>
</button>
<a href="{{ url_for('admin.translation_detail', trans_id=t.id) }}" class="btn btn-sm btn-outline-primary"><i class="bi bi-eye"></i></a>
<button class="btn btn-sm btn-outline-danger" onclick="deleteTrans({{ t.id }})"><i class="bi bi-trash"></i></button>
</div>
</td> </td>
</tr> </tr>
{% else %} {% else %}
<tr><td colspan="9" class="text-center text-muted py-4">暂无数据</td></tr> <tr><td colspan="10" class="text-center text-muted py-4">暂无数据</td></tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
@@ -122,6 +135,26 @@
.then(r => r.json()) .then(r => r.json())
.then(d => { if (d.success) location.reload(); }); .then(d => { if (d.success) location.reload(); });
} }
function toggleShare(id) {
fetch(`/admin/translation/${id}/toggle-share`, { method: 'POST' })
.then(r => r.json())
.then(d => {
if (d.success) {
// 更新显示状态
const badge = document.getElementById(`share-badge-${id}`);
if (d.no_share) {
badge.className = 'badge bg-secondary';
badge.textContent = '不共享';
} else {
badge.className = 'badge bg-success';
badge.textContent = '共享';
}
// 更新按钮样式
location.reload(); // 简化处理,刷新页面
}
});
}
</script> </script>
</body> </body>
</html> </html>