Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Arabic Selection Option #1236

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1bea99d
Fix Arabic Language
Dec 28, 2024
d30ef26
Fix Arabic
BasselArt Dec 29, 2024
eb054d8
Change the default font
BasselArt Dec 29, 2024
0c3c071
Enhance Arabic Translation
BasselArt Dec 29, 2024
33508d4
Enhance Arabic Translation
BasselArt Dec 29, 2024
42c33e2
Fix Images Gravater
BasselArt Dec 29, 2024
697b117
Remove Unicode
BasselArt Dec 29, 2024
f3a0a52
Add Arabic Support to Avatar Generator
BasselArt Dec 29, 2024
24479c8
Add Arabic Support to Avatar Generator
BasselArt Dec 29, 2024
8e96e60
Add Arabic Support to Avatar Generator
BasselArt Dec 29, 2024
f4c2956
Fix Images Generator
BasselArt Dec 29, 2024
975e8ad
Update docker-compose.yml
BasselArt Dec 29, 2024
6665089
Add docker-compose.yml to .gitignore
BasselArt Dec 29, 2024
2a5e38e
Stop tracking docker-compose.yml
BasselArt Dec 29, 2024
422a341
Fix Letters Generator
BasselArt Dec 29, 2024
ed4a307
Fix Letters Generator
BasselArt Dec 29, 2024
cf08f49
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
fa515e1
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
b265097
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
2c1226f
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
31108ef
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
c811aed
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
a0f2f2e
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
8756c8c
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
33810e2
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
4d97357
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
47a2b93
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
dadb561
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
02e3b55
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
73ab727
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
8d23d0d
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
d65f76f
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
c92f7b1
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
eb21600
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
03774f5
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
c628caf
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
8e32a86
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
2defc58
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
319ab80
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
b87e902
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
d762c41
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
d7cf868
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
b033467
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
850e562
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
6473523
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
e65a179
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
1653f56
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
22a2903
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
a99fcbf
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
300c424
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
6e37e27
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
fc0cdaf
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
951b64a
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
f04f073
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
0eb592a
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
6220200
fix: Enhance Arabic Compatibility
BasselArt Dec 31, 2024
9e68a53
fix: Enhance Arabic Compatibility
BasselArt Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ cover.out
coverage.tmp
tsconfig.tsbuildinfo
etc/*.pem
docker-compose.yml
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ RUN make build-ui
################
FROM --platform=${TARGETPLATFORM:-linux/amd64} debian:bookworm-slim

RUN apt-get update
RUN apt-get install -y ca-certificates
RUN apt-get update && \
apt-get install -y ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion app/actions/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (action *UpdateTenantSettings) Validate(ctx context.Context, user *entity.U
MinHeight: 200,
MinWidth: 200,
MaxKilobytes: 100,
ExactRatio: true,
ExactRatio: false,
})
if err != nil {
return validate.Error(err)
Expand Down
86 changes: 79 additions & 7 deletions app/handlers/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ import (
"image/color"
"image/png"
"net/http"
"net/url"
"os"
"strings"
"time"

"github.com/getfider/fider/app/models/cmd"
"github.com/getfider/fider/app/models/dto"
"github.com/getfider/fider/app/models/query"

"github.com/getfider/fider/app/pkg/bus"
"github.com/getfider/fider/app/pkg/crypto"
"github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/letteravatar"
"github.com/getfider/fider/app/pkg/log"
"github.com/getfider/fider/app/pkg/web"
"github.com/goenning/imagic"
"github.com/goenning/letteravatar"
)

// LetterAvatar returns a letter gravatar picture based on given name
Expand All @@ -32,22 +31,38 @@ func LetterAvatar() web.HandlerFunc {
name = "?"
}

// URL decode the name
decodedName, err := url.QueryUnescape(name)
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

size, err := c.QueryParamAsInt("size")
if err != nil {
log.Error(c, err)
return c.BadRequest(web.Map{})
}
size = between(size, 50, 200)

img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{
PaletteKey: fmt.Sprintf("%s:%s", id, name),
extractedLetter := letteravatar.Extract(decodedName)
log.Debugf(c, "Generating letter avatar. Name: @{Name}, Letter: @{Letter}", dto.Props{
"Name": decodedName,
"Letter": extractedLetter,
})

img, err := letteravatar.Draw(size, extractedLetter, &letteravatar.Options{
PaletteKey: fmt.Sprintf("%s:%s", id, decodedName),
})
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

buf := new(bytes.Buffer)
err = png.Encode(buf, img)
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

Expand All @@ -70,10 +85,12 @@ func Gravatar() web.HandlerFunc {

size = between(size, 50, 200)

if err == nil && id > 0 {
var userName string
if id > 0 {
userByID := &query.GetUserByID{UserID: id}
err := bus.Dispatch(c, userByID)
if err == nil && userByID.Result.Tenant.ID == c.Tenant().ID {
userName = userByID.Result.Name
if userByID.Result.Email != "" {
url := fmt.Sprintf("https://www.gravatar.com/avatar/%s?s=%d&d=404", crypto.MD5(strings.ToLower(userByID.Result.Email)), size)
cacheKey := fmt.Sprintf("gravatar:%s", url)
Expand Down Expand Up @@ -105,7 +122,44 @@ func Gravatar() web.HandlerFunc {
}
}

return LetterAvatar()(c)
// Fallback to letter avatar if:
// 1. User ID is invalid
// 2. User not found
// 3. User has no email
// 4. Gravatar not found
name := c.QueryParam("name")
if name == "" {
name = userName
}
if name == "" {
name = "?"
}

// URL decode the name (matching LetterAvatar behavior)
decodedName, err := url.QueryUnescape(name)
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

// Use the same mechanism as LetterAvatar
extractedLetter := letteravatar.Extract(decodedName)
img, err := letteravatar.Draw(size, extractedLetter, &letteravatar.Options{
PaletteKey: fmt.Sprintf("%s:%s", fmt.Sprint(id), decodedName),
})
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

buf := new(bytes.Buffer)
err = png.Encode(buf, img)
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

return c.Image("image/png", buf.Bytes())
}
}

Expand Down Expand Up @@ -190,3 +244,21 @@ func ViewUploadedImage() web.HandlerFunc {
return c.Image(q.Result.ContentType, bytes)
}
}

// ValidateLogoUpload validates if logo upload is within allowed formats and size
func ValidateLogoUpload(c *web.Context) error {
contentType := c.Request.GetHeader("Content-Type")
if contentType != "image/png" && contentType != "image/jpeg" && contentType != "image/gif" && contentType != "image/svg+xml" {
return c.BadRequest(web.Map{
"message": "File format not supported. Upload only JPG, GIF, PNG or SVG files.",
})
}

if c.Request.ContentLength > 100*1024 {
return c.BadRequest(web.Map{
"message": "File size is too large. Maximum allowed size is 100KB.",
})
}

return nil
}
1 change: 1 addition & 0 deletions app/pkg/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var localeToPlurals = map[string]string{
"it": "it",
"tr": "tr",
"zh-CN": "zh",
"ar": "ar",
}

type Params map[string]any
Expand Down
Loading