feat: 默认页面模板增加上传按钮+对应后端接口
This commit is contained in:
@@ -17,6 +17,7 @@ public class SitePagesController {
|
|||||||
|
|
||||||
private final SitePagesService sitePagesService;
|
private final SitePagesService sitePagesService;
|
||||||
private final com.par.core.mapper.SiteMapper siteMapper;
|
private final com.par.core.mapper.SiteMapper siteMapper;
|
||||||
|
private final com.par.core.storage.CachedStorageService storageService;
|
||||||
|
|
||||||
@GetMapping("/api/v1/sites/{siteId}/pages")
|
@GetMapping("/api/v1/sites/{siteId}/pages")
|
||||||
public ApiResponse<Map<String, Object>> getPages(@PathVariable String siteId) {
|
public ApiResponse<Map<String, Object>> getPages(@PathVariable String siteId) {
|
||||||
@@ -109,6 +110,21 @@ public class SitePagesController {
|
|||||||
return ApiResponse.success();
|
return ApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 发布默认页面模板到云存储 */
|
||||||
|
@PutMapping("/api/v1/admin/default-pages/{type}/upload")
|
||||||
|
public ApiResponse<Void> uploadDefaultPages(
|
||||||
|
@PathVariable String type, @RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||||||
|
checkAdmin(request);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
var entries = (List<Map<String, Object>>) payload.get("entries");
|
||||||
|
sitePagesService.savePages("default:" + type, entries != null ? entries : List.of());
|
||||||
|
String json = payload.containsKey("entries")
|
||||||
|
? new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(entries)
|
||||||
|
: "[]";
|
||||||
|
storageService.store("pages/default/" + type + ".json", json);
|
||||||
|
return ApiResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
private void checkAdmin(HttpServletRequest request) {
|
private void checkAdmin(HttpServletRequest request) {
|
||||||
var level = request.getAttribute("trustLevel");
|
var level = request.getAttribute("trustLevel");
|
||||||
if (level == null || !"ADMIN".equals(level.toString())) {
|
if (level == null || !"ADMIN".equals(level.toString())) {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
<h2 style="margin:0">编辑: {{ editSiteId }}</h2>
|
<h2 style="margin:0">编辑: {{ editSiteId }}</h2>
|
||||||
<div style="display:flex;gap:8px">
|
<div style="display:flex;gap:8px">
|
||||||
<el-button size="small" type="primary" @click="savePages" :loading="saving">保存</el-button>
|
<el-button size="small" type="primary" @click="savePages" :loading="saving">保存</el-button>
|
||||||
|
<el-button v-if="isDefaultEditor" size="small" @click="uploadPages" :loading="uploading">上传</el-button>
|
||||||
<el-button size="small" type="danger" @click="deletePages" :loading="deleting">删除</el-button>
|
<el-button size="small" type="danger" @click="deletePages" :loading="deleting">删除</el-button>
|
||||||
<el-button size="small" @click="editSiteId=''">返回列表</el-button>
|
<el-button size="small" @click="editSiteId=''">返回列表</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -86,9 +87,10 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import api from '../api'; import { Refresh } from '@element-plus/icons-vue'
|
import api from '../api'; import { Refresh } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
const loading = ref(false), saving = ref(false), deleting = ref(false), sites = ref([]), pagesMap = ref({}), sitesList = ref([])
|
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 defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d']
|
const defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d']
|
||||||
|
const isDefaultEditor = computed(() => editSiteId.value.startsWith('default:'))
|
||||||
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
|
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) } catch { return [] } })
|
||||||
const resolveUrl = (url) => url?.replace('{base}', sitesList.value.find(s=>s.siteId===editSiteId.value)?.urls?.[0] || '{base}') || ''
|
const resolveUrl = (url) => url?.replace('{base}', sitesList.value.find(s=>s.siteId===editSiteId.value)?.urls?.[0] || '{base}') || ''
|
||||||
@@ -134,6 +136,16 @@ const deletePages = async () => {
|
|||||||
finally { deleting.value = false }
|
finally { deleting.value = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uploadPages = async () => {
|
||||||
|
uploading.value = true
|
||||||
|
try {
|
||||||
|
const type = editSiteId.value.replace('default:','')
|
||||||
|
await api.raw.put('/admin/default-pages/'+type+'/upload', { entries: parsed.value })
|
||||||
|
ElMessage.success('已上传到云存储')
|
||||||
|
} catch { ElMessage.error('上传失败') }
|
||||||
|
finally { uploading.value = false }
|
||||||
|
}
|
||||||
|
|
||||||
const savePages = async () => {
|
const savePages = async () => {
|
||||||
saving.value = true
|
saving.value = true
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user