From ffce3b73dcc9c93dc6e3c68d993f35bf53dff100 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 31 Jul 2023 18:08:54 +0200 Subject: [PATCH] fix: allow non expiring claims --- packages/lambda/src/lib/store/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/lambda/src/lib/store/index.js b/packages/lambda/src/lib/store/index.js index c311112..bbbda64 100644 --- a/packages/lambda/src/lib/store/index.js +++ b/packages/lambda/src/lib/store/index.js @@ -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({ @@ -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) }