mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 08:47:42 +08:00
Move dir-index-html + assets to a separate repo
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
@ -28,6 +28,11 @@ func SeedInitDocs(nd *core.IpfsNode) (*key.Key, error) {
|
|||||||
return addAssetList(nd, initDocPaths)
|
return addAssetList(nd, initDocPaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var initDirIndex = []string{
|
||||||
|
"../vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/knownIcons.txt",
|
||||||
|
"../vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/dir-index.html",
|
||||||
|
}
|
||||||
|
|
||||||
var initGwAssets = []string{
|
var initGwAssets = []string{
|
||||||
"gw-assets/icons.css",
|
"gw-assets/icons.css",
|
||||||
"gw-assets/bootstrap.min.css",
|
"gw-assets/bootstrap.min.css",
|
||||||
@ -70,7 +75,7 @@ func addAssetList(nd *core.IpfsNode, l []string) (*key.Key, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := nd.Pinning.Flush(); err != nil {
|
if err := nd.Pinning.Flush(); err != nil {
|
||||||
return nil, fmt.Errorf("assets: Pinnig flush failed: %s", err)
|
return nil, fmt.Errorf("assets: Pinning flush failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &dkey, nil
|
return &dkey, nil
|
||||||
|
@ -9,69 +9,53 @@ import (
|
|||||||
|
|
||||||
// TestEmbeddedDocs makes sure we don't forget to regenerate after documentation change
|
// TestEmbeddedDocs makes sure we don't forget to regenerate after documentation change
|
||||||
func TestEmbeddedDocs(t *testing.T) {
|
func TestEmbeddedDocs(t *testing.T) {
|
||||||
const wantCnt = 6
|
testNFiles(initDocPaths, 6, t, "documents")
|
||||||
if len(initDocPaths) < wantCnt {
|
}
|
||||||
t.Fatalf("expected %d documents got %d", wantCnt, len(initDocPaths))
|
|
||||||
|
func TestGatewayAssets(t *testing.T) {
|
||||||
|
testNFiles(initGwAssets, 2, t, "assets")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDirIndex(t *testing.T) {
|
||||||
|
testNFiles(initDirIndex, 2, t, "assets")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testNFiles(fs []string, wantCnt int, t *testing.T, ftype string) {
|
||||||
|
if len(fs) < wantCnt {
|
||||||
|
t.Fatalf("expected %d %s. got %d", wantCnt, ftype, len(fs))
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, f := range initDocPaths {
|
for _, f := range fs {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
// compare asset
|
// compare asset
|
||||||
go func(f string) {
|
go func(f string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
// load data from filesystem (git)
|
testOneFile(f, t)
|
||||||
vcsData, err := ioutil.ReadFile(f)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("asset %s: could not read vcs file: %s", f, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// load data from emdedded source
|
|
||||||
embdData, err := Asset(f)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("asset %s: could not read vcs file: %s", f, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !bytes.Equal(vcsData, embdData) {
|
|
||||||
t.Errorf("asset %s: vcs and embedded data isnt equal", f)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Logf("checked %s", f)
|
|
||||||
}(f)
|
}(f)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatewayAssets(t *testing.T) {
|
func testOneFile(f string, t *testing.T) {
|
||||||
const wantCnt = 2
|
// load data from filesystem (git)
|
||||||
if len(initGwAssets) < wantCnt {
|
vcsData, err := ioutil.ReadFile(f)
|
||||||
t.Fatalf("expected %d assets. got %d", wantCnt, len(initDocPaths))
|
if err != nil {
|
||||||
|
t.Errorf("asset %s: could not read vcs file: %s", f, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range initGwAssets {
|
// load data from emdedded source
|
||||||
// load data from filesystem (git)
|
embdData, err := Asset(f)
|
||||||
vcsData, err := ioutil.ReadFile(f)
|
if err != nil {
|
||||||
if err != nil {
|
t.Errorf("asset %s: could not read vcs file: %s", f, err)
|
||||||
t.Errorf("asset %s: could not read vcs file: %s", f, err)
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// load data from emdedded source
|
|
||||||
embdData, err := Asset(f)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("asset %s: could not read vcs file: %s", f, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !bytes.Equal(vcsData, embdData) {
|
|
||||||
t.Errorf("asset %s: vcs and embedded data isnt equal", f)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Logf("checked %s", f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(vcsData, embdData) {
|
||||||
|
t.Errorf("asset %s: vcs and embedded data isnt equal", f)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("checked %s", f)
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
1
assets/gw-assets
Symbolic link
1
assets/gw-assets
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/gw-assets
|
@ -1,8 +1,10 @@
|
|||||||
package corehttp
|
package corehttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ipfs/go-ipfs/assets"
|
||||||
"html/template"
|
"html/template"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// structs for directory listing
|
// structs for directory listing
|
||||||
@ -18,143 +20,37 @@ type directoryItem struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directory listing template
|
var listingTemplate *template.Template
|
||||||
var listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{"iconFromExt": iconFromExt}).Parse(`
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<!-- TODO: seed these - maybe like the starter ex or the webui? -->
|
|
||||||
<link rel="stylesheet" href="/ipfs/QmXB7PLRWH6bCiwrGh2MrBBjNkLv3mY3JdYXCikYZSwLED/bootstrap.min.css"/>
|
|
||||||
<!-- helper to construct this is here: https://github.com/cryptix/exp/blob/master/imgesToCSSData/convert.go -->
|
|
||||||
<link rel="stylesheet" href="/ipfs/QmXB7PLRWH6bCiwrGh2MrBBjNkLv3mY3JdYXCikYZSwLED/icons.css">
|
|
||||||
<style>
|
|
||||||
.narrow {width: 0px;}
|
|
||||||
.padding { margin: 100px;}
|
|
||||||
#header {
|
|
||||||
background: #000;
|
|
||||||
}
|
|
||||||
#logo {
|
|
||||||
height: 25px;
|
|
||||||
margin: 10px;
|
|
||||||
}
|
|
||||||
.ipfs-icon {
|
|
||||||
width:16px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<title>{{ .Path }}</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="header" class="row">
|
|
||||||
<div class="col-xs-2">
|
|
||||||
<div id="logo" class="ipfs-logo"> </div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>
|
|
||||||
<div class="col-xs-12">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<strong>Index of {{ .Path }}</strong>
|
|
||||||
</div>
|
|
||||||
<table class="table table-striped">
|
|
||||||
<tr>
|
|
||||||
<td class="narrow">
|
|
||||||
<div class="ipfs-icon ipfs-_blank"> </div>
|
|
||||||
</td>
|
|
||||||
<td class="padding">
|
|
||||||
<a href="{{.BackLink}}">..</a>
|
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
|
||||||
{{ range .Listing }}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<div class="ipfs-icon {{iconFromExt .Name}}"> </div>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="{{ .Path }}">{{ .Name }}</a>
|
|
||||||
</td>
|
|
||||||
<td>{{ .Size }} bytes</td>
|
|
||||||
</tr>
|
|
||||||
{{ end }}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`))
|
|
||||||
|
|
||||||
// helper to guess the type/icon for it by the extension name
|
func init() {
|
||||||
func iconFromExt(name string) string {
|
assetPath := "../vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/"
|
||||||
ext := path.Ext(name)
|
knownIconsBytes, err := assets.Asset(assetPath + "knownIcons.txt")
|
||||||
_, ok := knownIcons[ext]
|
if err != nil {
|
||||||
if !ok {
|
panic(err)
|
||||||
// default blank icon
|
}
|
||||||
return "ipfs-_blank"
|
knownIcons := make(map[string]struct{})
|
||||||
|
for _, ext := range strings.Split(strings.TrimSuffix(string(knownIconsBytes), "\n"), "\n") {
|
||||||
|
knownIcons[ext] = struct{}{}
|
||||||
}
|
}
|
||||||
return "ipfs-" + ext[1:] // slice of the first dot
|
|
||||||
}
|
|
||||||
|
|
||||||
var knownIcons = map[string]bool{
|
// helper to guess the type/icon for it by the extension name
|
||||||
".aac": true,
|
iconFromExt := func(name string) string {
|
||||||
".aiff": true,
|
ext := path.Ext(name)
|
||||||
".ai": true,
|
_, ok := knownIcons[ext]
|
||||||
".avi": true,
|
if !ok {
|
||||||
".bmp": true,
|
// default blank icon
|
||||||
".c": true,
|
return "ipfs-_blank"
|
||||||
".cpp": true,
|
}
|
||||||
".css": true,
|
return "ipfs-" + ext[1:] // slice of the first dot
|
||||||
".dat": true,
|
}
|
||||||
".dmg": true,
|
|
||||||
".doc": true,
|
// Directory listing template
|
||||||
".dotx": true,
|
dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html")
|
||||||
".dwg": true,
|
if err != nil {
|
||||||
".dxf": true,
|
panic(err)
|
||||||
".eps": true,
|
}
|
||||||
".exe": true,
|
|
||||||
".flv": true,
|
listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{
|
||||||
".gif": true,
|
"iconFromExt": iconFromExt,
|
||||||
".h": true,
|
}).Parse(string(dirIndexBytes)))
|
||||||
".hpp": true,
|
|
||||||
".html": true,
|
|
||||||
".ics": true,
|
|
||||||
".iso": true,
|
|
||||||
".java": true,
|
|
||||||
".jpg": true,
|
|
||||||
".js": true,
|
|
||||||
".key": true,
|
|
||||||
".less": true,
|
|
||||||
".mid": true,
|
|
||||||
".mp3": true,
|
|
||||||
".mp4": true,
|
|
||||||
".mpg": true,
|
|
||||||
".odf": true,
|
|
||||||
".ods": true,
|
|
||||||
".odt": true,
|
|
||||||
".otp": true,
|
|
||||||
".ots": true,
|
|
||||||
".ott": true,
|
|
||||||
".pdf": true,
|
|
||||||
".php": true,
|
|
||||||
".png": true,
|
|
||||||
".ppt": true,
|
|
||||||
".psd": true,
|
|
||||||
".py": true,
|
|
||||||
".qt": true,
|
|
||||||
".rar": true,
|
|
||||||
".rb": true,
|
|
||||||
".rtf": true,
|
|
||||||
".sass": true,
|
|
||||||
".scss": true,
|
|
||||||
".sql": true,
|
|
||||||
".tga": true,
|
|
||||||
".tgz": true,
|
|
||||||
".tiff": true,
|
|
||||||
".txt": true,
|
|
||||||
".wav": true,
|
|
||||||
".xls": true,
|
|
||||||
".xlsx": true,
|
|
||||||
".xml": true,
|
|
||||||
".yml": true,
|
|
||||||
".zip": true,
|
|
||||||
}
|
}
|
||||||
|
10
package.json
Normal file
10
package.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "go-ipfs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": [
|
||||||
|
{
|
||||||
|
"name": "dir-index-html",
|
||||||
|
"hash": "QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -16,8 +16,8 @@ var log = logrus.New()
|
|||||||
// TODO: write custom TextFormatter (don't print module=name explicitly) and
|
// TODO: write custom TextFormatter (don't print module=name explicitly) and
|
||||||
// fork logrus to add shortfile
|
// fork logrus to add shortfile
|
||||||
var LogFormats = map[string]*logrus.TextFormatter{
|
var LogFormats = map[string]*logrus.TextFormatter{
|
||||||
"nocolor": &logrus.TextFormatter{DisableColors: true, FullTimestamp: true, TimestampFormat: "2006-01-02 15:04:05.000000", DisableSorting: true},
|
"nocolor": {DisableColors: true, FullTimestamp: true, TimestampFormat: "2006-01-02 15:04:05.000000", DisableSorting: true},
|
||||||
"color": &logrus.TextFormatter{DisableColors: false, FullTimestamp: true, TimestampFormat: "15:04:05:000", DisableSorting: true},
|
"color": {DisableColors: false, FullTimestamp: true, TimestampFormat: "15:04:05:000", DisableSorting: true},
|
||||||
}
|
}
|
||||||
var defaultLogFormat = "color"
|
var defaultLogFormat = "color"
|
||||||
|
|
||||||
|
62
vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/dir-index.html
vendored
Normal file
62
vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/dir-index.html
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<!-- TODO: seed these - maybe like the starter ex or the webui? -->
|
||||||
|
<link rel="stylesheet" href="/ipfs/QmXB7PLRWH6bCiwrGh2MrBBjNkLv3mY3JdYXCikYZSwLED/bootstrap.min.css"/>
|
||||||
|
<!-- helper to construct this is here: https://github.com/cryptix/exp/blob/master/imgesToCSSData/convert.go -->
|
||||||
|
<link rel="stylesheet" href="/ipfs/QmXB7PLRWH6bCiwrGh2MrBBjNkLv3mY3JdYXCikYZSwLED/icons.css">
|
||||||
|
<style>
|
||||||
|
.narrow {width: 0px;}
|
||||||
|
.padding { margin: 100px;}
|
||||||
|
#header {
|
||||||
|
background: #000;
|
||||||
|
}
|
||||||
|
#logo {
|
||||||
|
height: 25px;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
.ipfs-icon {
|
||||||
|
width:16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<title>{{ .Path }}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header" class="row">
|
||||||
|
<div class="col-xs-2">
|
||||||
|
<div id="logo" class="ipfs-logo"> </div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<strong>Index of {{ .Path }}</strong>
|
||||||
|
</div>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<tr>
|
||||||
|
<td class="narrow">
|
||||||
|
<div class="ipfs-icon ipfs-_blank"> </div>
|
||||||
|
</td>
|
||||||
|
<td class="padding">
|
||||||
|
<a href="{{.BackLink}}">..</a>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{{ range .Listing }}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="ipfs-icon {{iconFromExt .Name}}"> </div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ .Path }}">{{ .Name }}</a>
|
||||||
|
</td>
|
||||||
|
<td>{{ .Size }} bytes</td>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
61
vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/knownIcons.txt
vendored
Normal file
61
vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/knownIcons.txt
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
.aac
|
||||||
|
.aiff
|
||||||
|
.ai
|
||||||
|
.avi
|
||||||
|
.bmp
|
||||||
|
.c
|
||||||
|
.cpp
|
||||||
|
.css
|
||||||
|
.dat
|
||||||
|
.dmg
|
||||||
|
.doc
|
||||||
|
.dotx
|
||||||
|
.dwg
|
||||||
|
.dxf
|
||||||
|
.eps
|
||||||
|
.exe
|
||||||
|
.flv
|
||||||
|
.gif
|
||||||
|
.h
|
||||||
|
.hpp
|
||||||
|
.html
|
||||||
|
.ics
|
||||||
|
.iso
|
||||||
|
.java
|
||||||
|
.jpg
|
||||||
|
.js
|
||||||
|
.key
|
||||||
|
.less
|
||||||
|
.mid
|
||||||
|
.mp3
|
||||||
|
.mp4
|
||||||
|
.mpg
|
||||||
|
.odf
|
||||||
|
.ods
|
||||||
|
.odt
|
||||||
|
.otp
|
||||||
|
.ots
|
||||||
|
.ott
|
||||||
|
.pdf
|
||||||
|
.php
|
||||||
|
.png
|
||||||
|
.ppt
|
||||||
|
.psd
|
||||||
|
.py
|
||||||
|
.qt
|
||||||
|
.rar
|
||||||
|
.rb
|
||||||
|
.rtf
|
||||||
|
.sass
|
||||||
|
.scss
|
||||||
|
.sql
|
||||||
|
.tga
|
||||||
|
.tgz
|
||||||
|
.tiff
|
||||||
|
.txt
|
||||||
|
.wav
|
||||||
|
.xls
|
||||||
|
.xlsx
|
||||||
|
.xml
|
||||||
|
.yml
|
||||||
|
.zip
|
4
vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/package.json
vendored
Normal file
4
vendor/src/QmeNXKecZ7CQagtkQUJxG3yS7UcvU6puS777dQsx3amkS7/dir-index-html/package.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "dir-index-html",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
Reference in New Issue
Block a user