From 821f0b909df65cd2b6cd1dae39aa9d35dc05b950 Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Mon, 6 Jul 2026 01:26:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B5=E9=9D=A2=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0authType=E8=AE=A4=E8=AF=81=E6=96=B9=E5=BC=8F(?= =?UTF-8?q?NONE/COOKIE/TOKEN/BASIC/API=5FKEY)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/SitePagesController.java | 18 ++++--- .../par/core/service/SitePagesService.java | 2 + .../service/impl/SitePagesServiceImpl.java | 11 ++++- web/src/views/SitePages.vue | 47 ++++++++++++++++--- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/par-api/src/main/java/com/par/api/controller/SitePagesController.java b/par-api/src/main/java/com/par/api/controller/SitePagesController.java index b0d8158..89ba5c7 100644 --- a/par-api/src/main/java/com/par/api/controller/SitePagesController.java +++ b/par-api/src/main/java/com/par/api/controller/SitePagesController.java @@ -48,12 +48,14 @@ public class SitePagesController { @PutMapping("/api/v1/sites/{siteId}/pages") public ApiResponse savePages( @PathVariable String siteId, @RequestBody Map payload) { - @SuppressWarnings("unchecked") - var entries = (List>) payload.get("entries"); - if (entries == null || entries.isEmpty()) return ApiResponse.error(400, "entries is required"); - sitePagesService.savePages(siteId, entries); - return ApiResponse.success(); - } + @SuppressWarnings("unchecked") + var entries = (List>) payload.get("entries"); + if (entries == null || entries.isEmpty()) return ApiResponse.error(400, "entries is required"); + String authType = (String) payload.get("authType"); + String authValue = (String) payload.get("authValue"); + sitePagesService.savePages(siteId, entries, authType, authValue); + return ApiResponse.success(); +} @GetMapping("/api/v1/admin/site-pages") public ApiResponse>> adminList(HttpServletRequest request) { @@ -115,7 +117,9 @@ public class SitePagesController { checkAdmin(request); @SuppressWarnings("unchecked") var entries = (List>) payload.get("entries"); - sitePagesService.savePages("default:" + type, entries != null ? entries : List.of()); + String authType = (String) payload.get("authType"); + String authValue = (String) payload.get("authValue"); + sitePagesService.savePages("default:" + type, entries != null ? entries : List.of(), authType, authValue); return ApiResponse.success(); } diff --git a/par-core/src/main/java/com/par/core/service/SitePagesService.java b/par-core/src/main/java/com/par/core/service/SitePagesService.java index 2e0716f..8ca5771 100644 --- a/par-core/src/main/java/com/par/core/service/SitePagesService.java +++ b/par-core/src/main/java/com/par/core/service/SitePagesService.java @@ -10,6 +10,8 @@ public interface SitePagesService { String getVersion(String siteId); /** 保存/更新页面配置 */ void savePages(String siteId, List> entries); + /** 保存/更新页面配置(含认证方式) */ + void savePages(String siteId, List> entries, String authType, String authValue); /** 获取所有站点页面配置列表(管理员) */ List> listAll(); /** 删除站点页面配置 */ diff --git a/par-core/src/main/java/com/par/core/service/impl/SitePagesServiceImpl.java b/par-core/src/main/java/com/par/core/service/impl/SitePagesServiceImpl.java index 329e59a..400face 100644 --- a/par-core/src/main/java/com/par/core/service/impl/SitePagesServiceImpl.java +++ b/par-core/src/main/java/com/par/core/service/impl/SitePagesServiceImpl.java @@ -53,8 +53,17 @@ public class SitePagesServiceImpl implements SitePagesService { @Override public void savePages(String siteId, List> entries) { + savePages(siteId, entries, null, null); + } + + @Override + public void savePages(String siteId, List> entries, String authType, String authValue) { try { - String json = om.writerWithDefaultPrettyPrinter().writeValueAsString(entries); + Map full = new LinkedHashMap<>(); + full.put("entries", entries); + if (authType != null && !"NONE".equals(authType)) full.put("authType", authType); + if (authValue != null && !authValue.isBlank()) full.put("authValue", authValue); + String json = om.writerWithDefaultPrettyPrinter().writeValueAsString(full); // 版本号递增 String currentVer = getVersion(siteId); int nextVer = 1; diff --git a/web/src/views/SitePages.vue b/web/src/views/SitePages.vue index 62e068c..4e31867 100644 --- a/web/src/views/SitePages.vue +++ b/web/src/views/SitePages.vue @@ -59,8 +59,24 @@
+ +
+
认证方式
+
+ + + + + + + + +
+
+ +
- 页面入口编辑 + 页面入口 + 添加
暂无,点击添加
@@ -88,7 +104,8 @@ import api from '../api'; import { Refresh } from '@element-plus/icons-vue' const loading = ref(false), saving = ref(false), uploading = ref(false), deleting = ref(false), sites = ref([]), pagesMap = ref({}), sitesList = ref([]) -const editSiteId = ref(''), editorJson = ref('[]') +const editSiteId = ref(''), editorJson = ref('{}') +const authType = ref('NONE'), authValue = ref('') const defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d'] const isDefaultEditor = computed(() => editSiteId.value.startsWith('default:')) const pageKeys = ref([]) @@ -104,7 +121,20 @@ const onKeyChange = (row) => { syncToJson() } const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-' -const parsed = computed(() => { try { return JSON.parse(editorJson.value) } catch { return [] } }) +const parsed = computed(() => { try { return JSON.parse(editorJson.value).entries || [] } catch { return [] } }) +const syncAuth = () => { + const obj = (() => { try { return JSON.parse(editorJson.value) } catch { return {} } })() + obj.authType = authType.value + if (authType.value !== 'NONE') obj.authValue = authValue.value + else delete obj.authValue + obj.entries = parsed.value + editorJson.value = JSON.stringify(obj, null, 2) +} +const syncToJson = () => { + const obj = { authType: authType.value, entries: parsed.value } + if (authType.value !== 'NONE') obj.authValue = authValue.value + editorJson.value = JSON.stringify(obj, null, 2) +} const resolveUrl = (url) => url?.replace('{base}', sitesList.value.find(s=>s.siteId===editSiteId.value)?.urls?.[0] || '{base}') || '' const merged = computed(() => (Array.isArray(sitesList.value)?sitesList.value:[]).map(s => ({ siteId: s.siteId, names: s.names, @@ -133,8 +163,13 @@ const editPage = async (row) => { const url = row.siteId.startsWith('default:') ? '/admin/default-pages/' + row.siteId.replace('default:','') : '/admin/site-pages/' + row.siteId - try { const r = await api.raw.get(url); editorJson.value = (r?.data||r)?.entries ? JSON.stringify((r.data||r).entries, null, 2) : '[]' } - catch { editorJson.value = '[]' } + try { + const r = await api.raw.get(url) + const data = r?.data || r + authType.value = data?.authType || 'NONE' + authValue.value = data?.authValue || '' + editorJson.value = JSON.stringify({ authType: authType.value, authValue: authValue.value || undefined, entries: data?.entries || [] }, null, 2) + } catch { editorJson.value = JSON.stringify({ authType:'NONE', entries:[] }, null, 2) } } const syncToJson = () => { editorJson.value = JSON.stringify(parsed.value, null, 2) } @@ -164,7 +199,7 @@ const savePages = async () => { const url = editSiteId.value.startsWith('default:') ? '/admin/default-pages/' + editSiteId.value.replace('default:','') : '/sites/' + editSiteId.value + '/pages' - await api.raw.put(url, { entries: parsed.value }) + await api.raw.put(url, { entries: parsed.value, authType: authType.value, authValue: authType.value!=='NONE'?authValue.value:null }) ElMessage.success('已保存'); editSiteId.value=''; fetchAll() } catch { ElMessage.error('保存失败') } finally { saving.value = false }