Skip to content

Commit

Permalink
allow all gateway request & try fix interface contract call (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackstorm authored Dec 21, 2021
1 parent 814a8f6 commit cfdbbb0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
9 changes: 9 additions & 0 deletions gateway/ipfs_gateway_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

const (
DEFAULT = CLOUDFLARE
CLOUDFLARE = "https://cloudflare-ipfs.com/ipfs/"
IPFS_IO = "https://ipfs.io/ipfs/"
DWEB_LINK = "https://dweb.link/ipfs/"
INFURA_IO = "https://ipfs.infura.io/ipfs/"
)
28 changes: 27 additions & 1 deletion gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,40 @@ func handle(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
return
}

w.Header().Add("Location", "https://cloudflare-ipfs.com/ipfs/"+avatar)
gatewayParam := r.URL.Query().Get("gateway")
gateway := DEFAULT
switch gatewayParam {
case "cloudflare":
gateway = CLOUDFLARE
case "ipfs":
gateway = IPFS_IO
case "dweb":
gateway = DWEB_LINK
case "infura":
gateway = INFURA_IO
default:
gateway = DEFAULT
}

accessControlHeaders(w)
w.Header().Add("Location", gateway+avatar)
w.WriteHeader(302)
}

func main() {
r := httprouter.New()
r.GlobalOPTIONS = http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
accessControlHeaders(w)
})
r.GET("/v1/:address", handle)
r.GET("/v1/:address/:name", handle)

log.Fatalln(http.ListenAndServe(":8080", r))
}

func accessControlHeaders(w http.ResponseWriter) {
header := w.Header()
header.Set("Access-Control-Allow-Methods", "GET")
header.Set("Access-Control-Allow-Origin", "*")
header.Set("Access-Control-Allow-Headers", "*")
}
15 changes: 7 additions & 8 deletions interface/src/pages/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styled from "styled-components";
import { useWeb3React } from "@web3-react/core";
import ABI from "../abi/Web3Avatar.abi.json";
import Contract from "web3-eth-contract";
import web3 from "web3";

const ImageContainer = styled.div`
width: 250px;
Expand Down Expand Up @@ -58,12 +59,12 @@ const App = () => {
// contract address
"0xEBFFe5EEe4a3a195cC726B0Aa3D7988Ed480679a"
);
// console.log(added)
const res = await contract.methods
contract.methods
.setAvatar("default", added.data.Hash)
.send({ from: account });
// TODO handle res
console.log(res);
.send({ from: account })
.then((res) => {
console.log(res);
});
} finally {
setIsUploading(false);
}
Expand Down Expand Up @@ -107,9 +108,7 @@ const App = () => {
</div>

<div className="my-4 text-gray-400 text-center">
<p>
Your avatar will be upload to IPFS.
</p>
<p>Your avatar will be upload to IPFS.</p>
</div>
</>
);
Expand Down

1 comment on commit cfdbbb0

@vercel
Copy link

@vercel vercel bot commented on cfdbbb0 Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.