Skip to content

Commit

Permalink
fix(ipns): correct getIpns
Browse files Browse the repository at this point in the history
  • Loading branch information
gitwoz committed Nov 6, 2024
1 parent 38cd48d commit dc63cab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions handlers/refresh-ipns-gw3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const handler = async (
forceReplace?: boolean
useMattersIPNS?: boolean
}
console.log('event:', event)

const { limit = 50, concurrency = 5, forceReplace, useMattersIPNS } = body
let names: string[] = []
Expand Down
21 changes: 12 additions & 9 deletions lib/refresh-ipns-gw3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ class GW3Client {
}

async dagImport(file: File | Blob | string) {
const size =
(file as Blob).size ??
// (file as Buffer).byteLength ??
(file as any).length
const size = (file as Blob).size ?? (file as any).length

const res = await fetch(
`https://gw3.io/api/v0/dag/import?size=${size}&ts=${getTs()}`,
Expand Down Expand Up @@ -180,10 +177,10 @@ class GW3Client {
)

const body = new FormData()
body.set('file', file)
const blob = file instanceof Blob ? file : new Blob([file])
body.set('file', blob)
const res2 = await fetch(importUrl, {
method: 'POST',
// headers: { "Content-Type": "multipart/form-data", },
body,
})
console.log(
Expand Down Expand Up @@ -349,7 +346,7 @@ class GW3Client {
method: 'GET',
headers: this.#authHeaders,
})
// console.log(new Date(), "getPin res:", res.ok, res.status, res.headers);
console.log(new Date(), 'getIpns res:', res.ok, res.status, res.headers)

return res.json()
}
Expand All @@ -363,7 +360,13 @@ class GW3Client {
method: 'GET',
headers: this.#authHeaders,
})
console.log(new Date(), 'search IPNS res:', res.ok, res.status, res.headers)
console.log(
new Date(),
'getIpnsByName res:',
res.ok,
res.status,
res.headers
)

return res.json()
}
Expand Down Expand Up @@ -1308,7 +1311,7 @@ export async function refreshIPNSFeed(

if (resGetIpns1?.code === 200) {
// existed: do update
if (resGetIpns1?.data.value === lastCid) {
if (resGetIpns1?.data?.value === lastCid) {
console.log(new Date(), `lastCid remained the same, no need to update:`, {
// testGw3IPNSKey,
keyPair, // .ipnsKey,
Expand Down

0 comments on commit dc63cab

Please sign in to comment.