Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  setup-logic.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

/**
 * QQBot setup business logic (pure layer).
 * QQBot setup 相关纯业务逻辑。
 *
 * Token parsing, input validation, and setup config application.
 * All functions are framework-agnostic and operate on plain objects.
 */

import { applyAccountConfig } from "./resolve.js";
import { DEFAULT_ACCOUNT_ID } from "./resolve.js";

/** Parse an inline "appId:clientSecret" token string. */
export function parseInlineToken(token: string): { appId: string; clientSecret: string } | null {
  const colonIdx = token.indexOf(":");
  if (colonIdx <= 0 || colonIdx === token.length - 1) {
    return null;
  }

  const appId = token.slice(0, colonIdx).trim();
  const clientSecret = token.slice(colonIdx + 1).trim();
  if (!appId || !clientSecret) {
    return null;
  }

  return { appId, clientSecret };
}

export interface SetupInput {
  token?: string;
  tokenFile?: string;
  useEnv?: boolean;
  name?: string;
}

/** Validate setup input for a QQBot account. Returns an error string or null. */
export function validateSetupInput(accountId: string, input: SetupInput): string | null {
  if (!input.token && !input.tokenFile && !input.useEnv) {
    return "QQBot requires --token (format: appId:clientSecret) or --use-env";
  }

  if (input.useEnv && accountId !== DEFAULT_ACCOUNT_ID) {
    return "QQBot --use-env only supports the default account";
  }

  if (input.token && !parseInlineToken(input.token)) {
    return "QQBot --token must be in appId:clientSecret format";
  }

  return null;
}

/** Apply setup input to account config. Returns updated config. */
export function applySetupAccountConfig(
  cfg: Record<string, unknown>,
  accountId: string,
  input: SetupInput,
): Record<string, unknown> {
  if (input.useEnv && accountId !== DEFAULT_ACCOUNT_ID) {
    return cfg;
  }

  let appId = "";
  let clientSecret = "";

  if (input.token) {
    const parsed = parseInlineToken(input.token);
    if (!parsed) {
      return cfg;
    }
    appId = parsed.appId;
    clientSecret = parsed.clientSecret;
  }

  if (!appId && !input.tokenFile && !input.useEnv) {
    return cfg;
  }

  return applyAccountConfig(cfg, accountId, {
    appId,
    clientSecret,
    clientSecretFile: input.tokenFile,
    name: input.name,
  });
}

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge