Skip to content

Commit

Permalink
ipfs util dependencies update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorizen committed Aug 15, 2023
1 parent 1b25eb5 commit 5c15e76
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 214 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.0-rc.19] - 2023-08-15
### Changed
- `@tokene/toolkit` - `IpfsUtil` class now is using `kubo-rpc-client`

## [0.0.0-rc.18] - 2023-08-10
### Fixed
- `@tokene/toolkit` - `abbrCenter` function
Expand Down Expand Up @@ -164,7 +168,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial release
- `root` - `@tokene/toolkit` package

[Unreleased]: https://github.com/dl-tokene/webkit/compare/0.0.0-rc.18...HEAD
[Unreleased]: https://github.com/dl-tokene/webkit/compare/0.0.0-rc.19...HEAD
[0.0.0-rc.19]: https://github.com/dl-tokene/webkit/compare/0.0.0-rc.18...0.0.0-rc.19
[0.0.0-rc.18]: https://github.com/dl-tokene/webkit/compare/0.0.0-rc.17...0.0.0-rc.18
[0.0.0-rc.17]: https://github.com/dl-tokene/webkit/compare/0.0.0-rc.16...0.0.0-rc.17
[0.0.0-rc.16]: https://github.com/dl-tokene/webkit/compare/0.0.0-rc.15...0.0.0-rc.16
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokene/sdk",
"version": "0.0.0-rc.18",
"version": "0.0.0-rc.19",
"description": "Collection of common interactions with TokenE graph and core contracts",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/styles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokene/styles",
"version": "0.0.0-rc.18",
"version": "0.0.0-rc.19",
"description": "Default styles for every single frontend module of TokenE",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/toasts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokene/toasts",
"version": "0.0.0-rc.18",
"version": "0.0.0-rc.19",
"description": "Vue based toasts",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ If you're using `helpers`, `errors`, `enums` only, you can skip this step.
import { IpfsUtil } from '@tokene/toolkit'

const ipfsEntity = new IpfsUtil<{ someData: string }>({
rawData: JSON.stringify({
rawData: {
someData: 'lorem ipsum dolor sit amet concestetur!',
}),
},
})

await ipfsEntity.uploadSelf()
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokene/toolkit",
"version": "0.0.0-rc.18",
"version": "0.0.0-rc.19",
"description": "Collection of common utility functions and classes in tokenE frontend modules",
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,7 +54,7 @@
"@vueuse/integrations": "^10.1.2",
"axios": "^1.3.6",
"i18next": "^22.4.15",
"ipfs-http-client": "^60.0.0",
"kubo-rpc-client": "^3.0.1",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"universal-cookie": "^4.0.4",
Expand Down
45 changes: 24 additions & 21 deletions packages/toolkit/src/utils/ipfs.util.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import axios from 'axios'
import type { ImportCandidate } from 'ipfs-core-types/src/utils'
import { create, type IPFSHTTPClient } from 'ipfs-http-client'
import { create, type IPFSHTTPClient } from 'kubo-rpc-client'

import { toolkitConfig } from '@/globals'

const PREFIX = 'ipfs://'

export class IpfsUtil<T> {
private _rawData?: T
private _path?: string
private _paths = [] as string[]
private _cid?: string
private _cids = [] as string[]
private _ipfsApi: IPFSHTTPClient

constructor(options: { rawData?: T; path?: string }) {
const { rawData, path } = options
constructor(options: { rawData?: T; cid?: string }) {
const { rawData, cid } = options

this._rawData = rawData
this._path = path
this._cid = cid
this._ipfsApi = create({
url: `${toolkitConfig.API_IPFS_URL}/api/api/v0`,
})
Expand All @@ -26,40 +25,44 @@ export class IpfsUtil<T> {
if (!this._rawData) throw new Error('No data provided to upload')

if (Array.isArray(this._rawData)) {
for await (const { path } of this._ipfsApi.addAll(
this._rawData as ImportCandidate[],
)) {
this._paths.push(path)
const dataArrayToAdd = this._rawData.map(item => ({
content: JSON.stringify(item),
}))
for await (const { path } of this._ipfsApi.addAll(dataArrayToAdd)) {
this._cids.push(path)
}
} else {
const { path } = await this._ipfsApi.add(this._rawData as ImportCandidate)
this._path = path
return
}

const { path } = await this._ipfsApi.add({
content: JSON.stringify(this._rawData),
})
this._cid = path
}

async loadSelf(): Promise<T> {
if (!this._path) throw new Error('No path provided to load')
if (!this._cid) throw new Error('No path provided to load')

const { data } = await axios.get(this.publicUrl)

return data as T
}

get publicUrl() {
return this._path
? `${toolkitConfig.API_IPFS_URL}/ipfs/ipfs/${this._path.replace(
return this._cid
? `${toolkitConfig.API_IPFS_URL}/ipfs/ipfs/${this._cid.replace(
PREFIX,
'',
)}`
: ''
}

get path() {
return `${PREFIX}${this._path}`
get cid() {
return `${PREFIX}${this._cid}`
}

get paths() {
return this._paths.map(el => `${PREFIX}${el}`)
get cids() {
return this._cids.map(el => `${PREFIX}${el}`)
}

get ipfsApi() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokene/ui-kit",
"version": "0.0.0-rc.18",
"version": "0.0.0-rc.19",
"description": "Collection of common TokenE vue components",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-web3-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokene/vue-web3-provider",
"version": "0.0.0-rc.18",
"version": "0.0.0-rc.19",
"description": "The Vue reactive wrapper for @distributedlab/w3p",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 5c15e76

Please sign in to comment.