fix: clear orphan qdreader bindings on save

This commit is contained in:
2026-05-17 21:59:47 +08:00
parent 5d67f06a60
commit 89de9452b1
3 changed files with 37 additions and 4 deletions
+7 -2
View File
@@ -4,7 +4,7 @@
//[author: Hermes]
//[service: BOSS]
//[class: 工具类]
//[version: 2.4.0]
//[version: 2.4.1]
//[platform: web,qq,wx,tg,tb,fs,we]
//[public: false]
//[price: 0]
@@ -242,7 +242,7 @@ function contentText() {
}
function usage() {
return [
"启点读书签到插件 v2.4.0",
"启点读书签到插件 v2.4.1",
"【一级菜单】",
"账号管理:启点账号",
"执行查询:启点查询",
@@ -653,6 +653,11 @@ function handleSaveCookie(arg, store, bind) {
if (!uid) return { ok: false, text: "无法从 Cookie 识别 uid。请确认 QX 抓的是启点读书福利中心 getlogininfo 请求,Cookie 内应包含 QDHeader 或 uid。", uids: savedUids }
var isNew = !store[uid]
var oldOwner = bind[uid] || ""
if (!store[uid] && oldOwner && oldOwner !== me) {
delete bind[uid]
oldOwner = ""
lines.push("检测到 uid: " + uid + " 只有旧绑定没有CK,已自动清理残留绑定")
}
if (store[uid] && oldOwner && me && oldOwner !== me) {
lines.push("无权更新 uid: " + uid + "(该账号已绑定其他用户)")
continue
+7 -2
View File
@@ -4,7 +4,7 @@
//[author: Hermes]
//[service: BOSS]
//[class: 工具类]
//[version: 2.4.0]
//[version: 2.4.1]
//[platform: web,qq,wx,tg,tb,fs,we]
//[public: false]
//[price: 0]
@@ -242,7 +242,7 @@ function contentText() {
}
function usage() {
return [
"启点读书签到插件 v2.4.0",
"启点读书签到插件 v2.4.1",
"【一级菜单】",
"账号管理:启点账号",
"执行查询:启点查询",
@@ -653,6 +653,11 @@ function handleSaveCookie(arg, store, bind) {
if (!uid) return { ok: false, text: "无法从 Cookie 识别 uid。请确认 QX 抓的是启点读书福利中心 getlogininfo 请求,Cookie 内应包含 QDHeader 或 uid。", uids: savedUids }
var isNew = !store[uid]
var oldOwner = bind[uid] || ""
if (!store[uid] && oldOwner && oldOwner !== me) {
delete bind[uid]
oldOwner = ""
lines.push("检测到 uid: " + uid + " 只有旧绑定没有CK,已自动清理残留绑定")
}
if (store[uid] && oldOwner && me && oldOwner !== me) {
lines.push("无权更新 uid: " + uid + "(该账号已绑定其他用户)")
continue
+23
View File
@@ -166,6 +166,29 @@ test('quick submit can bind user from alternate Autman sender fields', () => {
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'sender-42');
});
test('quick submit can re-add cookie when old binding remains but cookie was manually deleted', () => {
const store = {
qdreader_cookie_json: JSON.stringify({}),
qdreader_user_bind_json: JSON.stringify({ '12345': 'old-user' }),
};
const r = runPlugin({ content: '启点ck ' + cookie, store, userId: 'user-a', listens: ['n'] });
assert.match(r.replies.join('\n'), /已自动清理残留绑定/);
assert.match(r.replies.join('\n'), /CK新增成功/);
assert.equal(JSON.parse(r.store.qdreader_cookie_json)['12345'], cookie);
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'user-a');
});
test('quick submit still rejects overwrite when cookie and another owner binding both exist', () => {
const store = {
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
qdreader_user_bind_json: JSON.stringify({ '12345': 'old-user' }),
};
const r = runPlugin({ content: '启点ck ' + cookie.replace('qdh=qdh', 'qdh=newqdh'), store, userId: 'user-a', listens: ['n'] });
assert.match(r.replies.join('\n'), /无权更新 uid: 12345/);
assert.equal(JSON.parse(r.store.qdreader_cookie_json)['12345'], cookie);
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'old-user');
});
test('quick submit rejects save when Autman JS has no user identity', () => {
const r = runPlugin({
content: '启点ck ' + cookie,