Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit e3ae21c

Browse files
authored
Merge pull request #16 from mayocream/feat_ipfs_path
feat: IPFS path compatibility
2 parents 2fb4d97 + b7d675d commit e3ae21c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

server/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,26 @@ func gracefulShutdown(ctx context.Context, app *fiber.App) {
9292
}
9393

9494
func (s *Server) registerRoutes(app *fiber.App) {
95-
v0 := app.Group("/api/v0")
95+
// API Usage
96+
v0 := app.Group("/api/v0")
9697
v0.Post("/upload", s.handleUpload)
9798
v0.Get("/gallery", s.handleGallery)
9899
v0.Get("/:cid/:file", s.handleCat)
100+
101+
// Terminal Upload
99102
v0.Post("/", s.handlePut)
100103
v0.Put("/:name", s.handlePut)
101104

105+
// Root shorter upload url.
102106
// app.Post("/", s.handlePut)
103107
// app.Put("/:name", s.handlePut)
104108

105109
app.Get("/:cid/raw/:file", s.handleCat)
106110

111+
// IPFS paths
112+
app.Get("/ipfs/:cid/:file", s.handleCat)
113+
114+
// Static files or frontend
107115
app.Static("/", "./dist")
108116
app.Get("/*", func(c *fiber.Ctx) error {
109117
return c.SendFile("./dist/index.html")

src/pages/View.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ interface ViewProps {
1919
}
2020

2121
async function getMetadata(cid: string): Promise<CidResource> {
22-
return await fetch(import.meta.env.VITE_API_URL + `/api/v0/${cid}/__metadata.json`).then((res) => {
22+
return await fetch(import.meta.env.VITE_API_URL + `/ipfs/${cid}/__metadata.json`).then((res) => {
2323
console.log(res.json)
2424
return res.json() as Promise<CidResource>
2525
})
2626
}
2727

2828
async function getFile(cid: string, filename: string): Promise<string> {
29-
return await fetch(import.meta.env.VITE_API_URL + `/api/v0/${cid}/${filename}`).then((res) => {
29+
return await fetch(import.meta.env.VITE_API_URL + `/ipfs/${cid}/${filename}`).then((res) => {
3030
console.log(res.text)
3131
return res.text()
3232
})
@@ -126,7 +126,7 @@ function View(props: RouteComponentProps<ViewProps>) {
126126
href={
127127
revealText !== ''
128128
? `data:text/plain;base64,${btoa(unescape(encodeURIComponent(revealText)))}`
129-
: import.meta.env.VITE_API_URL + `/api/v0/${cid}/${metadata?.objects[0].name}`
129+
: import.meta.env.VITE_API_URL + `/ipfs/${cid}/${metadata?.objects[0].name}`
130130
}
131131
>
132132
Raw

0 commit comments

Comments
 (0)