同步配置
This commit is contained in:
parent
1dc9d2d131
commit
f69fb95860
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
node_modules/*
|
node_modules/*
|
||||||
config.json
|
config.json
|
||||||
profiles/
|
profiles/*
|
||||||
|
|||||||
@ -61,38 +61,42 @@ async function syncToDouxiaoyun(cookieString, secUserId) {
|
|||||||
|
|
||||||
if (!configResp.ok) throw new Error(`查询配置失败: HTTP ${configResp.status}`);
|
if (!configResp.ok) throw new Error(`查询配置失败: HTTP ${configResp.status}`);
|
||||||
const configData = await configResp.json();
|
const configData = await configResp.json();
|
||||||
const items = configData.data?.items || configData.items || configData.data || [];
|
const items = configData.data?.items || configData.items || configData.data.data || [];
|
||||||
const existingConfig = Array.isArray(items) ? items[0] : items;
|
const existingConfig = Array.isArray(items) ? items[0] : items;
|
||||||
|
|
||||||
if (!existingConfig || !existingConfig.id) {
|
if (!existingConfig || !existingConfig.id) {
|
||||||
console.log(" ⚠️ 未找到现有配置项");
|
console.log(" ⚠️ 未找到现有配置项");
|
||||||
|
console.log(JSON.stringify(configData, null, 4))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(` ✅ 找到配置项: id=${existingConfig.id}, userName=${existingConfig.userName}`);
|
console.log(` ✅ 找到配置项: id=${existingConfig.id}, userName=${existingConfig.userName} statusMsg=${existingConfig.statusMsg}`);
|
||||||
|
|
||||||
// 3. 更新配置
|
if("已过期" == existingConfig.statusMsg) {
|
||||||
console.log(" 3/3 更新 cookies...");
|
// 3. 更新配置
|
||||||
const updateBody = {
|
console.log(" 3/3 更新 cookies...");
|
||||||
...existingConfig,
|
const updateBody = {
|
||||||
cookies: cookieString,
|
...existingConfig,
|
||||||
secUserId: secUserId || existingConfig.secUserId || "",
|
cookies: cookieString,
|
||||||
};
|
secUserId: secUserId || existingConfig.secUserId || "",
|
||||||
|
};
|
||||||
|
|
||||||
const updateResp = await fetch(`${apiBase}/api/config/update`, {
|
const updateResp = await fetch(`${apiBase}/api/config/update`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"accept": "application/json, text/plain, */*",
|
"accept": "application/json, text/plain, */*",
|
||||||
"authorization": `Bearer ${token}`,
|
"authorization": `Bearer ${token}`,
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"Referer": `${apiBase}/`,
|
"Referer": `${apiBase}/`,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(updateBody),
|
body: JSON.stringify(updateBody),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!updateResp.ok) throw new Error(`更新配置失败: HTTP ${updateResp.status}`);
|
if (!updateResp.ok) throw new Error(`更新配置失败: HTTP ${updateResp.status}`);
|
||||||
const updateResult = await updateResp.json();
|
const updateResult = await updateResp.json();
|
||||||
console.log(" ✅ douxiaoyun cookies 更新成功!");
|
console.log(" ✅ douxiaoyun cookies 更新成功!");
|
||||||
console.log(` 响应: ${JSON.stringify(updateResult).substring(0, 200)}`);
|
console.log(` 响应: ${JSON.stringify(updateResult).substring(0, 200)}`);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(` ❌ 同步 douxiaoyun 失败: ${err.message}`);
|
console.error(` ❌ 同步 douxiaoyun 失败: ${err.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user