Skip to content

Web adapter compatibility contract ​

Language / 语言: 中文 · English

DAViewer talks to two DeviantArt surfaces:

  • Official OAuth API (stable, versioned, owned by DAKit).
  • Website-private JSON/HTML endpoints (unstable, undocumented) for the few detail features the official API does not expose: numeric-id resolution, related-artwork blocks, collection full contents, artwork keyword search, gallery keyword search, and profile fields (watchers/join date).

This document records private website data sources, fallbacks, and tests. When the website changes, locate the failing adapter before fixing parsing or adjusting the fallback.

Where the code lives ​

The generic private-protocol adapters now live in the optional dakit_web package in DAKit. The package is an adapter layer, not a promise that private endpoints are stable; dakit_web owns only “session + request → DeviantArt DTO → DAKit model”.

DAViewer keeps the product boundary: WebView sign-in, Cookie/CSRF refresh and persistence, SourceCoordinator capability routing, ArtworkStore merge rules, and UI fallback copy. Product-level wrappers remain under lib/core/data/ (for example, collection_contents.dart and web_session.dart). HTML/JSON parsing must not return to business code.

Adapter rules ​

  1. Stable interface isolation. Feature code depends on a small interface or a DAKit domain model (CollectionContentsSource.contents, Artwork, DeviationInit), never on raw HTML/JSON. A site change is fixed inside one adapter without touching a screen.

  2. Tolerant parsing and fallback. Every adapter parses defensively (a malformed entry is skipped, not fatal) and has a fallback: the official API, the preview data, or simply hiding the optional section. A web failure must never take down the artwork detail page.

  3. Contract tests against captured snapshots. Each parser in dakit_web has a committed unit test with a synthetic fixture, plus a gated live-snapshot test that reads a real captured page when the corresponding DA_* dart-define points at it. When DeviantArt changes shape, the snapshot test turns red and names the exact parser.

Endpoint registry ​

FeatureModuleEndpoint / sourceSessionFallbackContract test (snapshot define)
Personalized home feedRfyFeedFetcher (dakit_web)_puppy/dabrowse/networkbar/rfy/deviationsweb Cookie + CSRF (signed-in)none (needs the web session; shows sign-in prompt)rfy_feed_test.dart; updatedTime ?? publishedTime feeds the artwork timestamp so ordering reflects edits
Numeric→UUID + description + datesDeviationInitFetcher (dakit_web)_puppy/dadeviation/initanonymous browser CSRFdescription falls back to the short excerpt; tags empty (official deviation/metadata serves only OAuth items); dates fall back to the feed item's publish timedeviation_init_test.dart (DA_DEVIATION_INIT_JSON); also parses publishedTime / updatedTime for the detail date rows
Related artworkWebMoreLikeThisFetcher (dakit_web)artwork page __INITIAL_STATE__ / __RCACHE__none (public)official browse/morelikethisweb_more_like_this_test.dart (DA_MORE_LIKE_THIS_HTML)
Collection full contentsWebCollectionContentsFetcher (dakit_web) + DAViewer WebCollectionContentsSource_puppy/dashared/gallection/contents (JSON), fallback deviantart.com/{user}/favourites/{id}?page=Nanonymous browser CSRF (JSON) / none (SSR)preview deviations + open-on-webweb_collection_contents_test.dart (DA_COLLECTION_JSON, DA_COLLECTION_HTML)
Deviation searchWebSearchFetcher (dakit_web)_puppy/dabrowse/search/deviationsweb Cookie + CSRF (signed-in)official browse/home?q= (coarse, no web session)web_search_test.dart
Gallery keyword searchWebGallerySearchFetcher (dakit_web)_puppy/dashared/gallection/searchanonymous browser CSRFnone (search needs the web session)web_gallery_search_test.dart
Profile facts (watchers/join date)WebUserProfileFetcher (dakit_web)_puppy/dauserprofile/init/aboutanonymous browser CSRFnone (profile omits the extra fields)web_user_profile_test.dart

Shared, non-endpoint helpers (no separate fallback, tested directly):

HelperModulePurposeTest
Wix media descriptor → URLwix_media.dart (dakit_web)baseUri + prettyName + types resolutionwix_media_test.dart
JS literal JSON decoderhtml_state.dart (dakit_web)window.__X = JSON.parse("…") decodingvia the snapshot tests above
HTML / tiptap → text/htmlhtml_text.dart (dakit_web)description renderinghtml_text_test.dart
Public browser stateweb_session.dartread anonymous browser cookiesweb_session_refresh_policy_test.dart
Link → routeda_uri.dartpaste-link parsing (no network)da_uri_test.dart

Sections that are derived or use the official API (more_from_artist, similar_artists) are not web adapters and are excluded here.

When DeviantArt changes: runbook ​

  1. Run the snapshot tests with the latest capture to see which parser broke:

    bash
    cd /path/to/dakit/packages/dakit_web
    dart test --dart-define=DA_MORE_LIKE_THIS_HTML=/path/to/artwork.html \
              --dart-define=DA_COLLECTION_HTML=/path/to/folder.html \
              --dart-define=DA_DEVIATION_INIT_JSON=/path/to/init.json
  2. Isolate the failure to one adapter. Compare the new response with the fixture to distinguish an endpoint shape change from a session or network failure.

  3. Fix the parser in that one file, keeping the mapped DAKit model unchanged. Prefer tolerant reads (skip the bad entry) over strict parsing unless the endpoint is wholly gone.

  4. Refresh the snapshot and re-run; then update the endpoint registry above if the URL or fallback changed.

  5. If the endpoint is removed, do not invent a replacement. Swap in the official API path or hide the section, and update the fallback column here.

Capturing snapshots ​

Snapshots are real responses saved locally. Do not commit them: they may contain sensitive data and change with the website. To capture one:

  • Public pages (artwork, collection): save the page HTML with a browser User-Agent (login not required).
  • Browser-shaped endpoints (dadeviation/init): capture the JSON response from a public browser session. Do not include account cookies in fixtures.

The DA_* dart-defines point at those files; when unset, the gated tests skip, so CI never depends on a captured page.