Skip to content

Commit 5488285

Browse files
committed
add w3up-storage/capabilities lib + minor fixes
1 parent 95f0331 commit 5488285

File tree

4 files changed

+39
-44
lines changed

4 files changed

+39
-44
lines changed

package-lock.json

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@ucanto/principal": "^8.1.0",
4040
"@ucanto/transport": "^9.1.1",
4141
"@web3-storage/blob-fetcher": "^2.2.0",
42+
"@web3-storage/capabilities": "^17.4.1",
4243
"@web3-storage/gateway-lib": "^5.1.2",
4344
"dagula": "^8.0.0",
4445
"http-range-parse": "^1.0.0",

src/middleware/withUcantoClient.capabilities.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/middleware/withUcantoClient.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as CAR from '@ucanto/transport/car'
33
import { SpaceDID } from '@web3-storage/capabilities/utils'
44
import { Verifier, Signer } from '@ucanto/principal/ed25519'
55
import { HTTP } from '@ucanto/transport'
6-
import { Usage } from './withUcantoClient.capabilities.js'
6+
import { Space } from '@web3-storage/capabilities'
77

88
/**
99
* @import { Middleware } from '@web3-storage/gateway-lib'
@@ -46,7 +46,7 @@ async function create (env) {
4646
* @returns {Promise<void>}
4747
*/
4848
record: async (space, resource, bytes, servedAt) =>
49-
recordEgress(space, resource, bytes, servedAt, principal, service, connection),
49+
egressRecord(space, resource, bytes, servedAt, principal, service, connection),
5050

5151
/**
5252
* TODO: implement this function
@@ -91,17 +91,19 @@ async function connect (serverUrl, principal) {
9191
* @param {any} connection - The connection to execute the command
9292
* @returns {Promise<void>}
9393
*/
94-
async function recordEgress (space, resource, bytes, servedAt, principal, service, connection) {
95-
const res = await Usage.record.invoke({
96-
issuer: principal,
97-
audience: service,
98-
with: SpaceDID.from(space),
99-
nb: {
100-
resource,
101-
bytes,
102-
servedAt: Math.floor(servedAt.getTime() / 1000)
103-
}
104-
}).execute(connection)
94+
async function egressRecord (space, resource, bytes, servedAt, principal, service, connection) {
95+
const res = await Space.egressRecord
96+
.invoke({
97+
issuer: principal,
98+
audience: service,
99+
with: SpaceDID.from(space),
100+
nb: {
101+
resource,
102+
bytes,
103+
servedAt: Math.floor(servedAt.getTime() / 1000)
104+
}
105+
})
106+
.execute(connection)
105107

106108
if (res.out.error) {
107109
console.error('Failed to record egress', res.out.error)

0 commit comments

Comments
 (0)