Skip to content

Commit

Permalink
fix: allow non expiring claims
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Jul 31, 2023
1 parent b2bce88 commit ffce3b7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/lambda/src/lib/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { BlockIndexClaimFetcher } from './block-index.js'
export class ClaimStorage extends DynamoTable {
/** @param {import('@web3-storage/content-claims/server/api').Claim} claim */
async put ({ claim, bytes, content, expiration }) {
const hasExpiration = expiration && isFinite(expiration)
const cmd = new UpdateItemCommand({
TableName: this.tableName,
Key: marshall({
Expand All @@ -25,9 +26,11 @@ export class ClaimStorage extends DynamoTable {
}),
ExpressionAttributeValues: marshall({
':by': bytes,
':ex': expiration
':ex': hasExpiration ? expiration : undefined
}, { removeUndefinedValues: true, convertClassInstanceToMap: true }),
UpdateExpression: 'SET bytes=if_not_exists(bytes, :by), expiration=if_not_exists(expiration, :ex)'
UpdateExpression: hasExpiration
? 'SET bytes=if_not_exists(bytes, :by), expiration=if_not_exists(expiration, :ex)'
: 'SET bytes=if_not_exists(bytes, :by) REMOVE expiration'
})
await this.dynamoClient.send(cmd)
}
Expand Down

0 comments on commit ffce3b7

Please sign in to comment.