Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
watzon committed Jan 13, 2025
1 parent 06ab9ca commit a1fe3e0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
19 changes: 13 additions & 6 deletions internal/server/handlers/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"encoding/json"
"fmt"
"regexp"

"github.com/dustin/go-humanize"
"github.com/gofiber/fiber/v2"
Expand All @@ -26,6 +27,12 @@ func NewWebHandlers(services *services.Services, logger *zap.Logger, config *con
}
}

var httpRe = regexp.MustCompile(`^https?://`)

func (h *WebHandlers) getBaseURL() string {
return httpRe.ReplaceAllString(h.config.Server.BaseURL, "")
}

// HandleIndex serves the main web interface page
func (h *WebHandlers) HandleIndex(c *fiber.Ctx) error {
h.logger.Debug("generating retention data for index page")
Expand All @@ -48,7 +55,7 @@ func (h *WebHandlers) HandleIndex(c *fiber.Ctx) error {
}

h.logger.Debug("preparing template data",
zap.String("baseUrl", h.config.Server.BaseURL),
zap.String("baseUrl", h.getBaseURL()),
zap.Any("retention", retentionStats))

err = c.Render("index", fiber.Map{
Expand All @@ -62,7 +69,7 @@ func (h *WebHandlers) HandleIndex(c *fiber.Ctx) error {
"noKeyHistory": string(noKeyHistory),
"withKeyHistory": string(withKeyHistory),
},
"baseUrl": h.config.Server.BaseURL,
"baseUrl": h.getBaseURL(),
}, "layouts/main")

if err != nil {
Expand All @@ -85,7 +92,7 @@ func (h *WebHandlers) HandleStats(c *fiber.Ctx) error {

return c.Render("stats", fiber.Map{
"stats": stats,
"baseUrl": h.config.Server.BaseURL,
"baseUrl": h.getBaseURL(),
}, "layouts/main")
}

Expand All @@ -97,8 +104,8 @@ func (h *WebHandlers) HandleDocs(c *fiber.Ctx) error {
}

return c.Render("docs", fiber.Map{
"baseUrl": h.config.Server.BaseURL,
"apiKeysEnabled": h.services.APIKey.HasMailer(),
"baseUrl": h.getBaseURL(),
"apiKeysEnabled": h.services.APIKey.IsEnabled(),
"retention": fiber.Map{
"noKey": retentionStats.NoKeyRange,
"withKey": retentionStats.WithKeyRange,
Expand All @@ -116,6 +123,6 @@ func (h *WebHandlers) HandleDocs(c *fiber.Ctx) error {
// HandleSubmit serves the paste submission page
func (h *WebHandlers) HandleSubmit(c *fiber.Ctx) error {
return c.Render("submit", fiber.Map{
"baseUrl": h.config.Server.BaseURL,
"baseUrl": h.getBaseURL(),
}, "layouts/main")
}
4 changes: 4 additions & 0 deletions internal/server/services/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (s *APIKeyService) HasMailer() bool {
return s.mailer != nil
}

func (s *APIKeyService) IsEnabled() bool {
return s.config.SMTP.Enabled && s.HasMailer()
}

// Helper functions

func (s *APIKeyService) sendVerificationEmail(email, token string) error {
Expand Down
76 changes: 76 additions & 0 deletions views/docs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ul>
<li><a href="#getting-started">Getting Started</a></li>
<li><a href="#file-upload-endpoints">File Upload Endpoints</a></li>
<li><a href="#integrations">Integrations</a></li>
{{#if apiKeysEnabled}}
<li><a href="#authentication">Authentication & API Keys</a></li>
<li><a href="#url-shortener">URL Shortener</a></li>
Expand Down Expand Up @@ -217,6 +218,81 @@ EOF</code>
</dl>
</section>

<section id="integrations">
<h2>Integrations</h2>

<h3>ShareX Integration</h3>
<p>Copy and save the following configuration as a <code>.sxcu</code> file, then import it into ShareX:</p>

<div class="labeled-code-block">
<span class="command-label json-label">JSON</span>
<div class="code-block">
<code>{
"Version": "15.0.0",
"Name": "0x45 Uploader",
"DestinationType": "ImageUploader, TextUploader, FileUploader",
"RequestMethod": "POST",
"RequestURL": "{{baseUrl}}/p",
{{#if apiKeysEnabled}}
"Headers": {
"Authorization": "Bearer YOUR_API_KEY"
},
{{/if}}
"Body": "MultipartFormData",
"FileFormName": "file",
"URL": "{json:url}"
}</code>
<button class="action-btn" data-clipboard data-clipboard-selector="#sharex-config"><span>Copy</span></button>
</div>
</div>

<p>After importing, you can set this as your default uploader in ShareX under "Destinations".</p>

<h3>Flameshot Integration</h3>
<p>Save this script to use Flameshot with 0x45:</p>

<div class="labeled-code-block">
<span class="command-label bash-label">BASH</span>
<div class="code-block">
<code>#!/bin/bash

# Detect clipboard command
if command -v wl-copy >/dev/null 2>&1; then
CLIP_CMD="wl-copy"
elif command -v xclip >/dev/null 2>&1; then
CLIP_CMD="xclip -selection clipboard"
elif command -v pbcopy >/dev/null 2>&1; then
CLIP_CMD="pbcopy"
else
echo "No clipboard command found. Please install xclip, wl-copy, or pbcopy"
exit 1
fi

filename="/tmp/screenshot-$(date +%Y%m%d-%H%M%S).png"
flameshot gui -r > "$filename"; if [ ! -s "$filename" ]; then
exit 1
fi

{{#if apiKeysEnabled}}
curl -s -H "Authorization: Bearer YOUR_API_KEY" {{baseUrl}}/p -F file=@"$filename" | jq -r '.url' | $CLIP_CMD
{{else}}
curl -s {{baseUrl}}/p -F file=@"$filename" | jq -r '.url' | $CLIP_CMD
{{/if}}</code>
<button class="action-btn" data-clipboard data-clipboard-selector="#flameshot-script"><span>Copy</span></button>
</div>
</div>

<p>Save this script somewhere in your PATH (e.g. <code>~/.local/bin/upload-screenshot</code>), make it executable with <code>chmod +x</code>, and bind it to a keyboard shortcut.</p>

<p>Dependencies:</p>
<ul>
<li><code>flameshot</code> - Screenshot tool</li>
<li><code>curl</code> - For uploading</li>
<li><code>jq</code> - For parsing JSON response</li>
<li>One of: <code>wl-copy</code> (Wayland), <code>xclip</code> (X11), or <code>pbcopy</code> (macOS)</li>
</ul>
</section>

{{#if apiKeysEnabled}}
<section id="url-shortener">
<h2>URL Shortener</h2>
Expand Down

0 comments on commit a1fe3e0

Please sign in to comment.