Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
afa0c344
提交
afa0c344
authored
5月 06, 2017
作者:
Jeromy Johnson
提交者:
GitHub
5月 06, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3897 from ipfs/feat/faster-listing
improved gateway directory listing for sharded nodes
上级
d59554a7
5bb480b4
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
16 行删除
+28
-16
gateway_handler.go
core/corehttp/gateway_handler.go
+28
-16
没有找到文件。
core/corehttp/gateway_handler.go
浏览文件 @
afa0c344
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"os"
gopath
"path"
"runtime/debug"
"strings"
...
...
@@ -20,6 +21,7 @@ import (
dagutils
"github.com/ipfs/go-ipfs/merkledag/utils"
path
"github.com/ipfs/go-ipfs/path"
ft
"github.com/ipfs/go-ipfs/unixfs"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
humanize
"gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
cid
"gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
...
...
@@ -227,20 +229,22 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return
}
links
,
err
:=
i
.
api
.
Unixfs
()
.
Ls
(
ctx
,
resolvedPath
)
nd
,
err
:=
i
.
api
.
ResolveNode
(
ctx
,
resolvedPath
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
// storage for directory listing
var
dirListing
[]
directoryItem
// loop through files
foundIndex
:=
false
for
_
,
link
:=
range
links
{
if
link
.
Name
==
"index.html"
{
dirr
,
err
:=
uio
.
NewDirectoryFromNode
(
i
.
node
.
DAG
,
nd
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
ixnd
,
err
:=
dirr
.
Find
(
ctx
,
"index.html"
)
switch
{
case
err
==
nil
:
log
.
Debugf
(
"found index.html link for %s"
,
urlPath
)
foundIndex
=
true
if
urlPath
[
len
(
urlPath
)
-
1
]
!=
'/'
{
// See comment above where originalUrlPath is declared.
...
...
@@ -249,7 +253,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return
}
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Cat
(
ctx
,
coreapi
.
ParseCid
(
link
.
Cid
))
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Cat
(
ctx
,
coreapi
.
ParseCid
(
ixnd
.
Cid
()
))
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
@@ -258,16 +262,26 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
// write to request
http
.
ServeContent
(
w
,
r
,
"index.html"
,
modtime
,
dr
)
break
return
default
:
internalWebError
(
w
,
err
)
return
case
os
.
IsNotExist
(
err
)
:
}
if
r
.
Method
==
"HEAD"
{
return
}
// storage for directory listing
var
dirListing
[]
directoryItem
dirr
.
ForEachLink
(
ctx
,
func
(
link
*
node
.
Link
)
error
{
// See comment above where originalUrlPath is declared.
di
:=
directoryItem
{
humanize
.
Bytes
(
link
.
Size
),
link
.
Name
,
gopath
.
Join
(
originalUrlPath
,
link
.
Name
)}
dirListing
=
append
(
dirListing
,
di
)
}
return
nil
})
if
!
foundIndex
{
if
r
.
Method
!=
"HEAD"
{
// construct the correct back link
// https://github.com/ipfs/go-ipfs/issues/1365
var
backLink
string
=
prefix
+
urlPath
...
...
@@ -306,13 +320,11 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
Path
:
originalUrlPath
,
BackLink
:
backLink
,
}
err
:
=
listingTemplate
.
Execute
(
w
,
tplData
)
err
=
listingTemplate
.
Execute
(
w
,
tplData
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
}
}
}
func
(
i
*
gatewayHandler
)
postHandler
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论