fix(runtime): remove legacy action endpoint #22

Merged
kate522 merged 1 commits from worktree/fix-legacy-action-404 into main 2026-09-04 06:30:13 +00:00
3 changed files with 35 additions and 63 deletions
-62
View File
@@ -2855,68 +2855,6 @@ _win.bd.on('click', '.toggle-theme', function (event) {
}
});
/*==============点赞===收藏===关注===========*/
_win.bd.on('click', '[data-action]', function () {
var _this = jQuery(this);
var s = _this.attr('data-pid');
var key = _this.attr('data-action');
var type = key;
var _type = 'aksrt' + type;
var data = {
type: type,
key: key,
pid: s,
};
if (!_win.is_signin) {
var t = lcs.get(_type) || '';
if (-1 !== t.indexOf(',' + s + ',')) return notyf(aksrt__(type == 'like' ? 'like_already_post' : 'like_already_comment'), 'warning');
t ? (t.length >= 160 ? ((t = t.substring(0, t.length - 1)), (t = t.substr(1).split(',')), t.splice(0, 1), t.push(s), (t = t.join(',')), lcs.set(_type, ',' + t + ',')) : lcs.set(_type, t + s + ',')) : lcs.set(_type, ',' + s + ',');
}
action_ajax(_this, data, s, type, aksrt__('like_thanks'));
});
function action_ajax(_this, data, pid, type, text) {
if (_this.attr('disabled')) {
return !1;
}
data._wpnonce = _win.post_action_nonce;
var c = text || aksrt__('done');
jQuery.ajax({
type: 'POST',
url: _win.uri + '/action/action.php',
dataType: 'json',
data: data,
beforeSend: function () {
_this.attr('disabled', true).find('count').html('<i class="loading zts"></i>');
},
success: function (n) {
// console.log(n);
var ys = n.error ? 'danger' : '';
if (n.action && n.action == 'remove') {
_this.removeClass('actived action-animation');
ys = 'warning';
}
if (n.action && n.action == 'add') {
_this.addClass('actived action-animation');
}
notyf(n.msg || c, ys);
_this
.attr('disabled', false)
.find('count')
.html(n.cuont || '0');
if (type == 'follow_user') {
jQuery('[data-action="follow_user"][data-pid="' + pid + '"]').each(function () {
jQuery(this).find('count').html(n.cuont);
});
}
},
});
}
_win.bd.on('click', '[ajax-action]', function () {
var _this = jQuery(this);
if (_this.attr('disabled')) return false;
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -0,0 +1,34 @@
const test = require('node:test')
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const root = path.resolve(__dirname, '..', '..')
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8')
const runtimeFiles = [
'assets/js/runtime/main.js',
'assets/js/runtime/main.min.js',
]
test('legacy theme action endpoint stays removed from runtime bundles', () => {
for (const file of runtimeFiles) {
const source = read(file)
assert.doesNotMatch(source, /_win\.bd\.on\(['"]click['"],\s*['"]\[data-action\]['"]/, file)
assert.doesNotMatch(source, /\baction_ajax\s*\(/, file)
assert.doesNotMatch(source, /\/action\/action\.php/, file)
}
})
test('WordPress ajax-action runtime remains available after the hard cut', () => {
for (const file of runtimeFiles) {
const source = read(file)
const handlers = source.match(/_win\.bd\.on\(['"]click['"],\s*['"]\[ajax-action\]['"]/g) || []
assert.equal(handlers.length, 1, `${file} must preserve one ajax-action handler`)
}
})
test('unrelated data-action attributes remain available to runtime components', () => {
const source = read('assets/js/runtime/main.js')
assert.match(source, /\[data-toggle="RefreshModal"\][\s\S]*?attr\(['"]data-action['"]\)/)
})