forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List blobs method (bluesky-social#662)
* add list blobs method * tests + small bugfix * one more test
- Loading branch information
Showing
11 changed files
with
348 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "com.atproto.sync.listBlobs", | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "List blob cids for some range of commits", | ||
"parameters": { | ||
"type": "params", | ||
"required": ["did"], | ||
"properties": { | ||
"did": {"type": "string", "description": "The DID of the repo."}, | ||
"latest": { "type": "string", "description": "The most recent commit"}, | ||
"earliest": { "type": "string", "description": "The earliest commit to start from"} | ||
} | ||
}, | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["cids"], | ||
"properties": { | ||
"cids": { | ||
"type": "array", | ||
"items": { "type": "string" } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/api/src/client/types/com/atproto/sync/listBlobs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
|
||
export interface QueryParams { | ||
/** The DID of the repo. */ | ||
did: string | ||
/** The most recent commit */ | ||
latest?: string | ||
/** The earliest commit to start from */ | ||
earliest?: string | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
cids: string[] | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: Headers | ||
data: OutputSchema | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
} | ||
return e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CID } from 'multiformats/cid' | ||
import { InvalidRequestError } from '@atproto/xrpc-server' | ||
import { Server } from '../../../../lexicon' | ||
import SqlRepoStorage from '../../../../sql-repo-storage' | ||
import AppContext from '../../../../context' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.com.atproto.sync.listBlobs(async ({ params }) => { | ||
const { did } = params | ||
const storage = new SqlRepoStorage(ctx.db, did) | ||
const earliest = params.earliest ? CID.parse(params.earliest) : null | ||
const latest = params.latest | ||
? CID.parse(params.latest) | ||
: await storage.getHead() | ||
if (latest === null) { | ||
throw new InvalidRequestError(`Could not find root for DID: ${did}`) | ||
} | ||
const commitPath = await storage.getCommitPath(latest, earliest) | ||
if (commitPath === null) { | ||
throw new InvalidRequestError( | ||
`Could not find a valid commit path from ${latest.toString()} to ${earliest?.toString()}`, | ||
) | ||
} | ||
const cids = await ctx.services | ||
.repo(ctx.db) | ||
.blobs.listForCommits(did, commitPath) | ||
|
||
return { | ||
encoding: 'application/json', | ||
body: { | ||
cids: cids.map((c) => c.toString()), | ||
}, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/pds/src/lexicon/types/com/atproto/sync/listBlobs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import express from 'express' | ||
import { ValidationResult } from '@atproto/lexicon' | ||
import { lexicons } from '../../../../lexicons' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { HandlerAuth } from '@atproto/xrpc-server' | ||
|
||
export interface QueryParams { | ||
/** The DID of the repo. */ | ||
did: string | ||
/** The most recent commit */ | ||
latest?: string | ||
/** The earliest commit to start from */ | ||
earliest?: string | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
cids: string[] | ||
[k: string]: unknown | ||
} | ||
|
||
export type HandlerInput = undefined | ||
|
||
export interface HandlerSuccess { | ||
encoding: 'application/json' | ||
body: OutputSchema | ||
} | ||
|
||
export interface HandlerError { | ||
status: number | ||
message?: string | ||
} | ||
|
||
export type HandlerOutput = HandlerError | HandlerSuccess | ||
export type Handler<HA extends HandlerAuth = never> = (ctx: { | ||
auth: HA | ||
params: QueryParams | ||
input: HandlerInput | ||
req: express.Request | ||
res: express.Response | ||
}) => Promise<HandlerOutput> | HandlerOutput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.