5 Commits

Author SHA1 Message Date
d94c9bf4e6 novalagung is going to love this.
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 3m13s
2025-05-22 20:28:01 -04:00
f00f9b0946 forgot a contact page woops haha
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 5m7s
2025-05-22 20:18:20 -04:00
b0d4f3f890 Updated
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled
2025-05-22 20:15:01 -04:00
e9e0d30c7a [FIX] asdf
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 1m44s
2025-05-22 18:46:03 -04:00
0c458dd965 you do wanna make me cry and i wanna say goodbye
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled
2025-05-22 18:38:25 -04:00
6 changed files with 109 additions and 81 deletions

View File

@@ -12,7 +12,6 @@ jobs:
steps:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
apt update && apt install -yq ca-certificates curl
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates

View File

@@ -12,7 +12,6 @@ jobs:
steps:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
apt update && apt install -yq ca-certificates curl
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates

View File

@@ -15,7 +15,6 @@ jobs:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
apt update && apt install -yq ca-certificates curl
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates

View File

@@ -6,6 +6,7 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"errors"
"io"
)
@@ -15,6 +16,23 @@ func pkcs7pad(data []byte, blockSize int) []byte {
return append(data, padding...)
}
func pkcs7unpad(data []byte) ([]byte, error) {
length := len(data)
if length == 0 {
return nil, errors.New("invalid padding size")
}
padLen := int(data[length-1])
if padLen > length || padLen == 0 {
return nil, errors.New("invalid padding")
}
for _, v := range data[length-padLen:] {
if int(v) != padLen {
return nil, errors.New("invalid padding")
}
}
return data[:length-padLen], nil
}
func (g *Generator) Decrypt(s string) (string, error) {
c, err := aes.NewCipher(g.encryptionKey)
if err != nil {
@@ -32,7 +50,12 @@ func (g *Generator) Decrypt(s string) (string, error) {
cbc.CryptBlocks(cryptText, cryptText)
return string(cryptText), err
decrypted, err := pkcs7unpad(cryptText)
if err != nil {
return "", err
}
return string(decrypted), err
}
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {

View File

@@ -41,9 +41,8 @@ func (g *Generator) GenerateUrl(file string, params []string, format Format) (st
if params == nil || len(params) == 0 || params[0] == "" {
params = []string{"raw:1"}
} else {
params = append(params, "sm:1")
}
params = append(params, "sm:1")
if PathPrefix != "" {
file = PathPrefix + file
@@ -54,11 +53,11 @@ func (g *Generator) GenerateUrl(file string, params []string, format Format) (st
var url string
var err error
if config.GetConfig().Generator.PlainUrl {
url, _ = g.generatePlainUrl(file)
url, err = g.generatePlainUrl(file)
} else if g.encryptionKey != nil {
url, err = g.generateBaseAesEncUrl([]byte(file))
} else {
url, _ = g.generateBase64Url([]byte(file))
url, err = g.generateBase64Url([]byte(file))
}
if err != nil {

View File

@@ -5,95 +5,104 @@ import (
"github.com/charmbracelet/huh"
)
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Helper: find index of current focusField in a given field slice.
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) findCurrentFieldIndex(fields []huh.Field) int {
for i, field := range fields {
if field == m.focusField {
return i
}
}
return -1
}
if m.focusField == nil {
m.Fields[0].Focus()
m.focusField = m.Fields[0]
// Helper: blur current, focus next (wraps to 0)
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) focusNextField(fields []huh.Field) {
index := m.findCurrentFieldIndex(fields)
next := (index + 1) % len(fields)
m.focusField.Blur()
m.focusField = fields[next]
m.focusField.Focus()
}
// Helper: focus a specific field by index
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) focusFieldByIndex(fields []huh.Field, index int) {
if index >= 0 && index < len(fields) {
m.focusField.Blur()
m.focusField = fields[index]
m.focusField.Focus()
}
}
// Helper: get all selected param fields as a flat slice
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) selectedParamFields() []huh.Field {
var fields []huh.Field
for _, param := range *m.selectedParams {
fields = append(fields, param.Input()...)
}
return fields
}
//goland:noinspection GoMixedReceiverTypes
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
model := m // copy, since Bubble Tea prefers value receivers, but we'll operate on &model internally
if model.focusField == nil && len(model.Fields) > 0 {
model.Fields[0].Focus()
model.focusField = model.Fields[0]
}
if msg, ok := msg.(tea.KeyMsg); ok {
switch msg.String() {
if keyMsg, ok := msg.(tea.KeyMsg); ok {
switch keyMsg.String() {
case "tab":
if m.focusField != nil {
mainFields := model.Fields
paramFields := model.selectedParamFields()
index := -1
selectedParamFields := make([]huh.Field, 0)
for _, field := range *m.selectedParams {
for _, f := range field.Input() {
selectedParamFields = append(selectedParamFields, f)
}
}
if m.inParamsFields {
for i, field := range selectedParamFields {
if field == m.focusField {
index = i
break
}
}
} else {
for i, field := range m.Fields {
if field == m.focusField {
index = i
break
}
}
}
// if the field is not found, return
if model.inParamsFields && len(paramFields) > 0 {
index := model.findCurrentFieldIndex(paramFields)
if index == -1 {
return m, nil
break
}
// if the field is the last one, and we have params selected go to the param fields
if !m.inParamsFields && index == len(m.Fields)-1 && len(selectedParamFields) > 0 {
m.focusField.Blur()
m.inParamsFields = true
paramsFields := selectedParamFields
m.focusField = paramsFields[0]
m.focusField.Focus()
// if the field is the last one, and we have params selected go to the first non params field
} else if m.inParamsFields && index == len(selectedParamFields)-1 {
m.focusField.Blur()
m.inParamsFields = false
m.focusField = m.Fields[0]
m.focusField.Focus()
// if not in the params fields and the field is the last one, go to the first one
} else if index == len(m.Fields)-1 && !m.inParamsFields {
m.focusField.Blur()
m.focusField = m.Fields[0]
m.focusField.Focus()
if index == len(paramFields)-1 {
// Last param field: cycle to main fields
model.inParamsFields = false
model.focusFieldByIndex(mainFields, 0)
} else {
// otherwise, go to the next field
m.focusField.Blur()
if m.inParamsFields {
m.focusField = selectedParamFields[index+1]
} else {
m.focusField = m.Fields[index+1]
}
m.focusField.Focus()
model.focusNextField(paramFields)
}
} else {
index := model.findCurrentFieldIndex(mainFields)
if index == -1 {
break
}
if index == len(mainFields)-1 && len(paramFields) > 0 {
// Last main field & params exist: go to params
model.inParamsFields = true
model.focusFieldByIndex(paramFields, 0)
} else {
model.focusNextField(mainFields)
}
}
case "ctrl+c", "esc":
return m, tea.Quit
return model, tea.Quit
case "enter":
return m, nil
return model, nil
default:
if m.focusField != nil {
md, cmd := m.focusField.(huh.Field).Update(msg)
if model.focusField != nil {
md, cmd := model.focusField.(huh.Field).Update(msg)
if md != nil {
m.focusField = md.(huh.Field)
model.focusField = md.(huh.Field)
}
return m, cmd
return model, cmd
}
}
}
return m, nil
return model, nil
}