atproto/packages/bsky/src/api/blob-resolver.ts

399 lines
13 KiB
TypeScript
Raw Normal View History

import { Duplex, Transform, Writable } from 'node:stream'
import { pipeline } from 'node:stream/promises'
import createError, { isHttpError } from 'http-errors'
import { CID } from 'multiformats/cid'
import { Dispatcher } from 'undici'
import {
VerifyCidError,
VerifyCidTransform,
createDecoders,
} from '@atproto/common'
import { AtprotoDid, isAtprotoDid } from '@atproto/did'
import {
ACCEPT_ENCODING_COMPRESSED,
ACCEPT_ENCODING_UNCOMPRESSED,
buildProxiedContentEncoding,
formatAcceptHeader,
} from '@atproto-labs/xrpc-utils'
import { ServerConfig } from '../config'
import { AppContext } from '../context'
Feature: Appview v2 (#1924) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * filler commit * rm filler * server boilerplate * follows impl * posts impl * posts & likes impl * repost impl * profiles & handle null values * list impl * mutes impl * blocks impl * misc * feed gen impl * label impl * notifs impl * feeds impl * threads impl * early sketchwork * wip * stub out thick client * in-progress work on hydrator * tweak * hydrate profile labels, detail lists * feedgen hydration * protobuf tweaks * more protobuf tweaks * wip * snake case * moar snake case * tidy actor hydration * tidy parsing * type fixes, renaming, comments in hydrator * hydrate list items and likes * hydrate notifications * feed hydration * graph & label hydration * more record protobufs * pluralize * tweak pbs * use new methods * Setup dataplane grpc client/mock server (#1921) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * add record getter mocks * post view hydration * fix up mock dataplane to match new protos * missed one * wire up dataplane in ctx & dev-env * adding some basic views * feed hydration, add blocks to post hydration * pass over notification hydration * tidy * merge * implement getProfile * hydrate post aggregation and viewer state * fix * fix codegen * get some tests passing! * add takedowns & some like bugfixing * all profile tests passing! * likes test * follow endpoints using data plane * reorg follow block rules * reposts * post views! * implement getList w/ dataplane caveat * adjust dataplane getListMembers to return listitem uris * implement getListMutes and -Blocks w/ dataplane * suggestions * timeline * misc view fixes * view fixes for mutes, self-mute/block * author feed * feed gen routes * tidy * misc block/mute fixes * list feed & actor likes * implement getLists, fix some empty cursors * implement getMutes, empty profile description fix * implement getBlocks, block application fix * implement getSuggestedFollowsByActor, needs some fixes * feed generation * search routes * threads * tidy * fix some snaps * fix getSuggestedFollowsByActor * implement listNotifications * implement getUnreadCount w/ dataplane * implement notifications.updateSeen w/ dataplane * 3rd party blocking tests * blocked profile viewer * add search mocks * refactor getFeed * createPipeline -> createPipelineNew * basic replygating functionality on dataplane w/o filtering violating replies * hack threadgates into dataplane, apply gates * deterministic thread orders in dataplane * misc cleanup around dataplane * upgrade typescript to v5.3 * update typescript linter deps * sync bsky proto, codegen * update dataplane, sync with bsky proto updates * remove indexer, ingester, daemon, moderation services from appview * convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane * remove bsky services. db and indexing logic into mock dataplane. * remove tests not needed by appview v2, misc reorg * add basic in-mem repo subscription to dataplane mock * fix dev-env, bsky tests, bsky build * cull bsky service entrypoint * add bsky service readme * build * tidy * tidy, fix pds proxy tests * fix * fix bsky entrypoint deps * support http2 grpc client * build * fix dataplane bad tls config/default * support multiple dataplane urls, retry when unavailable * build * tidy/fix * move dataplane mock tests into their own dir * cover label hydration through timeline test * bring back labels in appview tests * remove unused db primary/replica/coordinator from bsky dataplane * bsky proto add cids to contracts, buf codegen * sync-up bsky data-plane w/ codegen updates * start using dataplane interaction endpoints * add file * avoid overfetching from dataplane, plumb feed items and cids * pass refs through for post viewer state * switch list feeds to use feed item in dataplane * handle not found err on get-thread dataplane call * support use of search service rather than dataplane methods * mark some appview v2 todos * tidy * still use dataplane on search endpoints when search service is not configured * fix pds test * fix up bsky tests & snaps * tidy migrations * fix appview-v2 docker build * Support label issuer tied to appview v2 (#2033) support label issuer tied to appview * Appview v2: handle empty cursor on list notifications (#2017) handle empty cursor on appview listnotifs * Update appview v2 to use author feed enum (#2047) * update bsky protos with author feed enum, misc feed item changes * support new author feed enums in dataplane * fix build * Appview v2: utilize sorted-at field in bsky protos (#2050) utilize new sorted-at field in bsky protos * remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts * Appview v2, sync w/ changes to protos (#2071) * sync bsky protos * sync-up bsky implementation w/ proto changes * Appview v2 initial implementation for getPopularFeedGenerators (#2072) add an initial implementation for getPopularFeedGenerators on appview v2 * merge * fixes * fix feed tests * fix bsync mock * format * remove unused config * fix lockfile * another lockfile fix * fix duplicate type * fix dupplicate test * Appview v2 handling clearly bad cursors (#2092) * make mock dataplane cursors different from v1 cursors * fail open on clearly bad appview cursors * fix pds appview proxy snaps * Appview v2 no notifs seen behavior (#2096) * alter behavior for presenting notifications w/ no last-seen time * fix pds proxy tests * Appview v2 dataplane retries based on client host (#2098) choose dataplane client for retries based on host when possible/relevant * don't apply negated labels * display suspensions on actor profile in appview v2 * Appview v2 use dataplane for identity lookups (#2095) * update bsky proto w/ identity methods * setup identity endpoints on mock dataplane * move from idresolver to dataplane for identity lookups on appview * tidy * Appview v2: apply safe takedown refs to records, actors (#2107) apply safe takedown refs to records, actors * Fix timing on appview v2 repo rev header (#2113) fix timing on appview repo rev * fix post thread responses * Appview v2 don't apply 3p self blocks (#2112) do not apply 3p self-blocks * Appview v2 search for feed generators (#2118) * add protos for feedgen search * support feed search on getPopularFeedGenerators * Appview v2 config tidy (#2117) * remove mod and triage roles from appview * rename cdn and search config * remove custom feed harness from appview v2 * Appview v2: don't apply missing modlists (#2122) * dont apply missing mod lists * update mock dataplane * Update packages/bsky/src/hydration/hydrator.ts Co-authored-by: devin ivy <devinivy@gmail.com> * refactor & document a bit better * fix up other routes --------- Co-authored-by: devin ivy <devinivy@gmail.com> * Appview v2 enforce post thread root boundary (#2120) * enforce post thread root boundary * test thread root boundary * Appview v2 fix admin environment variable (#2137) fix admin env in appview v2 * Remove re-pagination from getSuggestions (#2145) * remove re-pagination from getSuggestions * fix test * Adjust wording for account suspension (#2153) adjust wording for account suspension * Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps * :sparkles: Show author feed of takendown author to admins only (#2197) * fold in cid, auth, tracing, node version changes * remove dead config from bsky service entrypoint * build * remove ozone test codepaths for appview v2 * tidy, docs fix --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 14:22:55 -06:00
import {
Code,
DataPlaneClient,
Feature: Appview v2 (#1924) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * filler commit * rm filler * server boilerplate * follows impl * posts impl * posts & likes impl * repost impl * profiles & handle null values * list impl * mutes impl * blocks impl * misc * feed gen impl * label impl * notifs impl * feeds impl * threads impl * early sketchwork * wip * stub out thick client * in-progress work on hydrator * tweak * hydrate profile labels, detail lists * feedgen hydration * protobuf tweaks * more protobuf tweaks * wip * snake case * moar snake case * tidy actor hydration * tidy parsing * type fixes, renaming, comments in hydrator * hydrate list items and likes * hydrate notifications * feed hydration * graph & label hydration * more record protobufs * pluralize * tweak pbs * use new methods * Setup dataplane grpc client/mock server (#1921) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * add record getter mocks * post view hydration * fix up mock dataplane to match new protos * missed one * wire up dataplane in ctx & dev-env * adding some basic views * feed hydration, add blocks to post hydration * pass over notification hydration * tidy * merge * implement getProfile * hydrate post aggregation and viewer state * fix * fix codegen * get some tests passing! * add takedowns & some like bugfixing * all profile tests passing! * likes test * follow endpoints using data plane * reorg follow block rules * reposts * post views! * implement getList w/ dataplane caveat * adjust dataplane getListMembers to return listitem uris * implement getListMutes and -Blocks w/ dataplane * suggestions * timeline * misc view fixes * view fixes for mutes, self-mute/block * author feed * feed gen routes * tidy * misc block/mute fixes * list feed & actor likes * implement getLists, fix some empty cursors * implement getMutes, empty profile description fix * implement getBlocks, block application fix * implement getSuggestedFollowsByActor, needs some fixes * feed generation * search routes * threads * tidy * fix some snaps * fix getSuggestedFollowsByActor * implement listNotifications * implement getUnreadCount w/ dataplane * implement notifications.updateSeen w/ dataplane * 3rd party blocking tests * blocked profile viewer * add search mocks * refactor getFeed * createPipeline -> createPipelineNew * basic replygating functionality on dataplane w/o filtering violating replies * hack threadgates into dataplane, apply gates * deterministic thread orders in dataplane * misc cleanup around dataplane * upgrade typescript to v5.3 * update typescript linter deps * sync bsky proto, codegen * update dataplane, sync with bsky proto updates * remove indexer, ingester, daemon, moderation services from appview * convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane * remove bsky services. db and indexing logic into mock dataplane. * remove tests not needed by appview v2, misc reorg * add basic in-mem repo subscription to dataplane mock * fix dev-env, bsky tests, bsky build * cull bsky service entrypoint * add bsky service readme * build * tidy * tidy, fix pds proxy tests * fix * fix bsky entrypoint deps * support http2 grpc client * build * fix dataplane bad tls config/default * support multiple dataplane urls, retry when unavailable * build * tidy/fix * move dataplane mock tests into their own dir * cover label hydration through timeline test * bring back labels in appview tests * remove unused db primary/replica/coordinator from bsky dataplane * bsky proto add cids to contracts, buf codegen * sync-up bsky data-plane w/ codegen updates * start using dataplane interaction endpoints * add file * avoid overfetching from dataplane, plumb feed items and cids * pass refs through for post viewer state * switch list feeds to use feed item in dataplane * handle not found err on get-thread dataplane call * support use of search service rather than dataplane methods * mark some appview v2 todos * tidy * still use dataplane on search endpoints when search service is not configured * fix pds test * fix up bsky tests & snaps * tidy migrations * fix appview-v2 docker build * Support label issuer tied to appview v2 (#2033) support label issuer tied to appview * Appview v2: handle empty cursor on list notifications (#2017) handle empty cursor on appview listnotifs * Update appview v2 to use author feed enum (#2047) * update bsky protos with author feed enum, misc feed item changes * support new author feed enums in dataplane * fix build * Appview v2: utilize sorted-at field in bsky protos (#2050) utilize new sorted-at field in bsky protos * remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts * Appview v2, sync w/ changes to protos (#2071) * sync bsky protos * sync-up bsky implementation w/ proto changes * Appview v2 initial implementation for getPopularFeedGenerators (#2072) add an initial implementation for getPopularFeedGenerators on appview v2 * merge * fixes * fix feed tests * fix bsync mock * format * remove unused config * fix lockfile * another lockfile fix * fix duplicate type * fix dupplicate test * Appview v2 handling clearly bad cursors (#2092) * make mock dataplane cursors different from v1 cursors * fail open on clearly bad appview cursors * fix pds appview proxy snaps * Appview v2 no notifs seen behavior (#2096) * alter behavior for presenting notifications w/ no last-seen time * fix pds proxy tests * Appview v2 dataplane retries based on client host (#2098) choose dataplane client for retries based on host when possible/relevant * don't apply negated labels * display suspensions on actor profile in appview v2 * Appview v2 use dataplane for identity lookups (#2095) * update bsky proto w/ identity methods * setup identity endpoints on mock dataplane * move from idresolver to dataplane for identity lookups on appview * tidy * Appview v2: apply safe takedown refs to records, actors (#2107) apply safe takedown refs to records, actors * Fix timing on appview v2 repo rev header (#2113) fix timing on appview repo rev * fix post thread responses * Appview v2 don't apply 3p self blocks (#2112) do not apply 3p self-blocks * Appview v2 search for feed generators (#2118) * add protos for feedgen search * support feed search on getPopularFeedGenerators * Appview v2 config tidy (#2117) * remove mod and triage roles from appview * rename cdn and search config * remove custom feed harness from appview v2 * Appview v2: don't apply missing modlists (#2122) * dont apply missing mod lists * update mock dataplane * Update packages/bsky/src/hydration/hydrator.ts Co-authored-by: devin ivy <devinivy@gmail.com> * refactor & document a bit better * fix up other routes --------- Co-authored-by: devin ivy <devinivy@gmail.com> * Appview v2 enforce post thread root boundary (#2120) * enforce post thread root boundary * test thread root boundary * Appview v2 fix admin environment variable (#2137) fix admin env in appview v2 * Remove re-pagination from getSuggestions (#2145) * remove re-pagination from getSuggestions * fix test * Adjust wording for account suspension (#2153) adjust wording for account suspension * Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps * :sparkles: Show author feed of takendown author to admins only (#2197) * fold in cid, auth, tracing, node version changes * remove dead config from bsky service entrypoint * build * remove ozone test codepaths for appview v2 * tidy, docs fix --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 14:22:55 -06:00
getServiceEndpoint,
isDataplaneError,
unpackIdentityServices,
} from '../data-plane'
import { parseCid } from '../hydration/util'
import { httpLogger as log } from '../logger'
import { Middleware, proxyResponseHeaders, responseSignal } from '../util/http'
import { BSKY_USER_AGENT } from './util'
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
export function createMiddleware(ctx: AppContext): Middleware {
return async (req, res, next) => {
if (req.method !== 'GET' && req.method !== 'HEAD') return next()
if (!req.url?.startsWith('/blob/')) return next()
const { length, 2: didParam, 3: cidParam } = req.url.split('/')
if (length !== 4 || !didParam || !cidParam) return next()
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
// @TODO Check sec-fetch-* headers (e.g. to prevent files from being
// displayed as a web page) ?
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
try {
const streamOptions: StreamBlobOptions = {
did: didParam,
cid: cidParam,
signal: responseSignal(res),
// Because we will be verifying the CID, we need to ensure that the
// upstream response can be de-compressed. We do this by negotiating the
// "accept-encoding" header based on the downstream client's capabilities.
acceptEncoding: buildProxiedContentEncoding(
req.headers['accept-encoding'],
ctx.cfg.proxyPreferCompressed,
),
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
}
await streamBlob(ctx, streamOptions, (upstream, { cid, did, url }) => {
const encoding = upstream.headers['content-encoding']
const verifier = createCidVerifier(cid, encoding)
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
const logError = (err: unknown) => {
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
log.warn(
{ err, did, cid: cid.toString(), pds: url.origin },
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
'blob resolution failed during transmission',
)
}
const onError = (err: unknown) => {
// No need to pipe the data (verifier) into the response, as it is
// "errored". The response processing will continue in the "catch"
// block below (because streamBlob() will reject the promise in case
// of "error" event on the writable stream returned by the factory).
clearTimeout(graceTimer)
logError(err)
}
// Catch any error that occurs before the timer bellow is triggered.
// The promise returned by streamBlob() will be rejected as soon as
// the verifier errors.
verifier.on('error', onError)
// The way I/O work, it is likely that, in case of small payloads, the
// full upstream response is already buffered at this point. In order to
// return a 404 instead of a broken response stream, we allow the event
// loop to to process any pending I/O events before we start piping the
// bytes to the response. For larger payloads, the response will look
// like a 200 with a broken chunked response stream. The only way around
// that would be to buffer the entire response before piping it to the
// response, which will hurt latency (need the full payload) and memory
// usage (either RAM or DISK). Since this is more of an edge case, we
// allow the broken response stream to be sent.
const graceTimer = setTimeout(() => {
verifier.off('error', onError)
// Make sure that the content served from the bsky api domain cannot
// be used to perform XSS attacks (by serving HTML pages)
res.setHeader(
'Content-Security-Policy',
`default-src 'none'; sandbox`,
)
res.setHeader('X-Content-Type-Options', 'nosniff')
res.setHeader('X-Frame-Options', 'DENY')
res.setHeader('X-XSS-Protection', '0')
// @TODO Add a cache-control header ?
// @TODO Add content-disposition header (to force download) ?
proxyResponseHeaders(upstream, res)
// Force chunked encoding. This is required because the verifier will
// trigger an error *after* the last chunk has been passed through.
// Because the number of bytes sent will match the content-length, the
// HTTP response will be considered "complete" by the HTTP server. At
// this point, only trailers headers could indicate that an error
// occurred, but that is not the behavior we expect.
res.removeHeader('content-length')
// From this point on, triggering the next middleware (including any
// error handler) can be problematic because content-type,
// content-enconding, etc. headers have already been set. Because of
// this, we make sure that res.headersSent is set to true, preventing
// another error handler middleware from being called (from the catch
// block bellow). Not flushing the headers here would require to
// revert the headers set from this middleware (which we don't do for
// now).
res.flushHeaders()
// Pipe the verifier output into the HTTP response
void pipeline([verifier, res]).catch(logError)
}, 10) // 0 works too. Allow for additional data to come in for 10ms.
// Write the upstream response into the verifier.
return verifier
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
})
} catch (err) {
if (res.headersSent || res.destroyed) {
res.destroy()
} else if (err instanceof VerifyCidError) {
// @NOTE This only works because of the graceTimer above. It will also
// only be triggered for small payloads.
next(createError(404, err.message))
} else if (isHttpError(err)) {
next(err)
} else {
next(createError(502, 'Upstream Error', { cause: err }))
}
}
}
}
export type StreamBlobOptions = {
cid: string
did: string
acceptEncoding?: string
signal?: AbortSignal
}
export type StreamBlobFactory = (
data: Dispatcher.StreamFactoryData,
info: {
url: URL
did: AtprotoDid
cid: CID
},
) => Writable
export async function streamBlob(
ctx: AppContext,
options: StreamBlobOptions,
factory: StreamBlobFactory,
) {
const { did, cid } = parseBlobParams(options)
const url = await getBlobUrl(ctx.dataplane, did, cid)
const headers = getBlobHeaders(ctx.cfg, url)
headers.set(
'accept-encoding',
options.acceptEncoding ||
formatAcceptHeader(
ctx.cfg.proxyPreferCompressed
? ACCEPT_ENCODING_COMPRESSED
: ACCEPT_ENCODING_UNCOMPRESSED,
),
)
let headersReceived = false
return ctx.blobDispatcher
.stream(
{
method: 'GET',
origin: url.origin,
path: url.pathname + url.search,
headers,
signal: options.signal,
maxRedirections: 10,
},
(upstream) => {
headersReceived = true
if (upstream.statusCode !== 200) {
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
log.warn(
{
did,
cid: cid.toString(),
pds: url.origin,
status: upstream.statusCode,
},
`blob resolution failed upstream`,
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
)
throw upstream.statusCode >= 400 && upstream.statusCode < 500
? createError(404, 'Blob not found', { cause: upstream }) // 4xx => 404
: createError(502, 'Upstream Error', { cause: upstream }) // !200 && !4xx => 502
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
}
return factory(upstream, { url, did, cid })
},
)
.catch((err) => {
// Is this a connection error, or a stream error ?
if (!headersReceived) {
// connection error, dns error, headers timeout, ...
log.warn(
{ err, did, cid: cid.toString(), pds: url.origin },
'blob resolution failed during connection',
)
throw createError(502, 'Upstream Error', { cause: err })
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
}
throw err
})
}
function parseBlobParams(params: { cid: string; did: string }) {
const { cid, did } = params
if (!isAtprotoDid(did)) throw createError(400, 'Invalid did')
const cidObj = parseCid(cid)
if (!cidObj) throw createError(400, 'Invalid cid')
return { cid: cidObj, did }
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
}
async function getBlobUrl(
dataplane: DataPlaneClient,
did: string,
cid: CID,
): Promise<URL> {
const pds = await getBlobPds(dataplane, did, cid)
const url = new URL(`/xrpc/com.atproto.sync.getBlob`, pds)
url.searchParams.set('did', did)
url.searchParams.set('cid', cid.toString())
return url
}
Evented architecture for moderation system (#1617) * :construction: WIP with proposed lexicons for event based mod architecture * :construction: Remove unnecessary moderation action lexicon * :construction: Working on event based actions * :sparkles: Add escalated subject status * :bug: Alright, fixed the error in lexicon * :construction: Working through reversal * :sparkles: Cleanup build errors * :sparkles: Add subject status endpoint * :sparkles: Add handler * :sparkles: get reports from mod actions table * :rightwards_twisted_arrows: Merge with upstream * :construction: Builds but test network doesnt start * :sparkles: Tests passing on event based status change * :sparkles: Rename index * :recycle: Rename takeModerationAction->emitModerationEvent * :sparkles: Implement label reversal * :white_check_mark: Auto-revert test working * :recycle: :white_check_mark: Refactored to event types and tests are passing * :sparkles: Add takedown event sequence validation * :sparkles: Adds support for blobCid status * :broom: Cleanup unnecessary method: * :sparkles: Hydrate handles with status and events * :sparkles: Re-implement auto reversal * :sparkles: Add takendown and mute filters * :sparkles: Allow filtering events by type * :sparkles: Allow filtering events by creator did * :sparkles: Add subjectStatus to record and repoview * :sparkles: Add persistent note feature * :sparkles: Log send email event * :bug: Fix logging send email event * :sparkles: Better type * :sparkles: Adjust migration to create separate moderation_event table * :broom: Cleanup types * :white_check_mark: Adjust tests with mod event emitter * :sparkles: Fix more tests around takedowns * :white_check_mark: Get test suite to pass * :white_check_mark: Get test suite to pass for pds * :white_check_mark: Get test suite to pass for pds * :white_check_mark: Update snapshot for feedgen * :white_check_mark: Why are more snapshots updating? * :recycle: Rename getModerationEvents -> queryModerationEvents * :recycle: Rename getModerationStatuses -> queryModerationStatuses * :recycle: Rename persistNote->sticky * :bug: Rename subject * :recycle: Cleanup expiresAt for scheduled actions * :sparkles: Add more tests, allow fetching mod history for all content by a user * :white_check_mark: Fix repo and record tests * :sparkles: Migrate reports and actions to events * :bug: Fix escalated status overwrite * :sparkles: Implement direct sql query to create events from actions and reports * :construction: Adding keyset pagination for subject statuses * :sparkles: Add migration for lastReportedAt * :sparkles: Migrate blob cids * :sparkles: Fix pagination on mod subject list endpoint * :bug: Fix blob actions * :white_check_mark: All tests passing on bsky package * :white_check_mark: Bring back snapshots * :white_check_mark: Skipping timeline test temporarily * :white_check_mark: Skipping some more tests to isolate failing ones * :white_check_mark: Bring back list-feed test * :white_check_mark: Bring back timeline test * :white_check_mark: Fix label action in seeding * :white_check_mark: Enable timeline proxied test * :white_check_mark: Enable search actor proxied test * :white_check_mark: Enable feedgen tests * :white_check_mark: Fix test for admin/get-record * :sparkles: Move note to comment for subject status * :sparkles: Accept comments in mute event * :sparkles: Remap flag event to ack event * :bug: Add legacyRef in report union selection * @atproto/api 0.6.24-next.0 * @atproto/api 0.6.24-next.1 * :sparkles: Adjust migration export and add index for blobCids column * :sparkles: Maintin action ids when migrating * :sparkles: Paginate events using createdAt timestamp * :white_check_mark: Update snapshot for pds test with events cursor update * :white_check_mark: Use only events for snapshot testing * :white_check_mark: Use only events for snapshot in the remaining test * relative paths to lexicons for build * fix bsky periodic event reversal in service entrypoint * :sparkles: Allow comments in takedown and label * :sparkles: Only import reports on consecutive run of the migration script * :sparkles: Adjust moderation property of blob entries * determine latest reports to migrate * :sparkles: Process new reports for subject status * :sparkles: Process unresolved reports on first migration run * fix transaction error, process just unresolved reports, make reported-at updates safe for reruns * tidy --------- Co-authored-by: Devin Ivy <devinivy@gmail.com>
2023-11-30 17:53:56 +01:00
async function getBlobPds(
dataplane: DataPlaneClient,
did: string,
cid: CID,
): Promise<string> {
Feature: Appview v2 (#1924) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * filler commit * rm filler * server boilerplate * follows impl * posts impl * posts & likes impl * repost impl * profiles & handle null values * list impl * mutes impl * blocks impl * misc * feed gen impl * label impl * notifs impl * feeds impl * threads impl * early sketchwork * wip * stub out thick client * in-progress work on hydrator * tweak * hydrate profile labels, detail lists * feedgen hydration * protobuf tweaks * more protobuf tweaks * wip * snake case * moar snake case * tidy actor hydration * tidy parsing * type fixes, renaming, comments in hydrator * hydrate list items and likes * hydrate notifications * feed hydration * graph & label hydration * more record protobufs * pluralize * tweak pbs * use new methods * Setup dataplane grpc client/mock server (#1921) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * add record getter mocks * post view hydration * fix up mock dataplane to match new protos * missed one * wire up dataplane in ctx & dev-env * adding some basic views * feed hydration, add blocks to post hydration * pass over notification hydration * tidy * merge * implement getProfile * hydrate post aggregation and viewer state * fix * fix codegen * get some tests passing! * add takedowns & some like bugfixing * all profile tests passing! * likes test * follow endpoints using data plane * reorg follow block rules * reposts * post views! * implement getList w/ dataplane caveat * adjust dataplane getListMembers to return listitem uris * implement getListMutes and -Blocks w/ dataplane * suggestions * timeline * misc view fixes * view fixes for mutes, self-mute/block * author feed * feed gen routes * tidy * misc block/mute fixes * list feed & actor likes * implement getLists, fix some empty cursors * implement getMutes, empty profile description fix * implement getBlocks, block application fix * implement getSuggestedFollowsByActor, needs some fixes * feed generation * search routes * threads * tidy * fix some snaps * fix getSuggestedFollowsByActor * implement listNotifications * implement getUnreadCount w/ dataplane * implement notifications.updateSeen w/ dataplane * 3rd party blocking tests * blocked profile viewer * add search mocks * refactor getFeed * createPipeline -> createPipelineNew * basic replygating functionality on dataplane w/o filtering violating replies * hack threadgates into dataplane, apply gates * deterministic thread orders in dataplane * misc cleanup around dataplane * upgrade typescript to v5.3 * update typescript linter deps * sync bsky proto, codegen * update dataplane, sync with bsky proto updates * remove indexer, ingester, daemon, moderation services from appview * convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane * remove bsky services. db and indexing logic into mock dataplane. * remove tests not needed by appview v2, misc reorg * add basic in-mem repo subscription to dataplane mock * fix dev-env, bsky tests, bsky build * cull bsky service entrypoint * add bsky service readme * build * tidy * tidy, fix pds proxy tests * fix * fix bsky entrypoint deps * support http2 grpc client * build * fix dataplane bad tls config/default * support multiple dataplane urls, retry when unavailable * build * tidy/fix * move dataplane mock tests into their own dir * cover label hydration through timeline test * bring back labels in appview tests * remove unused db primary/replica/coordinator from bsky dataplane * bsky proto add cids to contracts, buf codegen * sync-up bsky data-plane w/ codegen updates * start using dataplane interaction endpoints * add file * avoid overfetching from dataplane, plumb feed items and cids * pass refs through for post viewer state * switch list feeds to use feed item in dataplane * handle not found err on get-thread dataplane call * support use of search service rather than dataplane methods * mark some appview v2 todos * tidy * still use dataplane on search endpoints when search service is not configured * fix pds test * fix up bsky tests & snaps * tidy migrations * fix appview-v2 docker build * Support label issuer tied to appview v2 (#2033) support label issuer tied to appview * Appview v2: handle empty cursor on list notifications (#2017) handle empty cursor on appview listnotifs * Update appview v2 to use author feed enum (#2047) * update bsky protos with author feed enum, misc feed item changes * support new author feed enums in dataplane * fix build * Appview v2: utilize sorted-at field in bsky protos (#2050) utilize new sorted-at field in bsky protos * remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts * Appview v2, sync w/ changes to protos (#2071) * sync bsky protos * sync-up bsky implementation w/ proto changes * Appview v2 initial implementation for getPopularFeedGenerators (#2072) add an initial implementation for getPopularFeedGenerators on appview v2 * merge * fixes * fix feed tests * fix bsync mock * format * remove unused config * fix lockfile * another lockfile fix * fix duplicate type * fix dupplicate test * Appview v2 handling clearly bad cursors (#2092) * make mock dataplane cursors different from v1 cursors * fail open on clearly bad appview cursors * fix pds appview proxy snaps * Appview v2 no notifs seen behavior (#2096) * alter behavior for presenting notifications w/ no last-seen time * fix pds proxy tests * Appview v2 dataplane retries based on client host (#2098) choose dataplane client for retries based on host when possible/relevant * don't apply negated labels * display suspensions on actor profile in appview v2 * Appview v2 use dataplane for identity lookups (#2095) * update bsky proto w/ identity methods * setup identity endpoints on mock dataplane * move from idresolver to dataplane for identity lookups on appview * tidy * Appview v2: apply safe takedown refs to records, actors (#2107) apply safe takedown refs to records, actors * Fix timing on appview v2 repo rev header (#2113) fix timing on appview repo rev * fix post thread responses * Appview v2 don't apply 3p self blocks (#2112) do not apply 3p self-blocks * Appview v2 search for feed generators (#2118) * add protos for feedgen search * support feed search on getPopularFeedGenerators * Appview v2 config tidy (#2117) * remove mod and triage roles from appview * rename cdn and search config * remove custom feed harness from appview v2 * Appview v2: don't apply missing modlists (#2122) * dont apply missing mod lists * update mock dataplane * Update packages/bsky/src/hydration/hydrator.ts Co-authored-by: devin ivy <devinivy@gmail.com> * refactor & document a bit better * fix up other routes --------- Co-authored-by: devin ivy <devinivy@gmail.com> * Appview v2 enforce post thread root boundary (#2120) * enforce post thread root boundary * test thread root boundary * Appview v2 fix admin environment variable (#2137) fix admin env in appview v2 * Remove re-pagination from getSuggestions (#2145) * remove re-pagination from getSuggestions * fix test * Adjust wording for account suspension (#2153) adjust wording for account suspension * Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps * :sparkles: Show author feed of takendown author to admins only (#2197) * fold in cid, auth, tracing, node version changes * remove dead config from bsky service entrypoint * build * remove ozone test codepaths for appview v2 * tidy, docs fix --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 14:22:55 -06:00
const [identity, { takenDown }] = await Promise.all([
dataplane.getIdentityByDid({ did }).catch((err) => {
Feature: Appview v2 (#1924) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * filler commit * rm filler * server boilerplate * follows impl * posts impl * posts & likes impl * repost impl * profiles & handle null values * list impl * mutes impl * blocks impl * misc * feed gen impl * label impl * notifs impl * feeds impl * threads impl * early sketchwork * wip * stub out thick client * in-progress work on hydrator * tweak * hydrate profile labels, detail lists * feedgen hydration * protobuf tweaks * more protobuf tweaks * wip * snake case * moar snake case * tidy actor hydration * tidy parsing * type fixes, renaming, comments in hydrator * hydrate list items and likes * hydrate notifications * feed hydration * graph & label hydration * more record protobufs * pluralize * tweak pbs * use new methods * Setup dataplane grpc client/mock server (#1921) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * add record getter mocks * post view hydration * fix up mock dataplane to match new protos * missed one * wire up dataplane in ctx & dev-env * adding some basic views * feed hydration, add blocks to post hydration * pass over notification hydration * tidy * merge * implement getProfile * hydrate post aggregation and viewer state * fix * fix codegen * get some tests passing! * add takedowns & some like bugfixing * all profile tests passing! * likes test * follow endpoints using data plane * reorg follow block rules * reposts * post views! * implement getList w/ dataplane caveat * adjust dataplane getListMembers to return listitem uris * implement getListMutes and -Blocks w/ dataplane * suggestions * timeline * misc view fixes * view fixes for mutes, self-mute/block * author feed * feed gen routes * tidy * misc block/mute fixes * list feed & actor likes * implement getLists, fix some empty cursors * implement getMutes, empty profile description fix * implement getBlocks, block application fix * implement getSuggestedFollowsByActor, needs some fixes * feed generation * search routes * threads * tidy * fix some snaps * fix getSuggestedFollowsByActor * implement listNotifications * implement getUnreadCount w/ dataplane * implement notifications.updateSeen w/ dataplane * 3rd party blocking tests * blocked profile viewer * add search mocks * refactor getFeed * createPipeline -> createPipelineNew * basic replygating functionality on dataplane w/o filtering violating replies * hack threadgates into dataplane, apply gates * deterministic thread orders in dataplane * misc cleanup around dataplane * upgrade typescript to v5.3 * update typescript linter deps * sync bsky proto, codegen * update dataplane, sync with bsky proto updates * remove indexer, ingester, daemon, moderation services from appview * convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane * remove bsky services. db and indexing logic into mock dataplane. * remove tests not needed by appview v2, misc reorg * add basic in-mem repo subscription to dataplane mock * fix dev-env, bsky tests, bsky build * cull bsky service entrypoint * add bsky service readme * build * tidy * tidy, fix pds proxy tests * fix * fix bsky entrypoint deps * support http2 grpc client * build * fix dataplane bad tls config/default * support multiple dataplane urls, retry when unavailable * build * tidy/fix * move dataplane mock tests into their own dir * cover label hydration through timeline test * bring back labels in appview tests * remove unused db primary/replica/coordinator from bsky dataplane * bsky proto add cids to contracts, buf codegen * sync-up bsky data-plane w/ codegen updates * start using dataplane interaction endpoints * add file * avoid overfetching from dataplane, plumb feed items and cids * pass refs through for post viewer state * switch list feeds to use feed item in dataplane * handle not found err on get-thread dataplane call * support use of search service rather than dataplane methods * mark some appview v2 todos * tidy * still use dataplane on search endpoints when search service is not configured * fix pds test * fix up bsky tests & snaps * tidy migrations * fix appview-v2 docker build * Support label issuer tied to appview v2 (#2033) support label issuer tied to appview * Appview v2: handle empty cursor on list notifications (#2017) handle empty cursor on appview listnotifs * Update appview v2 to use author feed enum (#2047) * update bsky protos with author feed enum, misc feed item changes * support new author feed enums in dataplane * fix build * Appview v2: utilize sorted-at field in bsky protos (#2050) utilize new sorted-at field in bsky protos * remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts * Appview v2, sync w/ changes to protos (#2071) * sync bsky protos * sync-up bsky implementation w/ proto changes * Appview v2 initial implementation for getPopularFeedGenerators (#2072) add an initial implementation for getPopularFeedGenerators on appview v2 * merge * fixes * fix feed tests * fix bsync mock * format * remove unused config * fix lockfile * another lockfile fix * fix duplicate type * fix dupplicate test * Appview v2 handling clearly bad cursors (#2092) * make mock dataplane cursors different from v1 cursors * fail open on clearly bad appview cursors * fix pds appview proxy snaps * Appview v2 no notifs seen behavior (#2096) * alter behavior for presenting notifications w/ no last-seen time * fix pds proxy tests * Appview v2 dataplane retries based on client host (#2098) choose dataplane client for retries based on host when possible/relevant * don't apply negated labels * display suspensions on actor profile in appview v2 * Appview v2 use dataplane for identity lookups (#2095) * update bsky proto w/ identity methods * setup identity endpoints on mock dataplane * move from idresolver to dataplane for identity lookups on appview * tidy * Appview v2: apply safe takedown refs to records, actors (#2107) apply safe takedown refs to records, actors * Fix timing on appview v2 repo rev header (#2113) fix timing on appview repo rev * fix post thread responses * Appview v2 don't apply 3p self blocks (#2112) do not apply 3p self-blocks * Appview v2 search for feed generators (#2118) * add protos for feedgen search * support feed search on getPopularFeedGenerators * Appview v2 config tidy (#2117) * remove mod and triage roles from appview * rename cdn and search config * remove custom feed harness from appview v2 * Appview v2: don't apply missing modlists (#2122) * dont apply missing mod lists * update mock dataplane * Update packages/bsky/src/hydration/hydrator.ts Co-authored-by: devin ivy <devinivy@gmail.com> * refactor & document a bit better * fix up other routes --------- Co-authored-by: devin ivy <devinivy@gmail.com> * Appview v2 enforce post thread root boundary (#2120) * enforce post thread root boundary * test thread root boundary * Appview v2 fix admin environment variable (#2137) fix admin env in appview v2 * Remove re-pagination from getSuggestions (#2145) * remove re-pagination from getSuggestions * fix test * Adjust wording for account suspension (#2153) adjust wording for account suspension * Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps * :sparkles: Show author feed of takendown author to admins only (#2197) * fold in cid, auth, tracing, node version changes * remove dead config from bsky service entrypoint * build * remove ozone test codepaths for appview v2 * tidy, docs fix --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 14:22:55 -06:00
if (isDataplaneError(err, Code.NotFound)) {
return undefined
}
throw err
}),
dataplane.getBlobTakedown({ did, cid: cid.toString() }),
2023-04-23 23:58:10 -04:00
])
if (takenDown) {
throw createError(404, 'Blob not found')
}
Feature: Appview v2 (#1924) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * filler commit * rm filler * server boilerplate * follows impl * posts impl * posts & likes impl * repost impl * profiles & handle null values * list impl * mutes impl * blocks impl * misc * feed gen impl * label impl * notifs impl * feeds impl * threads impl * early sketchwork * wip * stub out thick client * in-progress work on hydrator * tweak * hydrate profile labels, detail lists * feedgen hydration * protobuf tweaks * more protobuf tweaks * wip * snake case * moar snake case * tidy actor hydration * tidy parsing * type fixes, renaming, comments in hydrator * hydrate list items and likes * hydrate notifications * feed hydration * graph & label hydration * more record protobufs * pluralize * tweak pbs * use new methods * Setup dataplane grpc client/mock server (#1921) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * add record getter mocks * post view hydration * fix up mock dataplane to match new protos * missed one * wire up dataplane in ctx & dev-env * adding some basic views * feed hydration, add blocks to post hydration * pass over notification hydration * tidy * merge * implement getProfile * hydrate post aggregation and viewer state * fix * fix codegen * get some tests passing! * add takedowns & some like bugfixing * all profile tests passing! * likes test * follow endpoints using data plane * reorg follow block rules * reposts * post views! * implement getList w/ dataplane caveat * adjust dataplane getListMembers to return listitem uris * implement getListMutes and -Blocks w/ dataplane * suggestions * timeline * misc view fixes * view fixes for mutes, self-mute/block * author feed * feed gen routes * tidy * misc block/mute fixes * list feed & actor likes * implement getLists, fix some empty cursors * implement getMutes, empty profile description fix * implement getBlocks, block application fix * implement getSuggestedFollowsByActor, needs some fixes * feed generation * search routes * threads * tidy * fix some snaps * fix getSuggestedFollowsByActor * implement listNotifications * implement getUnreadCount w/ dataplane * implement notifications.updateSeen w/ dataplane * 3rd party blocking tests * blocked profile viewer * add search mocks * refactor getFeed * createPipeline -> createPipelineNew * basic replygating functionality on dataplane w/o filtering violating replies * hack threadgates into dataplane, apply gates * deterministic thread orders in dataplane * misc cleanup around dataplane * upgrade typescript to v5.3 * update typescript linter deps * sync bsky proto, codegen * update dataplane, sync with bsky proto updates * remove indexer, ingester, daemon, moderation services from appview * convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane * remove bsky services. db and indexing logic into mock dataplane. * remove tests not needed by appview v2, misc reorg * add basic in-mem repo subscription to dataplane mock * fix dev-env, bsky tests, bsky build * cull bsky service entrypoint * add bsky service readme * build * tidy * tidy, fix pds proxy tests * fix * fix bsky entrypoint deps * support http2 grpc client * build * fix dataplane bad tls config/default * support multiple dataplane urls, retry when unavailable * build * tidy/fix * move dataplane mock tests into their own dir * cover label hydration through timeline test * bring back labels in appview tests * remove unused db primary/replica/coordinator from bsky dataplane * bsky proto add cids to contracts, buf codegen * sync-up bsky data-plane w/ codegen updates * start using dataplane interaction endpoints * add file * avoid overfetching from dataplane, plumb feed items and cids * pass refs through for post viewer state * switch list feeds to use feed item in dataplane * handle not found err on get-thread dataplane call * support use of search service rather than dataplane methods * mark some appview v2 todos * tidy * still use dataplane on search endpoints when search service is not configured * fix pds test * fix up bsky tests & snaps * tidy migrations * fix appview-v2 docker build * Support label issuer tied to appview v2 (#2033) support label issuer tied to appview * Appview v2: handle empty cursor on list notifications (#2017) handle empty cursor on appview listnotifs * Update appview v2 to use author feed enum (#2047) * update bsky protos with author feed enum, misc feed item changes * support new author feed enums in dataplane * fix build * Appview v2: utilize sorted-at field in bsky protos (#2050) utilize new sorted-at field in bsky protos * remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts * Appview v2, sync w/ changes to protos (#2071) * sync bsky protos * sync-up bsky implementation w/ proto changes * Appview v2 initial implementation for getPopularFeedGenerators (#2072) add an initial implementation for getPopularFeedGenerators on appview v2 * merge * fixes * fix feed tests * fix bsync mock * format * remove unused config * fix lockfile * another lockfile fix * fix duplicate type * fix dupplicate test * Appview v2 handling clearly bad cursors (#2092) * make mock dataplane cursors different from v1 cursors * fail open on clearly bad appview cursors * fix pds appview proxy snaps * Appview v2 no notifs seen behavior (#2096) * alter behavior for presenting notifications w/ no last-seen time * fix pds proxy tests * Appview v2 dataplane retries based on client host (#2098) choose dataplane client for retries based on host when possible/relevant * don't apply negated labels * display suspensions on actor profile in appview v2 * Appview v2 use dataplane for identity lookups (#2095) * update bsky proto w/ identity methods * setup identity endpoints on mock dataplane * move from idresolver to dataplane for identity lookups on appview * tidy * Appview v2: apply safe takedown refs to records, actors (#2107) apply safe takedown refs to records, actors * Fix timing on appview v2 repo rev header (#2113) fix timing on appview repo rev * fix post thread responses * Appview v2 don't apply 3p self blocks (#2112) do not apply 3p self-blocks * Appview v2 search for feed generators (#2118) * add protos for feedgen search * support feed search on getPopularFeedGenerators * Appview v2 config tidy (#2117) * remove mod and triage roles from appview * rename cdn and search config * remove custom feed harness from appview v2 * Appview v2: don't apply missing modlists (#2122) * dont apply missing mod lists * update mock dataplane * Update packages/bsky/src/hydration/hydrator.ts Co-authored-by: devin ivy <devinivy@gmail.com> * refactor & document a bit better * fix up other routes --------- Co-authored-by: devin ivy <devinivy@gmail.com> * Appview v2 enforce post thread root boundary (#2120) * enforce post thread root boundary * test thread root boundary * Appview v2 fix admin environment variable (#2137) fix admin env in appview v2 * Remove re-pagination from getSuggestions (#2145) * remove re-pagination from getSuggestions * fix test * Adjust wording for account suspension (#2153) adjust wording for account suspension * Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps * :sparkles: Show author feed of takendown author to admins only (#2197) * fold in cid, auth, tracing, node version changes * remove dead config from bsky service entrypoint * build * remove ozone test codepaths for appview v2 * tidy, docs fix --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 14:22:55 -06:00
const services = identity && unpackIdentityServices(identity.services)
const pds =
services &&
getServiceEndpoint(services, {
id: 'atproto_pds',
type: 'AtprotoPersonalDataServer',
})
Feature: Appview v2 (#1924) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * filler commit * rm filler * server boilerplate * follows impl * posts impl * posts & likes impl * repost impl * profiles & handle null values * list impl * mutes impl * blocks impl * misc * feed gen impl * label impl * notifs impl * feeds impl * threads impl * early sketchwork * wip * stub out thick client * in-progress work on hydrator * tweak * hydrate profile labels, detail lists * feedgen hydration * protobuf tweaks * more protobuf tweaks * wip * snake case * moar snake case * tidy actor hydration * tidy parsing * type fixes, renaming, comments in hydrator * hydrate list items and likes * hydrate notifications * feed hydration * graph & label hydration * more record protobufs * pluralize * tweak pbs * use new methods * Setup dataplane grpc client/mock server (#1921) * add buf & connectrpc, codegen client * lint * prettier ignore * fix prettier ignore * tidy & add tests * add record getter mocks * post view hydration * fix up mock dataplane to match new protos * missed one * wire up dataplane in ctx & dev-env * adding some basic views * feed hydration, add blocks to post hydration * pass over notification hydration * tidy * merge * implement getProfile * hydrate post aggregation and viewer state * fix * fix codegen * get some tests passing! * add takedowns & some like bugfixing * all profile tests passing! * likes test * follow endpoints using data plane * reorg follow block rules * reposts * post views! * implement getList w/ dataplane caveat * adjust dataplane getListMembers to return listitem uris * implement getListMutes and -Blocks w/ dataplane * suggestions * timeline * misc view fixes * view fixes for mutes, self-mute/block * author feed * feed gen routes * tidy * misc block/mute fixes * list feed & actor likes * implement getLists, fix some empty cursors * implement getMutes, empty profile description fix * implement getBlocks, block application fix * implement getSuggestedFollowsByActor, needs some fixes * feed generation * search routes * threads * tidy * fix some snaps * fix getSuggestedFollowsByActor * implement listNotifications * implement getUnreadCount w/ dataplane * implement notifications.updateSeen w/ dataplane * 3rd party blocking tests * blocked profile viewer * add search mocks * refactor getFeed * createPipeline -> createPipelineNew * basic replygating functionality on dataplane w/o filtering violating replies * hack threadgates into dataplane, apply gates * deterministic thread orders in dataplane * misc cleanup around dataplane * upgrade typescript to v5.3 * update typescript linter deps * sync bsky proto, codegen * update dataplane, sync with bsky proto updates * remove indexer, ingester, daemon, moderation services from appview * convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane * remove bsky services. db and indexing logic into mock dataplane. * remove tests not needed by appview v2, misc reorg * add basic in-mem repo subscription to dataplane mock * fix dev-env, bsky tests, bsky build * cull bsky service entrypoint * add bsky service readme * build * tidy * tidy, fix pds proxy tests * fix * fix bsky entrypoint deps * support http2 grpc client * build * fix dataplane bad tls config/default * support multiple dataplane urls, retry when unavailable * build * tidy/fix * move dataplane mock tests into their own dir * cover label hydration through timeline test * bring back labels in appview tests * remove unused db primary/replica/coordinator from bsky dataplane * bsky proto add cids to contracts, buf codegen * sync-up bsky data-plane w/ codegen updates * start using dataplane interaction endpoints * add file * avoid overfetching from dataplane, plumb feed items and cids * pass refs through for post viewer state * switch list feeds to use feed item in dataplane * handle not found err on get-thread dataplane call * support use of search service rather than dataplane methods * mark some appview v2 todos * tidy * still use dataplane on search endpoints when search service is not configured * fix pds test * fix up bsky tests & snaps * tidy migrations * fix appview-v2 docker build * Support label issuer tied to appview v2 (#2033) support label issuer tied to appview * Appview v2: handle empty cursor on list notifications (#2017) handle empty cursor on appview listnotifs * Update appview v2 to use author feed enum (#2047) * update bsky protos with author feed enum, misc feed item changes * support new author feed enums in dataplane * fix build * Appview v2: utilize sorted-at field in bsky protos (#2050) utilize new sorted-at field in bsky protos * remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts * Appview v2, sync w/ changes to protos (#2071) * sync bsky protos * sync-up bsky implementation w/ proto changes * Appview v2 initial implementation for getPopularFeedGenerators (#2072) add an initial implementation for getPopularFeedGenerators on appview v2 * merge * fixes * fix feed tests * fix bsync mock * format * remove unused config * fix lockfile * another lockfile fix * fix duplicate type * fix dupplicate test * Appview v2 handling clearly bad cursors (#2092) * make mock dataplane cursors different from v1 cursors * fail open on clearly bad appview cursors * fix pds appview proxy snaps * Appview v2 no notifs seen behavior (#2096) * alter behavior for presenting notifications w/ no last-seen time * fix pds proxy tests * Appview v2 dataplane retries based on client host (#2098) choose dataplane client for retries based on host when possible/relevant * don't apply negated labels * display suspensions on actor profile in appview v2 * Appview v2 use dataplane for identity lookups (#2095) * update bsky proto w/ identity methods * setup identity endpoints on mock dataplane * move from idresolver to dataplane for identity lookups on appview * tidy * Appview v2: apply safe takedown refs to records, actors (#2107) apply safe takedown refs to records, actors * Fix timing on appview v2 repo rev header (#2113) fix timing on appview repo rev * fix post thread responses * Appview v2 don't apply 3p self blocks (#2112) do not apply 3p self-blocks * Appview v2 search for feed generators (#2118) * add protos for feedgen search * support feed search on getPopularFeedGenerators * Appview v2 config tidy (#2117) * remove mod and triage roles from appview * rename cdn and search config * remove custom feed harness from appview v2 * Appview v2: don't apply missing modlists (#2122) * dont apply missing mod lists * update mock dataplane * Update packages/bsky/src/hydration/hydrator.ts Co-authored-by: devin ivy <devinivy@gmail.com> * refactor & document a bit better * fix up other routes --------- Co-authored-by: devin ivy <devinivy@gmail.com> * Appview v2 enforce post thread root boundary (#2120) * enforce post thread root boundary * test thread root boundary * Appview v2 fix admin environment variable (#2137) fix admin env in appview v2 * Remove re-pagination from getSuggestions (#2145) * remove re-pagination from getSuggestions * fix test * Adjust wording for account suspension (#2153) adjust wording for account suspension * Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps * :sparkles: Show author feed of takendown author to admins only (#2197) * fold in cid, auth, tracing, node version changes * remove dead config from bsky service entrypoint * build * remove ozone test codepaths for appview v2 * tidy, docs fix --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 14:22:55 -06:00
if (!pds) {
throw createError(404, 'Origin not found')
}
2023-04-23 23:58:10 -04:00
return pds
Bsky app view (#716) * Init pulling bsky app view from pds package into its own package, remove sqlite db dialect * Cull bsky config, services, auth, etc. * Sweep app view xrpc methods, tidy deps, add storage back for img server * Run repo subscription on bsky app view * Collapse db migrations down for bsky app view * Tidy app view bin * Remove mute functionality from app view, delegate to pds * Initial tidy/culling of bsky app view tests * Passing bsky app view db, server, and repo subscription tests * Passing bsky app view duplicate-records tests * Bsky app view test tidy/cull * In bsky app view replace repo_root, ipld_block, did_handle with actor and record tables. Remove assertions/confirmations. * Update bsky impl for simpler actor and record tables, removed asserion/confirmations. Skip indexing unknown collections. * Setup actor handles by did in bsky app view * Passing indexing tests on bsky app view * Passing image tests on bsky app view * Fix bsky actor reindexing, support custom lock id for testing repo subs * Sweep bsky view tests, misc tests, passing * Tidy bsky deps * Include did in resized image uris * Update bsky image process server to use getBlob * Update image server tests, misc fixes * Implement bsky blob resolver * Wire local image processing server to local blob resolver, test blob resolver * Tidy * Tidy * Tidy * Tidy app view init * Fix handle resolution, tidy * Add utils for partitioning indexing by did * Update repo sub to parallelize work per repo * Dep tidy * Tidy bsky tests for updated repo sub destroy() * Update thead indexing to handle out-of-order posts * Sketch out strategy in bsky for handling too-big commits * Set content-type on sync.getBlob * Add logging for failed transmissions in bsky blob resolver * Tidy * Tidy bsky repo indexing and supporting repo interfaces * Sort in app view based on combo of creation and indexing times * Fix types * Add retry utils to bsky * Add retries to http requests made by bsky * Test repo indexing * Update bsky db/model for lex refactor * Update bsky lexicons for lex refactor * Update bsky actor service for lex refactor * Update bsky feed service for lex refactor * Update bsky indexing service for lex refactor * Update bsky repo subscription for lex refactor * Tidy bsky repo sub * Add unspecced endpoints to bsky app view, update entrypoint * Update bsky xrpc utils for lex refactor * Update bsky xrpc methods for lex refactor * Update bsky test seeds for lex refactor, tidy api entrypoint * Update bsky non-view tests for lex refactor * Update bsky likes view test for lex refactor, minor fix * Update bsky author feed tests for lex refactor, minor test util fix * Update bsky follow, profile, repost, search view tests for lex refactor * Update bsky timeline view tests for lex refactor * Replace bsky out-of-order thread indexing logic * Update bsky thread view tests for lex refactor, general test tidying * Handle rebases and too-big commits in repo subscription, tracking commit data cid * Tidy * Ensure did resolver reports "not found" only when positively not found * Handle tombstones and handle updates in bsky * Test indexing handle updates and did tombstones * Support cors on bsky * Allow app view to serve most routes unauthed * Tests for bsky unauthed views * Tidy bsky service entrypoint and dockerfile * Remove unused storage interfaces from bsky * Bsky entrypoint and dockerfile fixes, tidy * Add workflow for bsky build to aws * Use more standard db env variables, make migration creds optional * Make bsky repo subscription optional * Fix lex->json serialization in bsky * Split bsky actor sync state into its own table * Skip invalid records on indexing full repo, tidy * Tidy * Leader test timing * Tidy/lint * Fix bsky config overrides
2023-04-06 18:47:46 -04:00
}
function getBlobHeaders(
{
blobRateLimitBypassKey: bypassKey,
blobRateLimitBypassHostname: bypassHostname,
}: ServerConfig,
url: URL,
): Map<string, string> {
const headers = new Map<string, string>()
headers.set('user-agent', BSKY_USER_AGENT)
if (bypassKey && bypassHostname) {
const matchesUrl = bypassHostname.startsWith('.')
? url.hostname.endsWith(bypassHostname)
: url.hostname === bypassHostname
if (matchesUrl) {
headers.set('x-ratelimit-bypass', bypassKey)
}
}
return headers
}
/**
* This function creates a passthrough stream that will decompress (if needed)
* and verify the CID of the input stream. The output data will be identical to
* the input data.
*
* If you need the un-compressed data, you should use a decompress + verify
* pipeline instead.
*/
function createCidVerifier(cid: CID, encoding?: string | string[]): Duplex {
// If the upstream content is compressed, we do not want to return a
// de-compressed stream here. Indeed, the "compression" middleware will
// compress the response before it is sent downstream, if it is not already
// compressed. Because of this, it is preferable to return the content as-is
// to avoid re-compressing it.
//
// We do still want to be able to verify the CID, which requires decompressing
// the input bytes.
//
// To that end, we create a passthrough in order to "tee" the stream into two
// streams: one that will be sent, unaltered, downstream, and a pipeline that
// will be used to decompress & verify the CID (discarding de-compressed
// data).
const decoders = createDecoders(encoding)
const verifier = new VerifyCidTransform(cid)
// Optimization: If the content is not compressed, we don't need to "tee" the
// stream, we can use the verifier as simple passthrough.
if (!decoders.length) return verifier
const pipelineController = new AbortController()
const pipelineStreams: Duplex[] = [...decoders, verifier]
const pipelineInput = pipelineStreams[0]!
// Create a promise that will resolve if, and only if, the decoding and
// verification succeed.
const pipelinePromise: Promise<null | Error> = pipeline(pipelineStreams, {
signal: pipelineController.signal,
}).then(
() => null,
(err) => {
const error = asError(err)
// the data being processed by the pipeline is invalid (e.g. invalid
// compressed content, non-matching the CID, ...). If that occurs, we can
// destroy the passthrough (this allows not to wait for the "flush" event
// to propagate the error).
passthrough.destroy(error)
return error
},
)
// We don't care about the un-compressed data, we only use the verifier to
// detect any error through the pipelinePromise. We still need to pass the
// verifier into flowing mode to ensure that the pipelinePromise resolves.
verifier.resume()
const passthrough = new Transform({
transform(chunk, encoding, callback) {
pipelineInput.write(chunk, encoding)
callback(null, chunk)
},
flush(callback) {
// End the input stream, which will resolve the pipeline promise
pipelineInput.end()
// End the pass-through stream according to the result of the pipeline
pipelinePromise.then(callback)
},
destroy(err, callback) {
pipelineController.abort() // Causes pipeline() to destroy all streams
callback(err)
},
})
return passthrough
}
function asError(err: unknown): Error {
return err instanceof Error
? err
: new Error('Processing failed', { cause: err })
}