5 Commits
v1.4.0 ... 2.0

Author SHA1 Message Date
orangix
61a312aba0 implement random gallery (#245)
closes #229

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/245
Co-authored-by: orangix <uleo8b8g@anonaddy.me>
Co-committed-by: orangix <uleo8b8g@anonaddy.me>
2026-01-23 16:54:56 +01:00
orangix
33fa04e98d change pages/about.go to Config.ForceWebp 2026-01-19 03:04:06 +01:00
orangix
e5b87dc924 gofmt 2026-01-19 02:36:52 +01:00
orangix
8cb2524924 drop RIMGU_ environment variables 2026-01-16 22:55:45 +01:00
video-prize-ranch
23b66cba47 Use full instance url for cache key (#243)
Closes #240

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/243
Reviewed-by: orangix <orangix@noreply.codeberg.org>
Co-authored-by: video-prize-ranch <cb.8a3w5@simplelogin.co>
Co-committed-by: video-prize-ranch <cb.8a3w5@simplelogin.co>
2026-01-14 18:27:25 +01:00
20 changed files with 113 additions and 109 deletions

View File

@@ -11,7 +11,7 @@ type Client struct {
Cache *cache.Cache
}
func NewClient(clientId string) (*Client) {
func NewClient(clientId string) *Client {
client := Client{
ClientID: clientId,
Cache: cache.New(15*time.Minute, 15*time.Minute),

View File

@@ -36,6 +36,8 @@ func (client *Client) FetchTrending(section, sort, page string) ([]Submission, e
case "best":
q.Add("filter[window]", "all")
q.Add("sort", "-top")
case "random":
q.Add("sort", "random")
case "popular":
fallthrough
default:
@@ -51,6 +53,8 @@ func (client *Client) FetchTrending(section, sort, page string) ([]Submission, e
case "top":
q.Add("filter[section]", "eq:top")
q.Add("filter[window]", "day")
case "random":
q.Add("filter[section]", "eq:random")
default:
q.Add("filter[section]", "eq:hot")
section = "hot"

View File

@@ -96,7 +96,7 @@ func main() {
Expiration: 30 * time.Minute,
MaxBytes: 25000000,
KeyGenerator: func(c *fiber.Ctx) string {
return utils.GetInstanceProtocol(c) + " " + c.OriginalURL()
return utils.GetInstanceUrl(c) + c.OriginalURL()
},
CacheControl: true,
StoreResponseHeaders: true,

View File

@@ -1,13 +1,10 @@
package pages
import (
"os"
"codeberg.org/rimgo/rimgo/utils"
"github.com/gofiber/fiber/v2"
)
func HandleAbout(c *fiber.Ctx) error {
utils.SetHeaders(c)
c.Set("X-Frame-Options", "DENY")
@@ -17,6 +14,6 @@ func HandleAbout(c *fiber.Ctx) error {
return c.Render("about", fiber.Map{
"proto": c.Protocol(),
"domain": c.Hostname(),
"force_webp": os.Getenv("FORCE_WEBP"),
"force_webp": utils.Config.ForceWebp,
})
}

View File

@@ -25,7 +25,7 @@ func HandleTrending(c *fiber.Ctx) error {
section := c.Query("section")
switch section {
case "hot", "new", "top":
case "hot", "new", "top", "random":
default:
section = "hot"
}

View File

@@ -21,51 +21,38 @@ type config struct {
var Config config
func envString(name, def string) string {
env := os.Getenv(name)
if env != "" {
return env
}
return def
}
func envBool(name string) bool {
return os.Getenv(name) == "true" || os.Getenv(name) == "1"
}
func LoadConfig() {
port := "3000"
if os.Getenv("PORT") != "" {
port = os.Getenv("PORT")
}
if os.Getenv("RIMGU_PORT") != "" {
port = os.Getenv("RIMGU_PORT")
}
addr := "0.0.0.0"
if os.Getenv("ADDRESS") != "" {
addr = os.Getenv("ADDRESS")
}
if os.Getenv("RIMGU_ADDRESS") != "" {
addr = os.Getenv("RIMGU_ADDRESS")
}
imgurId := "546c25a59c58ad7"
if os.Getenv("IMGUR_CLIENT_ID") != "" {
imgurId = os.Getenv("IMGUR_CLIENT_ID")
}
if os.Getenv("RIMGU_IMGUR_CLIENT_ID") != "" {
imgurId = os.Getenv("RIMGU_IMGUR_CLIENT_ID")
}
Config = config{
Port: port,
Addr: addr,
ImgurId: imgurId,
ProtocolDetection: os.Getenv("PROTOCOL_DETECTION") == "true" || os.Getenv("PROTOCOL_DETECTION") == "1",
Secure: os.Getenv("SECURE") == "true" || os.Getenv("SECURE") == "1",
FiberPrefork: os.Getenv("FIBER_PREFORK") == "true" || os.Getenv("FIBER_PREFORK") == "1",
ForceWebp: os.Getenv("FORCE_WEBP") == "true" || os.Getenv("FORCE_WEBP") == "1",
Port: envString("PORT", "3000"),
Addr: envString("ADDR", "0.0.0.0"),
ImgurId: envString("IMGUR_CLIENT_ID", "546c25a59c58ad7"),
ProtocolDetection: envBool("PROTOCOL_DETECTION"),
Secure: envBool("SECURE"),
FiberPrefork: envBool("FIBER_PREFORK"),
ForceWebp: envBool("FORCE_WEBP"),
Privacy: map[string]interface{}{
"set": os.Getenv("PRIVACY_NOT_COLLECTED") != "",
"policy": os.Getenv("PRIVACY_POLICY"),
"message": os.Getenv("PRIVACY_MESSAGE"),
"country": os.Getenv("PRIVACY_COUNTRY"),
"provider": os.Getenv("PRIVACY_PROVIDER"),
"cloudflare": os.Getenv("PRIVACY_CLOUDFLARE") == "true" || os.Getenv("PRIVACY_CLOUDFLARE") == "1",
"not_collected": os.Getenv("PRIVACY_NOT_COLLECTED") == "true" || os.Getenv("PRIVACY_NOT_COLLECTED") == "1",
"ip": os.Getenv("PRIVACY_IP") == "true" || os.Getenv("PRIVACY_IP") == "1",
"url": os.Getenv("PRIVACY_URL") == "true" || os.Getenv("PRIVACY_URL") == "1",
"device": os.Getenv("PRIVACY_DEVICE") == "true" || os.Getenv("PRIVACY_DEVICE") == "1",
"diagnostics": os.Getenv("PRIVACY_DIAGNOSTICS") == "true" || os.Getenv("PRIVACY_DIAGNOSTICS") == "1",
"cloudflare": envBool("PRIVACY_CLOUDFLARE"),
"not_collected": envBool("PRIVACY_NOT_COLLECTED"),
"ip": envBool("PRIVACY_IP"),
"url": envBool("PRIVACY_URL"),
"device": envBool("PRIVACY_DEVICE"),
"diagnostics": envBool("PRIVACY_DIAGNOSTICS"),
},
}
}

View File

@@ -35,7 +35,7 @@ func GetJSON(url string) (gjson.Result, error) {
return gjson.Result{}, err
}
switch (res.StatusCode) {
switch res.StatusCode {
case 200:
return gjson.Parse(string(body)), nil
case 429:

View File

@@ -30,20 +30,35 @@
<a href="?section=hot&sort={{sort}}"><b>Hot</b></a>
<a href="?section=new&sort={{sort}}">New</a>
<a href="?section=top&sort={{sort}}">Top</a>
<a href="?section=random&sort=random">Random</a>
{{/equal}}
{{#equal section "new"}}
<a href="?section=hot&sort={{sort}}">Hot</a>
<a href="?section=new&sort={{sort}}"><b>New</b></a>
<a href="?section=top&sort={{sort}}">Top</a>
<a href="?section=random&sort=random">Random</a>
{{/equal}}
{{#equal section "top"}}
<a href="?section=hot&sort={{sort}}">Hot</a>
<a href="?section=new&sort={{sort}}">New</a>
<a href="?section=top&sort={{sort}}"><b>Top</b></a>
<a href="?section=random&sort=random">Random</a>
{{/equal}}
{{#equal section "random"}}
<a href="?section=hot&sort={{sort}}">Hot</a>
<a href="?section=new&sort={{sort}}">New</a>
<a href="?section=top&sort={{sort}}">Top</a>
<a href="?section=random&sort=random"><b>Random</b></a>
{{/equal}}
</div>
<hr class="sm:hidden my-2" />
<div class="flex flex-col sm:items-end">
{{#equal section "random"}}
<a href="?section=hot&sort=popular">Popular</a>
<a href="?section=hot&sort=newest">Newest</a>
<a href="?section=hot&sort=best">Best</a>
{{/equal}}
{{#noteq section "random"}}
{{#equal sort "popular"}}
<a href="?section={{section}}&sort=popular"><b>Popular</b></a>
<a href="?section={{section}}&sort=newest">Newest</a>
@@ -59,6 +74,7 @@
<a href="?section={{section}}&sort=newest">Newest</a>
<a href="?section={{section}}&sort=best"><b>Best</b></a>
{{/equal}}
{{/noteq}}
</div>
</div>
</header>