Skip to content

Commit 9b35c67

Browse files
authored
Merge pull request #142 from lighthouse-web3/v0.4.7
V0.4.7
2 parents d5d86db + c362c41 commit 9b35c67

9 files changed

Lines changed: 118 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lighthouse <img src="https://img.shields.io/badge/v0.4.6-green"/>
1+
# Lighthouse <img src="https://img.shields.io/badge/v0.4.7-green"/>
22

33
Lighthouse is a permanent decentralized file storage protocol that allows the ability to pay once and store forever. While traditionally, users need to repeatedly keep track and pay for their storage after every fixed amount of time, Lighthouse manages this for them and makes sure that user files are stored forever. The aim is to move users from a rent-based cost model where they are renting their own files on cloud storage to a permanent ownership model. It is built on top of IPFS, Filecoin, and Polygon. It uses the existing miner network and storage capacity of the filecoin network.
44

package-lock.json

Lines changed: 2 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lighthouse-web3/sdk",
3-
"version": "0.4.6",
3+
"version": "0.4.7",
44
"description": "NPM package and CLI tool to interact with lighthouse protocol",
55
"main": "./dist/Lighthouse/index.js",
66
"types": "./dist/Lighthouse/index.d.ts",

src/Commands/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import shareFile from './share-file'
1111
import getUploads from './get-uploads'
1212
import deleteFile from './delete-file'
1313
import dealStatus from './deal-status'
14+
import walrusBlobs from './walrus-blobs'
1415
import decryptFile from './decrypt-file'
1516
import createWallet from './create-wallet'
1617
import walletForget from './wallet-forget'
@@ -72,7 +73,7 @@ Command.prototype.helpInformation = function (context: any) {
7273
}
7374

7475
widgets.addHelpText('before', 'Welcome to lighthouse-web3')
75-
widgets.version('0.4.6')
76+
widgets.version('0.4.7')
7677

7778
widgets
7879
.command('wallet')
@@ -160,6 +161,12 @@ widgets
160161
.description('Get filecoin deal status of a CID')
161162
.action(dealStatus)
162163

164+
widgets
165+
.command('walrus-blobs')
166+
.argument('<cid>', 'File Cid')
167+
.description('Get walrus blob IDs for a CID')
168+
.action(walrusBlobs)
169+
163170
widgets
164171
.command('get-uploads')
165172
.description('Get details of file uploaded')

src/Commands/walrus-blobs.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { yellow, red } from 'kleur'
2+
import lighthouse from '../Lighthouse'
3+
4+
export default async function (cid: string) {
5+
try {
6+
if (!cid) {
7+
throw new Error('Please provide a CID.')
8+
}
9+
10+
const { blobIds } = await lighthouse.walrusBlobs(cid)
11+
12+
console.log(
13+
yellow('\r\nCID:') + Array(9).fill('\xa0').join('') + cid
14+
)
15+
16+
if (blobIds.length === 0) {
17+
console.log(yellow('\r\nNo walrus blobs found for this CID'))
18+
return
19+
}
20+
21+
console.log(
22+
'\r\n' +
23+
Array(4).fill('\xa0').join('') +
24+
yellow('Blob ID')
25+
)
26+
27+
for (let i = 0; i < blobIds.length; i++) {
28+
console.log(
29+
Array(4).fill('\xa0').join('') + blobIds[i] + '\r\n'
30+
)
31+
}
32+
} catch (error: any) {
33+
console.log(red(error.message))
34+
process.exit(0)
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { lighthouseConfig } from '../../lighthouse.config'
2+
3+
export type deleteFileResponseType = {
4+
data: {
5+
message: string
6+
}
7+
}
8+
9+
export default async (
10+
authToken: string,
11+
fileId: string
12+
): Promise<deleteFileResponseType> => {
13+
try {
14+
const response = await fetch(
15+
`${lighthouseConfig.lighthouseAPI}/api/user/delete_file_walrus?id=${fileId}`,
16+
{
17+
method: 'DELETE',
18+
headers: {
19+
Authorization: `Bearer ${authToken}`,
20+
'Content-Type': 'application/json',
21+
},
22+
}
23+
)
24+
25+
if (!response.ok) {
26+
throw new Error(`Request failed with status code ${response.status}`)
27+
}
28+
29+
const result = (await response.json()) as any
30+
/*
31+
Example response:
32+
{
33+
"message": "File deleted successfully."
34+
}
35+
*/
36+
return { data: result }
37+
} catch (error: any) {
38+
throw new Error(error.message)
39+
}
40+
}

src/Lighthouse/getUploads/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ export type uploadsResponseType = {
2323

2424
export default async (
2525
authToken: string,
26-
lastKey: string | null = null
26+
lastKey: string | null = null,
27+
fileType: string = 'all'
2728
): Promise<uploadsResponseType> => {
2829
try {
2930
const response = await fetch(
3031
lighthouseConfig.lighthouseAPI +
31-
`/api/user/files_uploaded?lastKey=${lastKey}`,
32+
`/api/user/files_uploaded?lastKey=${lastKey}&fileType=${fileType}`,
3233
{
3334
headers: {
3435
Authorization: `Bearer ${authToken}`,

src/Lighthouse/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import getUploads from './getUploads'
66
import getFileInfo from './getFileInfo'
77
import createWallet from './createWallet'
88
import deleteFile from './deleteFile'
9-
9+
import walrusBlobs from './walrusBlobs'
10+
import deleteFileWalrus from './deleteFileWalrus'
1011
import shareFile from './encryption/shareFile'
1112
import getAuthMessage from './encryption/getAuthMessage'
1213
import revokeFileAccess from './encryption/revokeFileAccess'
@@ -53,6 +54,8 @@ export {
5354
getAllKeys,
5455
removeKey,
5556
deleteFile,
57+
walrusBlobs,
58+
deleteFileWalrus,
5659
}
5760

5861
export default {
@@ -81,4 +84,6 @@ export default {
8184
getAllKeys,
8285
removeKey,
8386
deleteFile,
87+
walrusBlobs,
88+
deleteFileWalrus,
8489
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { lighthouseConfig } from '../../lighthouse.config'
2+
3+
export type walrusBlobsResponse = {
4+
blobIds: string[]
5+
}
6+
7+
export default async (cid: string): Promise<walrusBlobsResponse> => {
8+
try {
9+
const response = await fetch(
10+
`${lighthouseConfig.lighthouseAPI}/api/lighthouse/walrus_blobs?cid=${cid}`
11+
)
12+
if (!response.ok) {
13+
throw new Error(`Request failed with status code ${response.status}`)
14+
}
15+
const walrusBlobs: walrusBlobsResponse = (await response.json()) as walrusBlobsResponse
16+
17+
return { blobIds: walrusBlobs.blobIds }
18+
} catch (error: any) {
19+
throw new Error(error.message)
20+
}
21+
}

0 commit comments

Comments
 (0)