fix sync
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
compressionLevel: mixed
|
||||||
|
|
||||||
|
enableGlobalCache: false
|
||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-3.6.3.cjs
|
yarnPath: .yarn/releases/yarn-sources.cjs
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const syncData = async (key, valueFn) => {
|
|||||||
syncMeta = {},
|
syncMeta = {},
|
||||||
} = await getSyncWithDefault();
|
} = await getSyncWithDefault();
|
||||||
if (!syncUrl || !syncKey || (syncType === OPT_SYNCTYPE_WEBDAV && !syncUser)) {
|
if (!syncUrl || !syncKey || (syncType === OPT_SYNCTYPE_WEBDAV && !syncUser)) {
|
||||||
throw new Error("sync setting err");
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { updateAt = 0, syncAt = 0 } = syncMeta[key] || {};
|
let { updateAt = 0, syncAt = 0 } = syncMeta[key] || {};
|
||||||
@@ -93,7 +93,7 @@ const syncData = async (key, valueFn) => {
|
|||||||
};
|
};
|
||||||
await updateSync({ syncMeta });
|
await updateSync({ syncMeta });
|
||||||
|
|
||||||
return [JSON.parse(res.value), res.updateAt > updateAt];
|
return { value: JSON.parse(res.value), isNew: res.updateAt > updateAt };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,9 +101,9 @@ const syncData = async (key, valueFn) => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const syncSetting = async () => {
|
const syncSetting = async () => {
|
||||||
const [value, isNew] = await syncData(KV_SETTING_KEY, getSettingWithDefault);
|
const res = await syncData(KV_SETTING_KEY, getSettingWithDefault);
|
||||||
if (isNew) {
|
if (res?.isNew) {
|
||||||
await setSetting(value);
|
await setSetting(res.value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,9 +120,9 @@ export const trySyncSetting = async () => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const syncRules = async () => {
|
const syncRules = async () => {
|
||||||
const [value, isNew] = await syncData(KV_RULES_KEY, getRulesWithDefault);
|
const res = await syncData(KV_RULES_KEY, getRulesWithDefault);
|
||||||
if (isNew) {
|
if (res?.isNew) {
|
||||||
await setRules(value);
|
await setRules(res.value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -140,15 +140,16 @@ export const trySyncRules = async () => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const syncShareRules = async ({ rules, syncUrl, syncKey }) => {
|
export const syncShareRules = async ({ rules, syncUrl, syncKey }) => {
|
||||||
const args = {
|
const data = {
|
||||||
key: KV_RULES_SHARE_KEY,
|
key: KV_RULES_SHARE_KEY,
|
||||||
value: rules,
|
value: JSON.stringify(rules, null, " "),
|
||||||
|
updateAt: Date.now(),
|
||||||
|
};
|
||||||
|
const args = {
|
||||||
syncUrl,
|
syncUrl,
|
||||||
syncKey,
|
syncKey,
|
||||||
updateAt: Date.now(),
|
|
||||||
syncAt: Date.now(),
|
|
||||||
};
|
};
|
||||||
await syncByWorker(args);
|
await syncByWorker(data, args);
|
||||||
const psk = await sha256(syncKey, KV_SALT_SHARE);
|
const psk = await sha256(syncKey, KV_SALT_SHARE);
|
||||||
const shareUrl = `${syncUrl}/rules?psk=${psk}`;
|
const shareUrl = `${syncUrl}/rules?psk=${psk}`;
|
||||||
return shareUrl;
|
return shareUrl;
|
||||||
|
|||||||
Reference in New Issue
Block a user