导入 AKSRT 主题开发源码

This commit is contained in:
Claude Code committed 2026-07-03 22:50:34 +08:00
1 parent 9681dd3d48
commit 1268a55dd0
595 files changed
+127705

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
/**
* AKSRT Admin API Client
*
* Communicates with the WordPress REST API at /wp-json/aksrt/v1.
* Methods are organized into domain modules while the client keeps the shared
* request pipeline and schema-domain normalization contract.
*/
import { apiMethods } from './modules/index.js'
const API_ROOT = window.aksrtAdminData?.apiUrl || '/wp-json/aksrt/v1'
const NONCE = window.aksrtAdminData?.nonce || ''
function normalizeDomainKey(domain) {
return String(domain || 'global').trim().replace(/-/g, '_')
}
class ApiClient {
constructor() {
this.baseUrl = API_ROOT
}
normalizeDomainKey(domain) {
return normalizeDomainKey(domain)
}
async request(endpointOrConfig, options = {}) {
// Dual-signature support:
// request('/forum/overview')
// request({ url: '/aksrt/v1/forum/topics', method: 'GET', params: { limit: 20 } })
// request({ url: '/aksrt/v1/verify/review', method: 'POST', data: { user_id: 1 } })
let endpoint, method, headers, params, body, rest
if (typeof endpointOrConfig === 'object' && endpointOrConfig !== null) {
const cfg = endpointOrConfig
endpoint = cfg.url || cfg.endpoint || ''
method = cfg.method || 'GET'
params = cfg.params
body = cfg.data
headers = cfg.headers
rest = { ...cfg }
delete rest.url; delete rest.endpoint; delete rest.method
delete rest.params; delete rest.data; delete rest.headers
} else {
endpoint = endpointOrConfig
method = options.method || 'GET'
params = options.params
body = options.body !== undefined ? options.body : options.data
headers = options.headers
rest = { ...options }
delete rest.method; delete rest.params; delete rest.body
delete rest.data; delete rest.headers
}
if (endpoint.startsWith('/wp-json/aksrt/v1')) {
endpoint = endpoint.replace('/wp-json/aksrt/v1', '') || '/'
} else if (endpoint.startsWith('/aksrt/v1')) {
endpoint = endpoint.replace('/aksrt/v1', '') || '/'
}
let url = `${this.baseUrl}${endpoint}`
if (params && typeof params === 'object') {
const qs = new URLSearchParams(params).toString()
if (qs) url += (url.includes('?') ? '&' : '?') + qs
}
let finalBody = body
if (body !== undefined && typeof body === 'object' && !(body instanceof FormData)) {
finalBody = JSON.stringify(body)
}
const config = {
method,
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': NONCE,
...headers,
},
...rest,
}
if (finalBody !== undefined && method !== 'GET') {
config.body = finalBody
}
try {
const response = await fetch(url, config)
const text = await response.text()
let data = {}
try {
data = text ? JSON.parse(text) : {}
} catch {
throw new Error(
`REST 返回非 JSON,endpoint=${endpoint},status=${response.status},body=${text.slice(0, 160)}`
)
}
if (!response.ok || data.success === false) {
const msg = data.message || data.data?.message || `HTTP ${response.status}`
if (response.status === 403 || response.status === 401) {
console.warn(`[API Auth] ${endpoint}: ${msg} — 可能需要刷新页面重新登录`)
}
throw new Error(msg)
}
return data
} catch (error) {
console.error(`[API Error] ${endpoint}:`, error)
throw error
}
}
}
Object.assign(ApiClient.prototype, apiMethods)
export { normalizeDomainKey }
export default new ApiClient()
@@ -0,0 +1,8 @@
export const extensionsApiMethods = {
/* ================================================================
* 扩展&增强 (Extensions)
* ================================================================ */
testIpGeo(ip) { return this.request('/extensions/ip-test', { method: 'POST', body: JSON.stringify({ ip }) }) },
testContentAudit(text) { return this.request('/extensions/audit-test', { method: 'POST', body: JSON.stringify({ text }) }) },
}
+28
View File
@@ -0,0 +1,28 @@
export const globalApiMethods = {
/* ================================================================
* 全局&功能 (Global & Functions)
* ================================================================ */
getMailSettings() { return this.request('/settings/mail') },
saveMailSettings(data) { return this.request('/settings/mail', { method: 'POST', body: JSON.stringify(data) }) },
testMail(to) { return this.request('/mail/test', { method: 'POST', body: JSON.stringify({ to }) }) },
getFooterSettings() { return this.request('/settings/footer') },
saveFooterSettings(data) { return this.request('/settings/footer', { method: 'POST', body: JSON.stringify(data) }) },
getFooterTabbarSettings() { return this.request('/settings/footer-tabbar') },
saveFooterTabbarSettings(data) { return this.request('/settings/footer-tabbar', { method: 'POST', body: JSON.stringify(data) }) },
reorderFooterTabbar(ids) { return this.request('/settings/footer-tabbar/reorder', { method: 'POST', body: JSON.stringify({ ids }) }) },
getFloatingButtons() { return this.request('/settings/floating-buttons') },
saveFloatingButtons(data) { return this.request('/settings/floating-buttons', { method: 'POST', body: JSON.stringify(data) }) },
reorderFloatingButtons(ids) { return this.request('/settings/floating-buttons/reorder', { method: 'POST', body: JSON.stringify({ ids }) }) },
getFriendLinks() { return this.request('/friend-links') },
addFriendLink(data) { return this.request('/friend-links', { method: 'POST', body: JSON.stringify(data) }) },
deleteFriendLink(id) { return this.request(`/friend-links/${id}`, { method: 'DELETE' }) },
reorderFriendLinks(ids) { return this.request('/friend-links/reorder', { method: 'POST', body: JSON.stringify({ ids }) }) },
getCmsFeatures() { return this.request('/settings/cms-features') },
saveCmsFeatures(cms_features) { return this.request('/settings/cms-features', { method: 'POST', body: JSON.stringify({ cms_features }) }) },
}
+19
View File
@@ -0,0 +1,19 @@
import { globalApiMethods } from './global.js'
import { pageDisplayApiMethods } from './page-display.js'
import { permissionsApiMethods } from './permissions.js'
import { usersApiMethods } from './users.js'
import { paymentApiMethods } from './payment.js'
import { extensionsApiMethods } from './extensions.js'
import { toolsApiMethods } from './tools.js'
import { schemaApiMethods } from './schema.js'
export const apiMethods = {
...globalApiMethods,
...pageDisplayApiMethods,
...permissionsApiMethods,
...usersApiMethods,
...paymentApiMethods,
...extensionsApiMethods,
...toolsApiMethods,
...schemaApiMethods,
}
@@ -0,0 +1,30 @@
export const pageDisplayApiMethods = {
/* ================================================================
* 页面&显示 (Page Display)
* ================================================================ */
getHomepageSettings() { return this.request('/settings/homepage') },
saveHomepageSettings(data) { return this.request('/settings/homepage', { method: 'POST', body: JSON.stringify(data) }) },
getHomepageCategories() { return this.request('/homepage/categories') },
getCategoryRecommendSettings() { return this.request('/settings/category-recommend') },
saveCategoryRecommendSettings(data) { return this.request('/settings/category-recommend', { method: 'POST', body: JSON.stringify(data) }) },
getCategories() { return this.request('/categories') },
updateCategoryMeta(id, data) { return this.request(`/categories/${id}/meta`, { method: 'POST', body: JSON.stringify(data) }) },
searchUsers(search = '', number = 20) { return this.request(`/users/search?search=${encodeURIComponent(search)}&number=${number}`) },
getBanners(kind = 'hero') { return this.request(`/banners?kind=${encodeURIComponent(kind)}`) },
createBanner(data) { return this.request('/banners', { method: 'POST', body: JSON.stringify(data) }) },
updateBanner(id, data) { return this.request(`/banners/${id}`, { method: 'PUT', body: JSON.stringify(data) }) },
deleteBanner(id) { return this.request(`/banners/${id}`, { method: 'DELETE' }) },
getHeroes() { return this.getBanners('hero') },
createHero(data) { return this.createBanner({ ...data, kind: 'hero' }) },
updateHero(id, data) { return this.updateBanner(id, { ...data, kind: 'hero' }) },
deleteHero(id) { return this.deleteBanner(id) },
getHomepageBanners() { return this.getBanners('banner') },
createHomepageBanner(data) { return this.createBanner({ ...data, kind: 'banner' }) },
updateHomepageBanner(id, data) { return this.updateBanner(id, { ...data, kind: 'banner' }) },
deleteHomepageBanner(id) { return this.deleteBanner(id) },
}
+7
View File
@@ -0,0 +1,7 @@
export const paymentApiMethods = {
/* ================================================================
* 支付&付费 (Payment)
* ================================================================ */
getPaymentOverview() { return this.request('/payment/overview') },
}
@@ -0,0 +1,17 @@
export const permissionsApiMethods = {
/* ================================================================
* 功能&权限 (Permissions)
* ================================================================ */
getPermissionsAttachmentSettings() { return this.getSchemaPage('permissions', 'attachment') },
savePermissionsAttachmentSettings(data) { return this.saveSchemaPage('permissions', 'attachment', data) },
getPermissionsLoginSettings() { return this.getSchemaPage('permissions', 'login') },
savePermissionsLoginSettings(data) { return this.saveSchemaPage('permissions', 'login', data) },
getPermissionsModerationSettings() { return this.getSchemaPage('permissions', 'moderation') },
savePermissionsModerationSettings(data) { return this.saveSchemaPage('permissions', 'moderation', data) },
getCapabilities() { return this.request('/permissions/capabilities') },
saveCapabilities(user_caps) { return this.request('/permissions/capabilities', { method: 'POST', body: JSON.stringify({ user_caps }) }) },
}
+17
View File
@@ -0,0 +1,17 @@
export const schemaApiMethods = {
getSchema(domain) { return this.request(`/settings/schema/${domain}`) },
getSchemaPage(domain, section) {
return this.request(`/settings/schema/${this.normalizeDomainKey(domain)}/${encodeURIComponent(section)}`)
},
saveSchemaPage(domain, section, data, version = '1.0.0') {
return this.request(`/settings/schema/${this.normalizeDomainKey(domain)}/${encodeURIComponent(section)}`, {
method: 'POST',
body: JSON.stringify({
domain: this.normalizeDomainKey(domain),
section,
data,
version,
}),
})
},
}
+28
View File
@@ -0,0 +1,28 @@
export const toolsApiMethods = {
/* ================================================================
* 扩展&增强 / 备份&导入 (Extensions & Tools)
* ================================================================ */
getHealthEmailVerification() { return this.request('/health/email-verification') },
getUpdateInfo() { return this.request('/tools/update-info') },
detectUpdate() { return this.request('/tools/update-check', { method: 'POST', body: JSON.stringify({}) }) },
dismissUpdate(version) { return this.request('/tools/update-dismiss', { method: 'POST', body: JSON.stringify({ version }) }) },
getEmailRollbackUsers() { return this.request('/email-rollback/users') },
executeEmailRollback(id) { return this.request(`/email-rollback/users/${id}/rollback`, { method: 'POST' }) },
/* ================================================================
* Settings Management (Import / Export / Reset / Health / Schema)
* ================================================================ */
exportSettings() { return this.request('/settings/export') },
importSettings(data) { return this.request('/settings/import', { method: 'POST', body: JSON.stringify(data) }) },
listSettingBackups() { return this.request('/settings/backups') },
createSettingBackup(data = {}) { return this.request('/settings/backups', { method: 'POST', body: JSON.stringify(data) }) },
restoreSettingBackup(id) { return this.request(`/settings/backups/${id}/restore`, { method: 'POST' }) },
deleteSettingBackup(id) { return this.request(`/settings/backups/${id}`, { method: 'DELETE' }) },
resetDomain(domain) { return this.request(`/settings/reset/${domain}`, { method: 'POST' }) },
resetAllSettings() { return this.request('/settings/reset-all', { method: 'POST' }) },
getHealthCheck() { return this.request('/settings/health') },
getMigrationStatus() { return this.request('/settings/migration-status') },
}
+36
View File
@@ -0,0 +1,36 @@
export const usersApiMethods = {
/* ================================================================
* 用户&互动 (User & Interaction)
* ================================================================ */
getAuthSettings() { return this.request('/settings/auth') },
saveAuthSettings(data) { return this.request('/settings/auth', { method: 'POST', body: JSON.stringify(data) }) },
getOAuthSettings() { return this.request('/settings/oauth') },
saveOAuthSettings(data) { return this.request('/settings/oauth', { method: 'POST', body: JSON.stringify(data) }) },
getNotificationSettings() { return this.request('/settings/notifications') },
saveNotificationSettings(data) { return this.request('/settings/notifications', { method: 'POST', body: JSON.stringify(data) }) },
getNotificationOverview(params = {}) {
const qs = new URLSearchParams(params).toString()
return this.request('/notifications/overview' + (qs ? `?${qs}` : ''))
},
markNotificationRead(id) { return this.request('/notifications/mark-read', { method: 'POST', body: JSON.stringify({ id }) }) },
markAllNotificationsRead() { return this.request('/notifications/mark-read', { method: 'POST', body: JSON.stringify({ mark_all: true }) }) },
deleteNotification(id) { return this.request(`/notifications/${id}`, { method: 'DELETE' }) },
runNotificationCleanup() { return this.request('/notifications/cleanup', { method: 'POST', body: JSON.stringify({}) }) },
getCreditSettings() { return this.request('/credits/settings') },
saveCreditSettings(data) { return this.request('/credits/settings', { method: 'POST', body: JSON.stringify(data) }) },
listCreditUsers(params = {}) {
const qs = new URLSearchParams(params).toString()
return this.request('/credits/users' + (qs ? `?${qs}` : ''))
},
adjustUserCredits(id, delta, reason) {
return this.request(`/credits/users/${id}/adjust`, { method: 'POST', body: JSON.stringify({ delta, reason }) })
},
getCreditLog(params = {}) {
const qs = new URLSearchParams(params).toString()
return this.request('/credits/log' + (qs ? `?${qs}` : ''))
},
}