mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-14 02:26:38 +00:00
chore: Run pnpm format:fix.
This commit is contained in:
@@ -43,10 +43,7 @@ function normalizeAccountId(accountId?: string): string {
|
||||
return trimmed.replace(/[^a-z0-9._-]+/gi, "_");
|
||||
}
|
||||
|
||||
function resolveNostrStatePath(
|
||||
accountId?: string,
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): string {
|
||||
function resolveNostrStatePath(accountId?: string, env: NodeJS.ProcessEnv = process.env): string {
|
||||
const stateDir = getNostrRuntime().state.resolveStateDir(env, os.homedir);
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
return path.join(stateDir, "nostr", `bus-state-${normalized}.json`);
|
||||
@@ -54,7 +51,7 @@ function resolveNostrStatePath(
|
||||
|
||||
function resolveNostrProfileStatePath(
|
||||
accountId?: string,
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): string {
|
||||
const stateDir = getNostrRuntime().state.resolveStateDir(env, os.homedir);
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
@@ -69,7 +66,8 @@ function safeParseState(raw: string): NostrBusState | null {
|
||||
return {
|
||||
version: 2,
|
||||
lastProcessedAt: typeof parsed.lastProcessedAt === "number" ? parsed.lastProcessedAt : null,
|
||||
gatewayStartedAt: typeof parsed.gatewayStartedAt === "number" ? parsed.gatewayStartedAt : null,
|
||||
gatewayStartedAt:
|
||||
typeof parsed.gatewayStartedAt === "number" ? parsed.gatewayStartedAt : null,
|
||||
recentEventIds: Array.isArray(parsed.recentEventIds)
|
||||
? parsed.recentEventIds.filter((x): x is string => typeof x === "string")
|
||||
: [],
|
||||
@@ -81,7 +79,8 @@ function safeParseState(raw: string): NostrBusState | null {
|
||||
return {
|
||||
version: 2,
|
||||
lastProcessedAt: typeof parsed.lastProcessedAt === "number" ? parsed.lastProcessedAt : null,
|
||||
gatewayStartedAt: typeof parsed.gatewayStartedAt === "number" ? parsed.gatewayStartedAt : null,
|
||||
gatewayStartedAt:
|
||||
typeof parsed.gatewayStartedAt === "number" ? parsed.gatewayStartedAt : null,
|
||||
recentEventIds: [],
|
||||
};
|
||||
}
|
||||
@@ -117,10 +116,7 @@ export async function writeNostrBusState(params: {
|
||||
const filePath = resolveNostrStatePath(params.accountId, params.env);
|
||||
const dir = path.dirname(filePath);
|
||||
await fs.mkdir(dir, { recursive: true, mode: 0o700 });
|
||||
const tmp = path.join(
|
||||
dir,
|
||||
`${path.basename(filePath)}.${crypto.randomUUID()}.tmp`
|
||||
);
|
||||
const tmp = path.join(dir, `${path.basename(filePath)}.${crypto.randomUUID()}.tmp`);
|
||||
const payload: NostrBusState = {
|
||||
version: STORE_VERSION,
|
||||
lastProcessedAt: params.lastProcessedAt,
|
||||
@@ -141,15 +137,14 @@ export async function writeNostrBusState(params: {
|
||||
*/
|
||||
export function computeSinceTimestamp(
|
||||
state: NostrBusState | null,
|
||||
nowSec: number = Math.floor(Date.now() / 1000)
|
||||
nowSec: number = Math.floor(Date.now() / 1000),
|
||||
): number {
|
||||
if (!state) return nowSec;
|
||||
|
||||
// Use the most recent timestamp we have
|
||||
const candidates = [
|
||||
state.lastProcessedAt,
|
||||
state.gatewayStartedAt,
|
||||
].filter((t): t is number => t !== null && t > 0);
|
||||
const candidates = [state.lastProcessedAt, state.gatewayStartedAt].filter(
|
||||
(t): t is number => t !== null && t > 0,
|
||||
);
|
||||
|
||||
if (candidates.length === 0) return nowSec;
|
||||
return Math.max(...candidates);
|
||||
@@ -166,8 +161,7 @@ function safeParseProfileState(raw: string): NostrProfileState | null {
|
||||
if (parsed?.version === 1) {
|
||||
return {
|
||||
version: 1,
|
||||
lastPublishedAt:
|
||||
typeof parsed.lastPublishedAt === "number" ? parsed.lastPublishedAt : null,
|
||||
lastPublishedAt: typeof parsed.lastPublishedAt === "number" ? parsed.lastPublishedAt : null,
|
||||
lastPublishedEventId:
|
||||
typeof parsed.lastPublishedEventId === "string" ? parsed.lastPublishedEventId : null,
|
||||
lastPublishResults:
|
||||
@@ -208,10 +202,7 @@ export async function writeNostrProfileState(params: {
|
||||
const filePath = resolveNostrProfileStatePath(params.accountId, params.env);
|
||||
const dir = path.dirname(filePath);
|
||||
await fs.mkdir(dir, { recursive: true, mode: 0o700 });
|
||||
const tmp = path.join(
|
||||
dir,
|
||||
`${path.basename(filePath)}.${crypto.randomUUID()}.tmp`
|
||||
);
|
||||
const tmp = path.join(dir, `${path.basename(filePath)}.${crypto.randomUUID()}.tmp`);
|
||||
const payload: NostrProfileState = {
|
||||
version: PROFILE_STATE_VERSION,
|
||||
lastPublishedAt: params.lastPublishedAt,
|
||||
|
||||
Reference in New Issue
Block a user