mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 20:14:30 +00:00
chore: Lint extensions folder.
This commit is contained in:
@@ -55,13 +55,21 @@ const EFFECT_MAP: Record<string, string> = {
|
||||
};
|
||||
|
||||
function resolveEffectId(raw?: string): string | undefined {
|
||||
if (!raw) return undefined;
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = raw.trim().toLowerCase();
|
||||
if (EFFECT_MAP[trimmed]) return EFFECT_MAP[trimmed];
|
||||
if (EFFECT_MAP[trimmed]) {
|
||||
return EFFECT_MAP[trimmed];
|
||||
}
|
||||
const normalized = trimmed.replace(/[\s_]+/g, "-");
|
||||
if (EFFECT_MAP[normalized]) return EFFECT_MAP[normalized];
|
||||
if (EFFECT_MAP[normalized]) {
|
||||
return EFFECT_MAP[normalized];
|
||||
}
|
||||
const compact = trimmed.replace(/[\s_-]+/g, "");
|
||||
if (EFFECT_MAP[compact]) return EFFECT_MAP[compact];
|
||||
if (EFFECT_MAP[compact]) {
|
||||
return EFFECT_MAP[compact];
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
@@ -84,7 +92,9 @@ function resolveSendTarget(raw: string): BlueBubblesSendTarget {
|
||||
}
|
||||
|
||||
function extractMessageId(payload: unknown): string {
|
||||
if (!payload || typeof payload !== "object") return "unknown";
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return "unknown";
|
||||
}
|
||||
const record = payload as Record<string, unknown>;
|
||||
const data =
|
||||
record.data && typeof record.data === "object"
|
||||
@@ -104,8 +114,12 @@ function extractMessageId(payload: unknown): string {
|
||||
data?.id,
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
|
||||
if (typeof candidate === "number" && Number.isFinite(candidate)) return String(candidate);
|
||||
if (typeof candidate === "string" && candidate.trim()) {
|
||||
return candidate.trim();
|
||||
}
|
||||
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
||||
return String(candidate);
|
||||
}
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
@@ -122,7 +136,9 @@ function extractChatGuid(chat: BlueBubblesChatRecord): string | null {
|
||||
chat.chat_identifier,
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
|
||||
if (typeof candidate === "string" && candidate.trim()) {
|
||||
return candidate.trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -130,14 +146,18 @@ function extractChatGuid(chat: BlueBubblesChatRecord): string | null {
|
||||
function extractChatId(chat: BlueBubblesChatRecord): number | null {
|
||||
const candidates = [chat.chatId, chat.id, chat.chat_id];
|
||||
for (const candidate of candidates) {
|
||||
if (typeof candidate === "number" && Number.isFinite(candidate)) return candidate;
|
||||
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractChatIdentifierFromChatGuid(chatGuid: string): string | null {
|
||||
const parts = chatGuid.split(";");
|
||||
if (parts.length < 3) return null;
|
||||
if (parts.length < 3) {
|
||||
return null;
|
||||
}
|
||||
const identifier = parts[2]?.trim();
|
||||
return identifier ? identifier : null;
|
||||
}
|
||||
@@ -147,7 +167,9 @@ function extractParticipantAddresses(chat: BlueBubblesChatRecord): string[] {
|
||||
(Array.isArray(chat.participants) ? chat.participants : null) ??
|
||||
(Array.isArray(chat.handles) ? chat.handles : null) ??
|
||||
(Array.isArray(chat.participantHandles) ? chat.participantHandles : null);
|
||||
if (!raw) return [];
|
||||
if (!raw) {
|
||||
return [];
|
||||
}
|
||||
const out: string[] = [];
|
||||
for (const entry of raw) {
|
||||
if (typeof entry === "string") {
|
||||
@@ -161,7 +183,9 @@ function extractParticipantAddresses(chat: BlueBubblesChatRecord): string[] {
|
||||
(typeof record.handle === "string" && record.handle) ||
|
||||
(typeof record.id === "string" && record.id) ||
|
||||
(typeof record.identifier === "string" && record.identifier);
|
||||
if (candidate) out.push(candidate);
|
||||
if (candidate) {
|
||||
out.push(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
@@ -192,7 +216,9 @@ async function queryChats(params: {
|
||||
},
|
||||
params.timeoutMs,
|
||||
);
|
||||
if (!res.ok) return [];
|
||||
if (!res.ok) {
|
||||
return [];
|
||||
}
|
||||
const payload = (await res.json().catch(() => null)) as Record<string, unknown> | null;
|
||||
const data = payload && typeof payload.data !== "undefined" ? (payload.data as unknown) : null;
|
||||
return Array.isArray(data) ? (data as BlueBubblesChatRecord[]) : [];
|
||||
@@ -204,7 +230,9 @@ export async function resolveChatGuidForTarget(params: {
|
||||
timeoutMs?: number;
|
||||
target: BlueBubblesSendTarget;
|
||||
}): Promise<string | null> {
|
||||
if (params.target.kind === "chat_guid") return params.target.chatGuid;
|
||||
if (params.target.kind === "chat_guid") {
|
||||
return params.target.chatGuid;
|
||||
}
|
||||
|
||||
const normalizedHandle =
|
||||
params.target.kind === "handle" ? normalizeBlueBubblesHandle(params.target.address) : "";
|
||||
@@ -222,7 +250,9 @@ export async function resolveChatGuidForTarget(params: {
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
if (chats.length === 0) break;
|
||||
if (chats.length === 0) {
|
||||
break;
|
||||
}
|
||||
for (const chat of chats) {
|
||||
if (targetChatId != null) {
|
||||
const chatId = extractChatId(chat);
|
||||
@@ -234,12 +264,16 @@ export async function resolveChatGuidForTarget(params: {
|
||||
const guid = extractChatGuid(chat);
|
||||
if (guid) {
|
||||
// Back-compat: some callers might pass a full chat GUID.
|
||||
if (guid === targetChatIdentifier) return guid;
|
||||
if (guid === targetChatIdentifier) {
|
||||
return guid;
|
||||
}
|
||||
|
||||
// Primary match: BlueBubbles `chat_identifier:*` targets correspond to the
|
||||
// third component of the chat GUID: `service;(+|-) ;identifier`.
|
||||
const guidIdentifier = extractChatIdentifierFromChatGuid(guid);
|
||||
if (guidIdentifier && guidIdentifier === targetChatIdentifier) return guid;
|
||||
if (guidIdentifier && guidIdentifier === targetChatIdentifier) {
|
||||
return guid;
|
||||
}
|
||||
}
|
||||
|
||||
const identifier =
|
||||
@@ -250,7 +284,9 @@ export async function resolveChatGuidForTarget(params: {
|
||||
: typeof chat.chat_identifier === "string"
|
||||
? chat.chat_identifier
|
||||
: "";
|
||||
if (identifier && identifier === targetChatIdentifier) return guid ?? extractChatGuid(chat);
|
||||
if (identifier && identifier === targetChatIdentifier) {
|
||||
return guid ?? extractChatGuid(chat);
|
||||
}
|
||||
}
|
||||
if (normalizedHandle) {
|
||||
const guid = extractChatGuid(chat);
|
||||
@@ -322,7 +358,9 @@ async function createNewChatWithMessage(params: {
|
||||
throw new Error(`BlueBubbles create chat failed (${res.status}): ${errorText || "unknown"}`);
|
||||
}
|
||||
const body = await res.text();
|
||||
if (!body) return { messageId: "ok" };
|
||||
if (!body) {
|
||||
return { messageId: "ok" };
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(body) as unknown;
|
||||
return { messageId: extractMessageId(parsed) };
|
||||
@@ -347,8 +385,12 @@ export async function sendMessageBlueBubbles(
|
||||
});
|
||||
const baseUrl = opts.serverUrl?.trim() || account.config.serverUrl?.trim();
|
||||
const password = opts.password?.trim() || account.config.password?.trim();
|
||||
if (!baseUrl) throw new Error("BlueBubbles serverUrl is required");
|
||||
if (!password) throw new Error("BlueBubbles password is required");
|
||||
if (!baseUrl) {
|
||||
throw new Error("BlueBubbles serverUrl is required");
|
||||
}
|
||||
if (!password) {
|
||||
throw new Error("BlueBubbles password is required");
|
||||
}
|
||||
|
||||
const target = resolveSendTarget(to);
|
||||
const chatGuid = await resolveChatGuidForTarget({
|
||||
@@ -414,7 +456,9 @@ export async function sendMessageBlueBubbles(
|
||||
throw new Error(`BlueBubbles send failed (${res.status}): ${errorText || "unknown"}`);
|
||||
}
|
||||
const body = await res.text();
|
||||
if (!body) return { messageId: "ok" };
|
||||
if (!body) {
|
||||
return { messageId: "ok" };
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(body) as unknown;
|
||||
return { messageId: extractMessageId(parsed) };
|
||||
|
||||
Reference in New Issue
Block a user