Add config file, favicon, and fix domain
Signed-off-by: jolheiser <john.olheiser@gmail.com>main latest
parent
5b86331c78
commit
41d68ba36d
|
@ -8,8 +8,8 @@ import (
|
|||
"time"
|
||||
|
||||
"go.jolheiser.com/cabinet/internal/gc"
|
||||
router2 "go.jolheiser.com/cabinet/internal/router"
|
||||
workspace2 "go.jolheiser.com/cabinet/internal/workspace"
|
||||
"go.jolheiser.com/cabinet/internal/router"
|
||||
"go.jolheiser.com/cabinet/internal/workspace"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/rs/zerolog"
|
||||
|
@ -44,17 +44,17 @@ var serveCmd = func(opts *serveOpts) func(context.Context, []string) error {
|
|||
opts.domain = fmt.Sprintf("http://localhost:%d", opts.port)
|
||||
}
|
||||
|
||||
ws, err := workspace2.New(opts.workspacePath)
|
||||
ws, err := workspace.New(opts.workspacePath)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not open workspace")
|
||||
}
|
||||
|
||||
go gc.Start(ws, opts.maxDiskSize, opts.gcInterval)
|
||||
|
||||
r := router2.New(opts.domain, ws, router2.NewLimit(opts.requestPerMinute, opts.sizePerMinute, opts.burstSize, opts.memPerRequest))
|
||||
r := router.New(opts.domain, ws, router.NewLimit(opts.requestPerMinute, opts.sizePerMinute, opts.burstSize, opts.memPerRequest))
|
||||
|
||||
portStr := fmt.Sprintf(":%d", opts.port)
|
||||
log.Info().Msgf("Listening at http://localhost%s", portStr)
|
||||
log.Info().Msgf("Listening at %s", opts.domain)
|
||||
if err := http.ListenAndServe(portStr, r); err != nil {
|
||||
log.Err(err).Msg("could not start HTTP server")
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ var serveCmd = func(opts *serveOpts) func(context.Context, []string) error {
|
|||
|
||||
type tokenOpts struct {
|
||||
token string
|
||||
perm workspace2.TokenPermission
|
||||
perm workspace.TokenPermission
|
||||
desc string
|
||||
workspacePath string
|
||||
delete bool
|
||||
|
@ -72,7 +72,7 @@ type tokenOpts struct {
|
|||
|
||||
var tokenCmd = func(opts *tokenOpts) func(context.Context, []string) error {
|
||||
return func(_ context.Context, _ []string) error {
|
||||
ws, err := workspace2.New(opts.workspacePath)
|
||||
ws, err := workspace.New(opts.workspacePath)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not open workspace")
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ var tokenCmd = func(opts *tokenOpts) func(context.Context, []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
func addToken(ws *workspace2.Workspace, opts *tokenOpts) error {
|
||||
func addToken(ws *workspace.Workspace, opts *tokenOpts) error {
|
||||
token := opts.token
|
||||
if token == "" {
|
||||
r, err := randToken()
|
||||
|
@ -118,7 +118,7 @@ func addToken(ws *workspace2.Workspace, opts *tokenOpts) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
perm, err = workspace2.ParseTokenPermission(p)
|
||||
perm, err = workspace.ParseTokenPermission(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ func addToken(ws *workspace2.Workspace, opts *tokenOpts) error {
|
|||
}
|
||||
}
|
||||
|
||||
if err := ws.AddToken(workspace2.Token{
|
||||
if err := ws.AddToken(workspace.Token{
|
||||
Key: token,
|
||||
Permission: perm,
|
||||
Description: desc,
|
||||
|
@ -148,7 +148,7 @@ func addToken(ws *workspace2.Workspace, opts *tokenOpts) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func deleteTokens(ws *workspace2.Workspace, opts *tokenOpts) error {
|
||||
func deleteTokens(ws *workspace.Workspace, opts *tokenOpts) error {
|
||||
if opts.token != "" {
|
||||
if err := ws.DeleteTokens(opts.token); err != nil {
|
||||
return err
|
||||
|
|
|
@ -34,6 +34,7 @@ func main() {
|
|||
memPerRequest: 1024 * 1024, // 1 MiB
|
||||
}
|
||||
serveFS := flag.NewFlagSet("serve", flag.ExitOnError)
|
||||
serveFS.String("config", "", "Config file")
|
||||
serveFS.BoolVar(&serveOpts.jsonMode, "json", false, "Log as JSON")
|
||||
serveFS.BoolVar(&serveOpts.debugMode, "debug", false, "Debug logging")
|
||||
serveFS.Func("max-file-size", "Max size of a file", fileSizeParse(&serveOpts.maxFileSize))
|
||||
|
|
|
@ -41,6 +41,10 @@ func New(domain string, c Cabinet, limit *Limit) *chi.Mux {
|
|||
|
||||
m.Get("/", index(domain))
|
||||
m.Mount("/css/", http.StripPrefix("/css/", http.FileServer(http.FS(static.CSS))))
|
||||
m.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "image/x-icon")
|
||||
_, _ = w.Write(static.Favicon)
|
||||
})
|
||||
|
||||
m.Route("/r", func(r chi.Router) {
|
||||
r.Get("/{id}", s.GetRedirect)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
|
@ -8,8 +8,8 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Simple File Host</h1>
|
||||
<p>A simple website that just hosts your files and redirects.</p>
|
||||
<h1>Cabinet</h1>
|
||||
<p>A simple web application that hosts your files and redirects.</p>
|
||||
|
||||
<h2>How to upload files?</h2>
|
||||
<p>HTTP POST files:</p>
|
||||
|
|
|
@ -12,4 +12,7 @@ var (
|
|||
|
||||
//go:embed sakura.css
|
||||
CSS embed.FS
|
||||
|
||||
//go:embed favicon.ico
|
||||
Favicon []byte
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue