Files
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.

Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
  cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
  window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)

Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
  so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
  (dropped 3 stale entries, added the 17 missing ones)

Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
  get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
  when it is empty

Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.

Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-01 20:05:04 +08:00

176 lines
5.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Jio frontend request adapter.
*
* Owns the injected REST root, nonce headers, response envelopes, and
* abort-aware error normalization used by modal loaders.
*
* @package Jio
*/
(function (window) {
"use strict";
function data() {
return window.jioData || window.jio || {};
}
function createIdempotencyKey() {
if (window.crypto && typeof window.crypto.randomUUID === "function") {
return window.crypto.randomUUID();
}
if (!window.crypto || typeof window.crypto.getRandomValues !== "function") {
throw new Error("当前浏览器无法生成安全的操作标识");
}
var bytes = new Uint8Array(16);
window.crypto.getRandomValues(bytes);
bytes[6] = (bytes[6] & 0x0f) | 0x40;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
var hex = Array.prototype.map.call(bytes, function (value) {
return value.toString(16).padStart(2, "0");
}).join("");
return hex.slice(0, 8) + "-" + hex.slice(8, 12) + "-" + hex.slice(12, 16) + "-" + hex.slice(16, 20) + "-" + hex.slice(20);
}
function restBase() {
var config = data();
var raw = config.restUrl || config.apiUrl || config.rest_url || "";
var siteUrl = config.siteUrl || config.homeUrl || (window.location.origin + "/");
if (window.location.protocol === "https:" && siteUrl.substring(0, 5) === "http:") {
siteUrl = "https:" + siteUrl.substring(5);
}
if (raw) return String(raw).replace(/\/$/, "");
return String(siteUrl).replace(/\/$/, "") + "/index.php?rest_route=/jio/v1";
}
function appendQuery(url, query) {
if (!query) return url;
var parts = [];
if (typeof query === "string") {
parts = query.replace(/^\?/, "").split("&").filter(Boolean);
} else if (typeof query === "object") {
Object.keys(query).forEach(function (key) {
if (query[key] === undefined || query[key] === null) return;
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(String(query[key])));
});
}
if (!parts.length) return url;
return url + (url.indexOf("?") >= 0 ? "&" : "?") + parts.join("&");
}
function url(path, query) {
path = String(path || "");
var inlineQuery = "";
var queryIndex = path.indexOf("?");
if (queryIndex >= 0) {
inlineQuery = path.slice(queryIndex + 1);
path = path.slice(0, queryIndex);
}
if (/^https?:\/\//i.test(path)) {
return appendQuery(path, query || inlineQuery);
}
if (path.charAt(0) !== "/") path = "/" + path;
var base = restBase();
var result = base.indexOf("rest_route=") >= 0 ? base + path : base + path;
return appendQuery(result, query || inlineQuery);
}
function headers(options) {
var config = data();
var source = (options && options.headers) || {};
var result = {};
var nonce = config.restNonce || config.nonce || "";
Object.keys(source).forEach(function (key) {
result[key] = source[key];
});
if (!result.Accept) result.Accept = "application/json, text/html;q=0.9, */*;q=0.8";
if (nonce && !result["X-WP-Nonce"]) result["X-WP-Nonce"] = nonce;
if (options && options.body !== undefined && options.body !== null &&
!(window.FormData && options.body instanceof window.FormData) &&
!result["Content-Type"]) {
result["Content-Type"] = "application/json";
}
return result;
}
function responseError(result) {
var json = result.json;
var message = json && (json.message || (json.data && json.data.message));
var error = new Error(message || (result.status ? "请求失败(HTTP " + result.status + ")" : "请求失败"));
error.status = result.status;
error.code = result.status === 401 ? "unauthorized" : "http_error";
error.response = result;
error.json = json;
return error;
}
function parseResponse(response) {
return response.text().then(function (text) {
var type = (response.headers.get("content-type") || "").toLowerCase();
var json = null;
var trimmed = String(text || "").trim();
if (type.indexOf("application/json") >= 0 || trimmed.charAt(0) === "{" || trimmed.charAt(0) === "[") {
try {
json = trimmed ? JSON.parse(trimmed) : {};
} catch (error) {
json = null;
}
}
return {
ok: response.ok,
status: response.status,
headers: response.headers,
text: text,
json: json,
data: json && json.data !== undefined ? json.data : json,
};
});
}
function request(path, options) {
options = Object.assign({}, options || {});
var requestUrl = url(path, options.query);
delete options.query;
var fetchOptions = Object.assign({}, options, {
credentials: options.credentials || "same-origin",
headers: headers(options),
});
return window.fetch(requestUrl, fetchOptions).then(function (response) {
return parseResponse(response);
}).then(function (result) {
if (!result.ok || (result.json && result.json.success === false)) {
throw responseError(result);
}
return result;
});
}
window.JioRequest = {
url: url,
request: request,
createIdempotencyKey: createIdempotencyKey,
get: function (path, options) {
return request(path, Object.assign({}, options || {}, { method: "GET" }));
},
post: function (path, body, options) {
return request(path, Object.assign({}, options || {}, {
method: "POST",
body: body,
}));
},
};
})(window);