Skip to content

Commit 9fd9ae8

Browse files
committed
cid version
1 parent fb2e5ed commit 9fd9ae8

File tree

12 files changed

+38
-43
lines changed

12 files changed

+38
-43
lines changed

src/Lighthouse/upload/buffer/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { lighthouseConfig } from '../../../lighthouse.config'
22

3-
export default async (blob: any, apiKey: string, mimeType = '') => {
3+
export default async (blob: any, apiKey: string, cidVersion: number) => {
44
try {
55
const token = 'Bearer ' + apiKey
6-
const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add'
6+
const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}`
77

88
// Upload file
99
const formData = new FormData()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import uploadBuffer from './node'
22
import uploadTypedArray from './browser'
33

4-
export default async (buffer: any, apiKey: string) => {
4+
export default async (buffer: any, apiKey: string, cidVersion: number = 1) => {
55
// Upload File to IPFS
66
//@ts-ignore
77
if (typeof window === 'undefined') {
8-
return await uploadBuffer(buffer, apiKey)
8+
return await uploadBuffer(buffer, apiKey, cidVersion)
99
} else {
10-
return await uploadTypedArray(buffer, apiKey)
10+
return await uploadTypedArray(buffer, apiKey, cidVersion)
1111
}
1212
}

src/Lighthouse/upload/buffer/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { lighthouseConfig } from '../../../lighthouse.config'
22

3-
export default async (buffer: any, apiKey: string, mimeType = '') => {
3+
export default async (buffer: any, apiKey: string, cidVersion: number) => {
44
try {
55
const token = 'Bearer ' + apiKey
6-
const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add'
6+
const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}`
77

88
// Upload file
99
const blob = new Blob([buffer])

src/Lighthouse/upload/files/browser.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
import { lighthouseConfig } from '../../../lighthouse.config'
33
import {
44
IUploadProgressCallback,
5-
UploadFileReturnType
5+
IFileUploadedResponse
66
} from '../../../types'
77
import { fetchWithTimeout } from '../../utils/util'
88

99
// eslint-disable-next-line @typescript-eslint/no-empty-function
10-
export default async <T extends boolean>(
10+
export default async (
1111
files: any,
1212
accessToken: string,
13+
cidVersion: number,
1314
uploadProgressCallback?: (data: IUploadProgressCallback) => void
14-
): Promise<{ data: UploadFileReturnType<T> }> => {
15+
): Promise<{ data: IFileUploadedResponse }> => {
1516
try {
1617
const isDirectory = [...files].some(file => file.webkitRelativePath)
17-
let endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false`
18+
let endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}`
1819

1920
if(!isDirectory && files.length > 1) {
20-
endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=true`
21+
endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=true&cid-version=${cidVersion}`
2122
}
2223

2324
const formData = new FormData()

src/Lighthouse/upload/files/index.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@ import {
55
IFileUploadedResponse
66
} from '../../../types'
77

8-
async function uploadFiles(
9-
sourcePath: string | any,
10-
apiKey: string,
11-
uploadProgressCallback?: (data: IUploadProgressCallback) => void
12-
): Promise<{ data: IFileUploadedResponse }>
13-
14-
async function uploadFiles(
15-
sourcePath: string | any,
16-
apiKey: string,
17-
uploadProgressCallback?: (data: IUploadProgressCallback) => void
18-
): Promise<{ data: IFileUploadedResponse[] }>
19-
208
async function uploadFiles(
219
path: string | any,
2210
apiKey: string,
11+
cidVersion: number = 1,
2312
uploadProgressCallback?: (data: IUploadProgressCallback) => void
24-
) {
13+
): Promise<{ data: IFileUploadedResponse }> {
2514
// Upload File to IPFS
2615
//@ts-ignore
2716
if (typeof window === 'undefined') {
28-
return await uploadFile(path, apiKey)
17+
return await uploadFile(path, apiKey, cidVersion)
2918
} else {
3019
return await uploadFileBrowser(
3120
path,
3221
apiKey,
22+
cidVersion,
3323
uploadProgressCallback
3424
)
3525
}

src/Lighthouse/upload/files/node.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import basePathConvert from '../../utils/basePathConvert'
22
import { lighthouseConfig } from '../../../lighthouse.config'
3-
import { UploadFileReturnType } from '../../../types'
43
import { fetchWithTimeout } from '../../utils/util'
5-
4+
import { IFileUploadedResponse } from '../../../types'
65
export async function walk(dir: string) {
76
const { readdir, stat } = eval(`require`)('fs-extra')
87
let results: string[] = []
@@ -22,10 +21,11 @@ export async function walk(dir: string) {
2221
return results
2322
}
2423

25-
export default async <T extends boolean>(
24+
export default async (
2625
sourcePath: string,
27-
apiKey: string
28-
): Promise<{ data: UploadFileReturnType<T> }> => {
26+
apiKey: string,
27+
cidVersion: number
28+
): Promise<{ data: IFileUploadedResponse }> => {
2929
const { createReadStream, lstatSync } = eval(`require`)('fs-extra')
3030
const path = eval(`require`)('path')
3131

@@ -34,7 +34,7 @@ export default async <T extends boolean>(
3434
try {
3535
const endpoint =
3636
lighthouseConfig.lighthouseNode +
37-
`/api/v0/add?wrap-with-directory=false`
37+
`/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}`
3838
if (stats.isFile()) {
3939
const data = new FormData()
4040
const stream = createReadStream(sourcePath)

src/Lighthouse/upload/text/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { lighthouseConfig } from '../../../lighthouse.config'
22
import { fetchWithTimeout } from '../../utils/util'
33

4-
export default async (text: string, apiKey: string, name: string) => {
4+
export default async (text: string, apiKey: string, name: string, cidVersion: number) => {
55
try {
66
const token = 'Bearer ' + apiKey
7-
const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add'
7+
const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}`
88

99
// Upload file
1010
const formData = new FormData()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import uploadTextServer from './node'
22
import uploadTextBrowser from './browser'
33

4-
export default async (text: string, apiKey: string, name = 'text') => {
4+
export default async (text: string, apiKey: string, name = 'text', cidVersion: number = 1) => {
55
// Upload File to IPFS
66
//@ts-ignore
77
if (typeof window === 'undefined') {
8-
return await uploadTextServer(text, apiKey, name)
8+
return await uploadTextServer(text, apiKey, name, cidVersion)
99
} else {
10-
return await uploadTextBrowser(text, apiKey, name)
10+
return await uploadTextBrowser(text, apiKey, name, cidVersion)
1111
}
1212
}

src/Lighthouse/upload/text/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { lighthouseConfig } from '../../../lighthouse.config'
22
import { fetchWithTimeout } from '../../utils/util'
33

4-
export default async (text: string, apiKey: string, name: string) => {
4+
export default async (text: string, apiKey: string, name: string, cidVersion: number) => {
55
try {
66
const token = 'Bearer ' + apiKey
7-
const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add'
7+
const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}`
88

99
// Upload file
1010
const formData = new FormData()

src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default async (
2929
apiKey: string,
3030
publicKey: string,
3131
auth_token: string,
32+
cidVersion: number,
3233
uploadProgressCallback?: (data: IUploadProgressCallback) => void
3334
): Promise<{ data: IFileUploadedResponse[] }> => {
3435
try {
@@ -38,7 +39,7 @@ export default async (
3839
mimeType = files[0].type
3940
}
4041
const endpoint =
41-
lighthouseConfig.lighthouseNode + '/api/v0/add?wrap-with-directory=false'
42+
lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}`
4243
const token = 'Bearer ' + apiKey
4344

4445
const fileArr = []

0 commit comments

Comments
 (0)