Merge branch 'dev' into compose

このコミットが含まれているのは:
Midou36O 2023-01-06 12:04:07 +00:00
コミット e6d314c715
15個のファイルの変更96行の追加41行の削除

ファイルの表示

@ -9,13 +9,14 @@ RUN git clone https://codeberg.org/gothub/gothub .
RUN go mod download
RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub
FROM scratch as bin
FROM alpine:3.16 as bin
WORKDIR /app
COPY --from=build /src/gothub .
COPY --from=build /src/views ./views
COPY --from=build /src/public ./public
ENV DOCKER true
EXPOSE 3000
CMD ["/app/gothub", "serve"]

ファイルの表示

@ -33,3 +33,10 @@ go build -o gothub
```
If you don't want to use port 3000 for GotHub, set the GOTHUB_PORT environment variable to the port you want to use.
## DMCA/Legal notice
All content shown on a GotHub instance is from GitHub. Any issues with content shown on a GotHub instance needs to be reported to GitHub, not the instance host's internet or domain provider.
GitHub is a registered trademark of GitHub, Inc. GotHub is not affiliated with GitHub, Inc.

12
go.mod
ファイルの表示

@ -5,7 +5,7 @@ go 1.19
require (
github.com/alecthomas/chroma/v2 v2.4.0
github.com/carlmjohnson/requests v0.22.3
github.com/gofiber/fiber/v2 v2.40.1
github.com/gofiber/fiber/v2 v2.41.0
github.com/gofiber/template v1.7.3
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c
github.com/microcosm-cc/bluemonday v1.0.21
@ -16,12 +16,12 @@ require (
require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/klauspost/compress v1.15.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
@ -30,6 +30,6 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.43.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
)

22
go.sum
ファイルの表示

@ -108,8 +108,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@ -137,8 +137,9 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.40.1 h1:pc7n9VVpGIqNsvg9IPLQhyFEMJL8gCs1kneH5D1pIl4=
github.com/gofiber/fiber/v2 v2.40.1/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk=
github.com/gofiber/fiber/v2 v2.41.0 h1:YhNoUS/OTjEz+/WLYuQ01xI7RXgKEFnGBKMagAu5f0M=
github.com/gofiber/fiber/v2 v2.41.0/go.mod h1:RdebcCuCRFp4W6hr3968/XxwJVg0K+jr9/Ae0PFzZ0Q=
github.com/gofiber/template v1.7.3 h1:ddWRgCB7kDdsgH7Qakwmlj6qM3kjggaT0aIhxLGatD0=
github.com/gofiber/template v1.7.3/go.mod h1:MI/DIYL6czowb8KLkkNAojCifLnAVQcN3KGEUDvlFtU=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -267,8 +268,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/compress v1.15.14 h1:i7WCKDToww0wA+9qrUZ1xOjp218vfFo3nTU6UHp+gOc=
github.com/klauspost/compress v1.15.14/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
@ -292,8 +293,9 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-slim v0.0.0-20200618151855-bde33eecb5ee/go.mod h1:ma9TUJeni8LGZMJvOwbAv/FOwiwqIMQN570LnpqCBSM=
@ -497,8 +499,8 @@ golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -595,8 +597,8 @@ golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

ファイルの表示

@ -36,6 +36,7 @@ func HandleExplore(c *fiber.Ctx) error {
}
return c.Render("explore", fiber.Map{
"title": "Explore",
"repos": trendingReposArray,
})
}

ファイルの表示

@ -1,26 +1,17 @@
package pages
import (
"runtime/debug"
"runtime"
"codeberg.org/gothub/gothub/utils"
"github.com/gofiber/fiber/v2"
)
// taken from https://git.vern.cc/pjals/bestofbot.
var Version = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value[:8]
}
}
}
return "unknown"
}()
func HandleIndex(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{
"host": c.Hostname(),
"version": Version,
"host": c.Hostname(),
"version": utils.Version(),
"fiberversion": fiber.Version,
"goversion": runtime.Version(),
})
}

ファイルの表示

@ -39,6 +39,7 @@ func HandleRepo(c *fiber.Ctx) error {
repo := utils.GetRequest("https://api.github.com/repos/" + c.Params("user") + "/" + c.Params("repo"))
if repo.Get("message").String() == "Not Found" {
return c.Status(404).Render("error", fiber.Map{
"title": "Error",
"error": "Repository " + c.Params("user") + "/" + c.Params("repo") + " not found",
})
}
@ -85,6 +86,7 @@ func HandleRepo(c *fiber.Ctx) error {
})
return c.Render("repo", fiber.Map{
"title": "Repository " + c.Params("user") + "/" + c.Params("repo"),
"repo": repoArray,
"files": repoFilesArray,
"readme": string(readmeOutput),

ファイルの表示

@ -112,7 +112,8 @@ func HandleUser(c *fiber.Ctx) error {
fmt.Println(userArray)
return c.Render("user", fiber.Map{
"user": userArray,
"Title": "User " + c.Params("user"),
"user": userArray,
})
}
}

ファイルの表示

@ -9,6 +9,7 @@
:root {
--text: #fff;
--background: #252525;
--secondary-background: #353535;
--background-darker: #151515;
--accent: #00b7c3;
}
@ -117,6 +118,8 @@ a:hover {
.userProfile h1 {
color: #00b7c3;
margin: 4px;
word-wrap: nowrap;
text-overflow: ellipsis;
}
.userProfile h2 {
@ -188,18 +191,29 @@ a:hover {
/* URI: /file/:user/:repo/:file */
.userReadme pre {
background-color: var(--background-darker);
padding: 8px;
border-radius: 8px;
/*white-space: pre-wrap;*/
overflow-x: auto;
}
.userContainer {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.secondary {
background-color: var(--secondary-background);
}
@media screen and (prefers-color-scheme: light) {
:root {
--text: #000;
--background: #f1f1f1;
--secondary-background: #e1e1e1;
--background-darker: #fff;
}
body {

ファイルの表示

@ -7,9 +7,11 @@ import (
"html/template"
"log"
"os"
"runtime"
"time"
"codeberg.org/gothub/gothub/pages"
"codeberg.org/gothub/gothub/utils"
"github.com/carlmjohnson/requests"
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
@ -169,6 +171,17 @@ func Serve() {
c.Response().Header.Del(fiber.HeaderServer)
return nil
})
api := app.Group("/api")
v1 := api.Group("/v1")
v1.Get("/version", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"version": utils.Version(),
"fiberversion": fiber.Version,
"goversion": runtime.Version(),
})
})
val, ok := os.LookupEnv("GOTHUB_PORT")
if !ok {
val = "3000"

17
utils/version.go ノーマルファイル
ファイルの表示

@ -0,0 +1,17 @@
package utils
import (
"runtime/debug"
)
// Version returns the git commit hash of the current build. Taken from https://git.vern.cc/pjals/bestofbot.
func Version() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value[:8]
}
}
}
return "unknown, please build with Go 1.13+ or use Git"
}

ファイルの表示

@ -8,11 +8,11 @@
</div>
<div class="userReadme">
<h3>{{.name}}</h3>
<div class="userContainer">
<h3>{{.name}}</h3>
<a href="/raw/{{.fullname}}/{{.branch}}/{{.name}}" class="button secondary">Raw</a>
</div>
{{ .file}}
</div>
<div class="downloadParent">
<a href="/raw/{{.fullname}}/{{.branch}}/{{.name}}" class="button">Download</a>
</div>
{{end}}
</main>

ファイルの表示

@ -1,7 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
{{ if .title }}
<title>{{ .title }} - GotHub</title>
{{ else }}
<title>GotHub</title>
{{ end }}
<link rel="stylesheet" href="/css/global.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="/favicon.ico">

ファイルの表示

@ -15,15 +15,17 @@
<h3>Usage</h3>
<p>Just replace <code class="indexGitHub">github.com</code> with <code class="indexGitHub">{{.host}}</code>!</p>
<h3>DMCA/Copyright Notice</h3>
<p>All content shown on this site are from GitHub. Any issues with content shown on this site needs to be reported to GitHub, not the instance host's internet or domain provider.</p>
<p>All content shown on this site are from GitHub. Any issues with content shown on this site needs to be reported to GitHub, not the instance host's internet or domain provider. GitHub is a registered trademark of GitHub, Inc. GotHub is not affiliated with GitHub, Inc.</p>
<p>This project was made as a "spiritual successor" to <a href="https://riverside.rocks" target="_blank">Riverside Rocks</a>' <a href="/RiversideRocks/1337git" target="_blank">1337git</a> which is, unfortunately, hosted on GitHub. Kinda ironic.</p>
<i>This project does not let you clone GitHub repositories. I would recommend using a VPN if you have to clone a GitHub repository and want to keep yourself private from them instead.</i>
<h3>Credits</h3>
<a href="https://midou36o.github.io">Midou36O</a> - desigining the GotHub logo
<br> <br/>
<h3>Info</h3>
{{ if eq .version "unknown"}}
GotHub version: <code>unknown</code>
{{ else }}
GotHub version: <a href="https://codeberg.org/gothub/gothub/commit/{{ .version}}"><code>{{ .version}}</code></a>
{{ end }}
<br>
Fiber version: {{ .fiberversion}}, running on {{ .goversion}}
</main>

ファイルの表示

@ -9,7 +9,7 @@
<div class="userProfile">
<img src="{{ .AvatarUrl }}" alt="{{.Login}}'s avatar" class="avatar" width="150" height="150">
{{ if .Name }}
<h1>{{.Name}}</h1>
<h1 class="user-profile-h1">{{.Name}}</h1>
{{ end }}
<h2>{{.Login}}</h2>
{{ if eq .Type "User" }}