mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:21:23 +00:00
refactor(daemon): share runtime and service probe helpers
This commit is contained in:
@@ -376,9 +376,14 @@ type AllowFromStoreEntryUpdateParams = {
|
||||
env?: NodeJS.ProcessEnv;
|
||||
};
|
||||
|
||||
type ChannelAllowFromStoreEntryMutation = (
|
||||
current: string[],
|
||||
normalized: string,
|
||||
) => string[] | null;
|
||||
|
||||
async function updateChannelAllowFromStore(
|
||||
params: {
|
||||
apply: (current: string[], normalized: string) => string[] | null;
|
||||
apply: ChannelAllowFromStoreEntryMutation;
|
||||
} & AllowFromStoreEntryUpdateParams,
|
||||
): Promise<{ changed: boolean; allowFrom: string[] }> {
|
||||
return await updateAllowFromStoreEntry({
|
||||
@@ -390,38 +395,36 @@ async function updateChannelAllowFromStore(
|
||||
});
|
||||
}
|
||||
|
||||
export async function addChannelAllowFromStoreEntry(params: {
|
||||
channel: PairingChannel;
|
||||
entry: string | number;
|
||||
accountId?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): Promise<{ changed: boolean; allowFrom: string[] }> {
|
||||
async function mutateChannelAllowFromStoreEntry(
|
||||
params: AllowFromStoreEntryUpdateParams,
|
||||
apply: ChannelAllowFromStoreEntryMutation,
|
||||
): Promise<{ changed: boolean; allowFrom: string[] }> {
|
||||
return await updateChannelAllowFromStore({
|
||||
...params,
|
||||
apply: (current, normalized) => {
|
||||
if (current.includes(normalized)) {
|
||||
return null;
|
||||
}
|
||||
return [...current, normalized];
|
||||
},
|
||||
apply,
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeChannelAllowFromStoreEntry(params: {
|
||||
channel: PairingChannel;
|
||||
entry: string | number;
|
||||
accountId?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): Promise<{ changed: boolean; allowFrom: string[] }> {
|
||||
return await updateChannelAllowFromStore({
|
||||
...params,
|
||||
apply: (current, normalized) => {
|
||||
const next = current.filter((entry) => entry !== normalized);
|
||||
if (next.length === current.length) {
|
||||
return null;
|
||||
}
|
||||
return next;
|
||||
},
|
||||
export async function addChannelAllowFromStoreEntry(
|
||||
params: AllowFromStoreEntryUpdateParams,
|
||||
): Promise<{ changed: boolean; allowFrom: string[] }> {
|
||||
return await mutateChannelAllowFromStoreEntry(params, (current, normalized) => {
|
||||
if (current.includes(normalized)) {
|
||||
return null;
|
||||
}
|
||||
return [...current, normalized];
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeChannelAllowFromStoreEntry(
|
||||
params: AllowFromStoreEntryUpdateParams,
|
||||
): Promise<{ changed: boolean; allowFrom: string[] }> {
|
||||
return await mutateChannelAllowFromStoreEntry(params, (current, normalized) => {
|
||||
const next = current.filter((entry) => entry !== normalized);
|
||||
if (next.length === current.length) {
|
||||
return null;
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user