Skip to content

Commit

Permalink
fix: add blob list and remove infra (#355)
Browse files Browse the repository at this point in the history
We just need to update `upload-api` dep
storacha/w3up#1387 and get
`AllocationsStorage` implementation to implement `remove`. All tests run
as part of the interface tests imported from
https://github.com/web3-storage/w3up/blob/main/packages/upload-api/test/handlers/blob.js

Also note that `filecoin-api` was updated (internally to `upload-api`
and the options for filecoin storefront skip submit queue were removed,
therefore storacha/w3up#1371
  • Loading branch information
vasco-santos authored Apr 24, 2024
1 parent 24d22ee commit af4700c
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 60 deletions.
2 changes: 1 addition & 1 deletion filecoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@ucanto/principal": "^9.0.1",
"@ucanto/transport": "^9.1.1",
"@web3-storage/data-segment": "^5.1.0",
"@web3-storage/filecoin-api": "^4.6.1",
"@web3-storage/filecoin-api": "^5.0.0",
"@web3-storage/filecoin-client": "^3.3.1",
"fr32-sha2-256-trunc254-padded-binary-tree-multihash": "^3.3.0",
"multiformats": "^13.1.0",
Expand Down
157 changes: 112 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@aws-sdk/client-dynamodb": "^3.226.0",
"@aws-sdk/util-dynamodb": "^3.226.0",
"@ipld/dag-ucan": "3.4.0",
"@web3-storage/capabilities": "^12.1.0",
"@web3-storage/capabilities": "^14.0.0",
"@web3-storage/data-segment": "5.0.0",
"sade": "^1.8.1"
}
Expand Down
5 changes: 0 additions & 5 deletions upload-api/functions/ucan-invocation-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ export async function ucanInvocationRouter(request) {
with: serviceSigner.did()
}
},
options: {
// TODO: we compute and put all pieces into the queue on bucket event
// We may change this to validate user provided piece
skipFilecoinSubmitQueue: false
},
plansStorage,
requirePaymentPlan,
usageStorage,
Expand Down
4 changes: 2 additions & 2 deletions upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@ucanto/validator": "^9.0.2",
"@web-std/fetch": "^4.1.0",
"@web3-storage/access": "^18.3.1",
"@web3-storage/capabilities": "^13.3.1",
"@web3-storage/capabilities": "^14.0.0",
"@web3-storage/did-mailto": "^2.1.0",
"@web3-storage/upload-api": "^9.1.5",
"@web3-storage/upload-api": "^10.0.0",
"multiformats": "^13.1.0",
"nanoid": "^5.0.2",
"preact": "^10.14.1",
Expand Down
51 changes: 45 additions & 6 deletions upload-api/stores/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
GetItemCommand,
PutItemCommand,
QueryCommand,
DeleteItemCommand,
} from '@aws-sdk/client-dynamodb'
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb'
import { RecordKeyConflict, RecordNotFound } from '@web3-storage/upload-api/errors'
import { RecordKeyConflict, RecordNotFound, StorageOperationFailed } from '@web3-storage/upload-api/errors'
import { base58btc } from 'multiformats/bases/base58'
import * as Link from 'multiformats/link'

Expand Down Expand Up @@ -126,6 +127,44 @@ export function useAllocationsStorage(dynamoDb, tableName) {
}
return { ok: { blob } }
},
/**
* @param {import('@web3-storage/upload-api').DID} space
* @param {Uint8Array} blobMultihash
* @returns {ReturnType<AllocationsStorage['remove']>}
*/
async remove(space, blobMultihash) {
const key = getKey(space, blobMultihash)
const cmd = new DeleteItemCommand({
TableName: tableName,
Key: key,
ConditionExpression: 'attribute_exists(#S) AND attribute_exists(#M)',
ExpressionAttributeNames: { '#S': 'space', '#M': 'multihash' },
ReturnValues: 'ALL_OLD'
})

try {
const res = await dynamoDb.send(cmd)
if (!res.Attributes) {
throw new Error('missing return values')
}

const raw = unmarshall(res.Attributes)
return {
ok: {
size: Number(raw.size)
}
}
} catch (/** @type {any} */ err) {
if (err.name === 'ConditionalCheckFailedException') {
return {
error: new RecordNotFound()
}
}
return {
error: new StorageOperationFailed(err.name)
}
}
},
/**
* List all CARs bound to an account
*
Expand All @@ -137,7 +176,7 @@ export function useAllocationsStorage(dynamoDb, tableName) {
const exclusiveStartKey = options.cursor
? marshall({
space,
link: options.cursor,
multihash: options.cursor,
})
: undefined

Expand All @@ -150,7 +189,6 @@ export function useAllocationsStorage(dynamoDb, tableName) {
AttributeValueList: [{ S: space }],
},
},
ScanIndexForward: !options.pre,
ExclusiveStartKey: exclusiveStartKey,
AttributesToGet: ['multihash', 'size', 'insertedAt'],
})
Expand All @@ -165,15 +203,16 @@ export function useAllocationsStorage(dynamoDb, tableName) {
response.LastEvaluatedKey && unmarshall(response.LastEvaluatedKey)
const lastLinkCID = lastKey ? lastKey.multihash : undefined

const before = options.pre ? lastLinkCID : firstLinkCID
const after = options.pre ? firstLinkCID : lastLinkCID
const before = firstLinkCID
const after = lastLinkCID

return {
ok: {
size: results.length,
before,
after,
cursor: after,
results: options.pre ? results.reverse() : results,
results,
}
}
},
Expand Down

0 comments on commit af4700c

Please sign in to comment.