mirror of
https://codeberg.org/gothub/gothub
synced 2024-12-06 19:16:24 +01:00
@@ -28,3 +28,6 @@ tmp/
|
||||
|
||||
# Fiber compressed files
|
||||
*.fiber.gz
|
||||
|
||||
# Env files
|
||||
*.env
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package gothub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
)
|
||||
|
||||
var envCmd = &cobra.Command{
|
||||
Use: "env",
|
||||
Short: "Get environment variable status",
|
||||
Long: `gothub env will show you the status of all environment variables that are used by GotHub.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(envCmd)
|
||||
}
|
||||
|
||||
func env() {
|
||||
// Docker check
|
||||
fmt.Println("Docker: " + os.Getenv("DOCKER"))
|
||||
// IP logging
|
||||
fmt.Println("IP logging: " + os.Getenv("GOTHUB_IP_LOGGED"))
|
||||
// URL request logging
|
||||
fmt.Println("URL request logging: " + os.Getenv("GOTHUB_REQUEST_URL_LOGGED"))
|
||||
// User-Agent logging
|
||||
fmt.Println("User-Agent logging: " + os.Getenv("GOTHUB_USER_AGENT_LOGGED"))
|
||||
// Diagnostic information logging
|
||||
fmt.Println("Diagnostic information logging: " + os.Getenv("GOTHUB_DIAGNOSTIC_INFO_LOGGED"))
|
||||
// Privacy Policy URL
|
||||
fmt.Println("Privacy Policy URL: " + os.Getenv("GOTHUB_INSTANCE_PRIVACY_POLICY"))
|
||||
// Instance country
|
||||
fmt.Println("Instance country: " + os.Getenv("GOTHUB_INSTANCE_COUNTRY"))
|
||||
// ISP
|
||||
fmt.Println("ISP/Hosting provider: " + os.Getenv("GOTHUB_INSTANCE_PROVIDER"))
|
||||
// Cloudflare status
|
||||
fmt.Println("Cloudflare status: " + os.Getenv("GOTHUB_INSTANCE_CLOUDFLARE"))
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package gothub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var setupCmd = &cobra.Command{
|
||||
Use: "setup",
|
||||
Short: "Interactive GotHub instance setup wizard",
|
||||
Long: `gothub setup allows you to setup your GotHub instance in an interactive way. It will ask you a few questions and then set environment variables for you.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
setup()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(setupCmd)
|
||||
}
|
||||
|
||||
type Vars struct {
|
||||
IPLogging bool
|
||||
URLLogging bool
|
||||
UserAgentLogging bool
|
||||
DiagnosticLogging bool
|
||||
PrivacyPolicy string
|
||||
InstanceCountry string
|
||||
InstanceProvider string
|
||||
CloudflareStatus string
|
||||
}
|
||||
|
||||
func setup() {
|
||||
fmt.Println("GotHub setup wizard - v1.0.0")
|
||||
fmt.Println("This wizard will help you setup your GotHub instance.")
|
||||
|
||||
// Docker check
|
||||
if os.Getenv("DOCKER") == "true" {
|
||||
fmt.Println("You are running GotHub in Docker. This wizard will not work in Docker. Please set the environment variables manually.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// set up variables
|
||||
vars := Vars{}
|
||||
|
||||
// ask user for information about IP logging
|
||||
fmt.Println("Do you log IP addresses of users? (y/n)")
|
||||
var ipLogging string
|
||||
fmt.Scanln(&ipLogging)
|
||||
if ipLogging == "y" {
|
||||
// create environment variable
|
||||
vars.IPLogging = true
|
||||
} else {
|
||||
// create environment variable
|
||||
vars.IPLogging = false
|
||||
}
|
||||
|
||||
// ask user for information about URL request logging
|
||||
fmt.Println("Do you log URL requests of users? (y/n)")
|
||||
var urlLogging string
|
||||
fmt.Scanln(&urlLogging)
|
||||
if urlLogging == "y" {
|
||||
vars.URLLogging = true
|
||||
} else {
|
||||
vars.URLLogging = false
|
||||
}
|
||||
|
||||
// ask user for information about User-Agent logging
|
||||
fmt.Println("Do you log your users User-Agent? (y/n)")
|
||||
var uaLogging string
|
||||
fmt.Scanln(&uaLogging)
|
||||
if uaLogging == "y" {
|
||||
vars.UserAgentLogging = true
|
||||
} else {
|
||||
vars.UserAgentLogging = false
|
||||
}
|
||||
|
||||
// ask user for information about diagnostic information logging
|
||||
fmt.Println("Do you log diagnostic information? (y/n)")
|
||||
var diagLogging string
|
||||
fmt.Scanln(&diagLogging)
|
||||
if diagLogging == "y" {
|
||||
vars.DiagnosticLogging = true
|
||||
} else {
|
||||
vars.DiagnosticLogging = false
|
||||
}
|
||||
|
||||
// ask user about privacy policy
|
||||
fmt.Println("Do you have a privacy policy? (y/n)")
|
||||
var privacyPolicy string
|
||||
fmt.Scanln(&privacyPolicy)
|
||||
if privacyPolicy == "y" {
|
||||
// ask user for privacy policy URL
|
||||
fmt.Println("Please enter the URL of your privacy policy.")
|
||||
var privacyPolicyURL string
|
||||
fmt.Scanln(&privacyPolicyURL)
|
||||
vars.PrivacyPolicy = privacyPolicyURL
|
||||
} else {
|
||||
vars.PrivacyPolicy = ""
|
||||
}
|
||||
|
||||
// ask user about the country they're hosting from
|
||||
fmt.Println("Please enter the country you're hosting from.")
|
||||
var country string
|
||||
fmt.Scanln(&country)
|
||||
if country != "" {
|
||||
vars.InstanceCountry = country
|
||||
} else {
|
||||
vars.InstanceCountry = ""
|
||||
}
|
||||
|
||||
// ask user about their ISP/Hosting provider
|
||||
fmt.Println("Please enter your ISP/Hosting provider.")
|
||||
var isp string
|
||||
fmt.Scanln(&isp)
|
||||
if isp != "" {
|
||||
vars.InstanceProvider = isp
|
||||
} else {
|
||||
vars.InstanceProvider = ""
|
||||
}
|
||||
|
||||
// ask user about Cloudflare status
|
||||
fmt.Println("Are you using Cloudflare? (y/n)")
|
||||
var cloudflare string
|
||||
fmt.Scanln(&cloudflare)
|
||||
if cloudflare == "y" {
|
||||
vars.CloudflareStatus = "true"
|
||||
} else {
|
||||
vars.CloudflareStatus = "false"
|
||||
}
|
||||
|
||||
// save to .env file
|
||||
fmt.Println("Saving environment variables to .env file...")
|
||||
f, err := os.Create(".env")
|
||||
if err != nil {
|
||||
fmt.Println("Error creating .env file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// write to file. make it look nice
|
||||
f.WriteString("GOTHUB_IP_LOGGED=" + fmt.Sprint(vars.IPLogging) + "\n")
|
||||
f.WriteString("GOTHUB_REQUEST_URL_LOGGED=" + fmt.Sprint(vars.URLLogging) + "\n")
|
||||
f.WriteString("GOTHUB_USER_AGENT_LOGGED=" + fmt.Sprint(vars.UserAgentLogging) + "\n")
|
||||
f.WriteString("GOTHUB_DIAGNOSTIC_INFO_LOGGED=" + fmt.Sprint(vars.DiagnosticLogging) + "\n")
|
||||
f.WriteString("GOTHUB_INSTANCE_PRIVACY_POLICY=" + vars.PrivacyPolicy + "\n")
|
||||
f.WriteString("GOTHUB_INSTANCE_COUNTRY=" + vars.InstanceCountry + "\n")
|
||||
f.WriteString("GOTHUB_INSTANCE_PROVIDER=" + vars.InstanceProvider + "\n")
|
||||
f.WriteString("GOTHUB_INSTANCE_CLOUDFLARE=" + vars.CloudflareStatus)
|
||||
|
||||
println("All done! You can now start your GotHub instance with 'gothub serve'.")
|
||||
println("You can review the environment variables with 'gothub env'.")
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package gothub
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -25,7 +26,7 @@ func init() {
|
||||
|
||||
func update() {
|
||||
if os.Getenv("DOCKER") == "true" {
|
||||
println("The GotHub update command does not work on Docker. Please re-create the container with a new image instead.")
|
||||
fmt.Println("The GotHub update command does not work on Docker. Please re-create the container with a new image instead.")
|
||||
os.Exit(1)
|
||||
}
|
||||
gitPull := exec.Command("git", "pull")
|
||||
@@ -33,29 +34,29 @@ func update() {
|
||||
gitPull.Stdout = &out
|
||||
err := gitPull.Run()
|
||||
if out.String() == "Already up to date.\r" {
|
||||
println("GotHub is already up to date.")
|
||||
fmt.Println("GotHub is already up to date.")
|
||||
os.Exit(0)
|
||||
}
|
||||
if err != nil {
|
||||
println("Couldn't run Git pull. Are you using Git?", err)
|
||||
fmt.Println("Couldn't run Git pull. Are you using Git?", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
err := exec.Command("go", "build", "-o", "gothub.exe").Run()
|
||||
if err != nil {
|
||||
println("Couldn't build GotHub.", err)
|
||||
fmt.Println("Couldn't build GotHub.", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
println("GotHub updated successfully.")
|
||||
fmt.Println("GotHub updated successfully.")
|
||||
os.Exit(0)
|
||||
}
|
||||
} else {
|
||||
err := exec.Command("go", "build").Run()
|
||||
if err != nil {
|
||||
println("Couldn't build GotHub.", err)
|
||||
fmt.Println("Couldn't build GotHub.", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
println("GotHub updated successfully.")
|
||||
fmt.Println("GotHub updated successfully.")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ require (
|
||||
github.com/honmaple/org-golang v0.0.0-20230228095001-29f0e7ec1f5f // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jawher/mow.cli v1.2.0 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/kennygrant/sanitize v1.2.4 // indirect
|
||||
github.com/klauspost/compress v1.15.14 // indirect
|
||||
github.com/m4tty/cajun v0.0.0-20150303030909-35de273cc87b // indirect
|
||||
|
||||
@@ -295,6 +295,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jawher/mow.cli v1.2.0 h1:e6ViPPy+82A/NFF/cfbq3Lr6q4JHKT9tyHwTCcUQgQw=
|
||||
github.com/jawher/mow.cli v1.2.0/go.mod h1:y+pcA3jBAdo/GIZx/0rFjw/K2bVEODP9rfZOfaiq8Ko=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
|
||||
+2
-2
@@ -20,9 +20,9 @@ type Items struct {
|
||||
func HandleExplore(c *fiber.Ctx) error {
|
||||
// get trending repos
|
||||
trendingRepos := utils.GetRequest("https://api.github.com/search/repositories?q=code&sort=stars&order=desc&per_page=25")
|
||||
bruh2 := trendingRepos.Get("items").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
|
||||
gjsonArray := trendingRepos.Get("items").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
|
||||
var trendingReposArray []Items
|
||||
for _, item := range bruh2 {
|
||||
for _, item := range gjsonArray {
|
||||
trendingReposArray = append(trendingReposArray, Items{
|
||||
Fullname: item.Get("full_name").String(),
|
||||
Description: item.Get("description").String(),
|
||||
|
||||
+3
-2
@@ -4,12 +4,13 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"html/template"
|
||||
|
||||
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
|
||||
"github.com/alecthomas/chroma/v2/lexers"
|
||||
"github.com/alecthomas/chroma/v2/styles"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
// FileView is the file view page
|
||||
@@ -56,7 +57,7 @@ func FileView(c *fiber.Ctx) error {
|
||||
writer.Flush()
|
||||
cssw.Flush()
|
||||
return c.Render("file", fiber.Map{
|
||||
"title": "File " + c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
|
||||
"title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
|
||||
"file": template.HTML(buf.String()),
|
||||
"css": template.CSS(cssbuf.String()),
|
||||
"fullname": c.Params("user") + "/" + c.Params("repo"),
|
||||
|
||||
+8
-7
@@ -2,14 +2,19 @@ package pages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"codeberg.org/gothub/gothub/utils"
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"codeberg.org/gothub/gothub/utils"
|
||||
"github.com/bytesparadise/libasciidoc"
|
||||
"github.com/bytesparadise/libasciidoc/pkg/configuration"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"github.com/gocolly/colly"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/hhatto/gorst"
|
||||
rst "github.com/hhatto/gorst"
|
||||
"github.com/honmaple/org-golang"
|
||||
"github.com/m4tty/cajun"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -17,10 +22,6 @@ import (
|
||||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
@@ -181,7 +182,7 @@ func HandleRepo(c *fiber.Ctx) error {
|
||||
readmeOutput := utils.UGCPolicy().SanitizeBytes(mightBeUnsafe)
|
||||
|
||||
return c.Render("repo", fiber.Map{
|
||||
"title": "Repository " + c.Params("user") + "/" + repoUrl + branchExists,
|
||||
"title": c.Params("user") + "/" + repoUrl + branchExists,
|
||||
"repo": repoArray,
|
||||
"files": repoFilesArray,
|
||||
"readme": string(readmeOutput),
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||
"github.com/gofiber/template/html"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
)
|
||||
|
||||
func Serve() {
|
||||
|
||||
Reference in New Issue
Block a user