Skip to content
This repository was archived by the owner on Aug 31, 2024. It is now read-only.

Commit e0bf830

Browse files
authored
Merge pull request #4 from pexavc/staging
Refactor using Combing and async/await
2 parents 42fff9d + 5c4e418 commit e0bf830

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+964
-535
lines changed

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.7
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -22,6 +22,8 @@ let package = Package(
2222
.target(
2323
name: "IPFSKit",
2424
dependencies: []),
25+
.executableTarget(name: "IPFSExecutable",
26+
dependencies: ["IPFSKit"]),
2527
.testTarget(
2628
name: "IPFSKitTests",
2729
dependencies: ["IPFSKit"]),

README.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# IPFSKit
22

3-
![Travis CI Build](https://app.travis-ci.com/0xKala/IPFSKit.svg?branch=main)
4-
[![Swift 5.3](https://img.shields.io/badge/swift-5.5-brightgreen.svg)](https://github.com/apple/swift)
5-
[![xcode-version](https://img.shields.io/badge/xcode-12.5-brightgreen)](https://developer.apple.com/xcode/)
3+
[![Swift 5.7](https://img.shields.io/badge/swift-5.7-brightgreen.svg)](https://github.com/apple/swift)
4+
[![xcode-version](https://img.shields.io/badge/xcode-14.2-brightgreen)](https://developer.apple.com/xcode/)
65

76
Based on: https://github.com/ipfs-shipyard/swift-ipfs-http-client
87
Converted into a standalone Swift Package.
@@ -20,46 +19,43 @@ Add this repo link as a swift package to your XCode project.
2019
```swift
2120
import IPFSKit
2221

23-
let client: IPFSClient?
22+
struct InfuraGateway: IPFSGateway {
23+
var host: IPFSHost {
24+
InfuraHost(id: "...",//On Infura, this is simply the API_KEY
25+
secret: "...")//API_KEY_SECRET
26+
}
2427

25-
public init() {
26-
client = try? IPFSClient.init(
27-
host: "ipfs.infura.io",
28-
port: 5001,
29-
ssl: true,
30-
id: "INFURA-PROJECT-ID",
31-
secret: "INFURA-SECRET"
32-
)
28+
var gateway: String {
29+
"https://neatia.infura-ipfs.io"
30+
}
3331
}
32+
33+
IPFSKit.gateway = InfuraGateway()
3434
```
3535

3636
### Adding data to IPFS
3737

3838
```swift
39-
if let data = result.data.pngData() {
40-
do {
41-
try state.service.client?.add(data) { nodes in // Adding data to IPFS
42-
// use 'nodes' to pin content
43-
}
44-
} catch let error {
45-
GraniteLogger.info("error adding new image:\n\(error)", .expedition, focus: true)
46-
}
47-
}
39+
40+
let data: Data = "Hello World".data(using: .utf8)!
41+
42+
let response = await IPFS.upload(data)
43+
44+
print(IPFSKit.gateway?.url(for: response))
4845

4946
```
5047

5148
Convert any type of object into a `Data` type to prepare for adding.
5249

5350
### Pinning data to IPFS
5451

52+
> Infura seems to have updated their services to automatically pin data that is added via the `/add` endpoint. This step is uncessary depending on the provider used or edge cases involved.
53+
5554
```swift
56-
do {
57-
if let addHash = nodes.first?.hash { // the `nodes` from the closure of the previous code example
58-
try client?.pin.add(addHash) { pinHash in
59-
let gatewayHash = b58String(pinHash) // IPFS public hash gateway for the pinned content
60-
}
61-
}
62-
} catch let error {
63-
GraniteLogger.info("error pinning:\n\(error)", .expedition, focus: true)
64-
}
55+
56+
let data: Data = "Hello World".data(using: .utf8)!
57+
58+
let response = await IPFS.upload(data)
59+
60+
let gatewayHash = await IPFS.pin(response)
6561
```

Sources/IPFSExecutable/main.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// main.swift
3+
//
4+
//
5+
// Created by PEXAVC on 7/11/23.
6+
//
7+
8+
import Foundation
9+
import IPFSKit
10+
11+
struct InfuraGateway: IPFSGateway {
12+
var host: IPFSHost {
13+
InfuraHost(id: "...",//On Infura, this is simply the API_KEY
14+
secret: "...")//API_KEY_SECRET
15+
}
16+
17+
var gateway: String {
18+
"https://neatia.infura-ipfs.io"
19+
}
20+
}
21+
22+
IPFSKit.gateway = InfuraGateway()
23+
24+
let data: Data = "Hello World".data(using: .utf8)!
25+
26+
let response = await IPFS.upload(data)
27+
28+
print(IPFSKit.gateway?.url(for: response))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)