본문으로 건너뛰기
cccskills
무료GitHub에 공개

nostr-rest-api-field-mapping-gap

Fix features broken by REST API responses that flatten Nostr events, losing tag data. Use when: (1) A feature works for WebSocket-loaded events but not REST API-loaded ones, (2) A model field (like sha256, textTrackRef) is null for REST API data but set for WebSocket data, (3) REST API returns denormalized fields (d_tag, video_url) but omits raw tags array, (4) hasSubtitles/hasFeature returns false for REST-loaded videos. Common in Nostr clients that use both REST APIs (for analytics/bulk queries) and WebSocket (for real-time events).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.0 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Nostr REST API Field Mapping Gap

Problem

Nostr clients that use both REST APIs and WebSocket connections to load events can have features that work inconsistently. Features that depend on Nostr tag values (like the x tag for sha256, or custom tags for text tracks) work when events are loaded via WebSocket (which provides the full raw event with all tags), but break when the same events are loaded via REST API (which returns flattened/denormalized JSON without the raw tags array).

Context / Trigger Conditions

  • A feature works for some videos/events but not others (data source dependent)
  • A UI element (like a CC button) shows for WebSocket-loaded events but not REST ones
  • A model has null fields that should be populated (sha256, textTrackRef, etc.)
  • The REST API response has fields like d_tag, video_url, title but NO tags array
  • The fromJson() factory parses tags for values like x (sha256), but the REST API doesn't include raw tags
  • hasSubtitles, hasFeature, or similar getters return false for REST API data

Root Cause

REST APIs that index Nostr events typically:

  1. Extract commonly-used tag values into dedicated columns (d_tag, title, thumbnail, etc.)
  2. Do NOT return the full raw tags array in their response
  3. May have semantically equivalent fields under different names

For example, in a Blossom-based video system:

  • The Nostr x tag contains the SHA256 content hash
  • The REST API returns d_tag (which for Blossom uploads IS the SHA256) but not sha256
  • The model's fromJson() tries to find sha256 from direct field or x tag, finds neither
  • Features that depend on sha256 (like subtitle fetching) break silently

Solution

Step 1: Identify the mapping gap

Compare what the REST API returns vs what the model needs:

# Fetch a sample REST API response
curl -s "https://your-api.example.com/api/videos?limit=1" | jq '.[0] | keys'

Check which model fields are null after parsing:

  • Look at the fromJson() factory method
  • Identify fields populated from tag parsing (tags array) that won't exist in REST response
  • Check if any REST API fields are semantically equivalent but differently named

Step 2: Add fallback mappings

In the model's fromJson(), add fallback logic AFTER the primary parsing:

// Primary: try direct field and tags
var sha256 = eventData['sha256']?.toString() ?? json['sha256']?.toString();

// Parse from tags if available
if (eventData['tags'] is List) {
  // ... tag parsing for 'x' tag ...
}

// Normalize
if (sha256 != null && sha256.isEmpty) sha256 = null;

// FALLBACK: Use semantically equivalent field from REST API
// For Blossom uploads, d_tag IS the content hash (64 hex chars)
if (sha256 == null && dTag.length == 64 && _isHex(dTag)) {
  sha256 = dTag;
}

Step 3: Validate the fallback is safe

Ensure the fallback only triggers when appropriate:

  • Check format/length (SHA256 = 64 hex chars)
  • Don't override explicitly-set values
  • Handle edge cases (classic imports where d_tag is NOT a hash)

Step 4: Add tests

test('falls back to d_tag as sha256 when d_tag is 64-char hex', () {
  final json = {
    'd_tag': 'a04b70820ef370e90aae19d23e46b1482d3af0e7c9d994d1594a1384a62d3972',
    // No sha256 field, no tags array (REST API response)
    ...otherFields,
  };
  final model = Model.fromJson(json);
  expect(model.sha256, equals(json['d_tag']));
});

test('does not use d_tag as sha256 when d_tag is not a hex hash', () {
  final json = {'d_tag': 'my-video-slug', ...otherFields};
  final model = Model.fromJson(json);
  expect(model.sha256, isNull);
});

test('does not override explicit sha256 with d_tag', () {
  final json = {
    'd_tag': 'a04b708...', // 64 hex
    'sha256': 'explicit-value',
    ...otherFields,
  };
  final model = Model.fromJson(json);
  expect(model.sha256, equals('explicit-value'));
});

Verification

  1. Load the app and navigate to a feed that uses the REST API (e.g., trending/discovery)
  2. Verify the feature works (e.g., CC button shows AND subtitles display when toggled)
  3. Also verify WebSocket-loaded events still work (e.g., home feed from followed users)
  4. Check that non-hash d_tags (classic imports, custom slugs) don't get false positives

Debugging Approach

When a feature works inconsistently across events:

  1. Identify data source: Is the broken event from REST API or WebSocket?
  2. Compare raw data: Fetch the same event from both sources, diff the fields
  3. Trace the pipeline: API response -> fromJson() -> model -> getter -> UI condition
  4. Check conditional guards: Look for if (model.hasX) or if (field != null) in UI
  5. Log at the model level: Add temporary logging in fromJson() to see what's null

Notes

  • This pattern applies to ANY Nostr client that uses both REST and WebSocket data sources
  • The REST API may evolve to include more fields over time, so the fallback approach is forward-compatible (explicit fields take priority over fallbacks)
  • Consider requesting the REST API team add the missing fields directly
  • The _isHex() validation prevents false positives from non-hash d_tag values
  • Similar gaps may exist for other tag-derived fields (textTrackRef, duration, etc.)

Related Skills

  • rest-api-optimistic-update-race-condition - Another REST API data consistency issue
  • nostr-addressable-event-d-tag-requirement - Related d_tag handling

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y". Use when: (1) ExternalSecret shows OutOfSync in ArgoCD but won't sync, (2) ArgoCD application status shows "namespace X is not permitted in project 'infrastructure'", (3) ExternalSecret targets a namespace managed by a different ArgoCD project, (4) Using apps-of-apps pattern with separate infrastructure and application projects.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language. After selection, generates AI image prompts and visual briefs section-by-section. Use when the user shares content and needs visual direction, image sourcing, or creative direction for any material.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix "Null check operator used on a null value" errors when an object is set to null during an async await. Use when: (1) Object reference is nullified while awaiting, (2) Code accesses object with ! after await returns, (3) Cancel/dispose operations run concurrently with async operations on same object. Solution: capture local reference before await.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Add custom metadata headers (x-amz-meta-*) to AWS v4 signed requests for GCS S3-compatible API. Use when: (1) Adding custom metadata to GCS uploads via S3 API, (2) Getting signature mismatch errors after adding new headers, (3) x-amz-meta-* headers being ignored or causing 403 errors. Custom headers MUST be included in canonical headers and signed headers list.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings. Use when: (1) Password authentication fails with correct password, (2) Secret created with `<<< "value"` syntax, (3) Error like "password authentication failed" or "invalid token" despite correct value. Bash here-strings (`<<<`) add a trailing newline that corrupts secrets.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp). Use when: (1) Media moderation, transcoding, or analysis silently skips files from Blossom or content-addressed storage servers, (2) URL extraction from Nostr event tags (imeta, r tags) drops URLs without recognized extensions, (3) CDN fallback URLs append .mp4 but the actual server uses extensionless content-addressed paths like /{sha256}. Common in Nostr video events (kind 34236) where different clients use different URL formats.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

divinevideo의 스킬 모두 보기

이 스킬의 문제 신고