diff --git a/backend/service/templateService.go b/backend/service/templateService.go index 3d0cad0..8514b76 100644 --- a/backend/service/templateService.go +++ b/backend/service/templateService.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "encoding/base64" "fmt" "html" "html/template" @@ -431,6 +432,9 @@ func TemplateFuncs() template.FuncMap { goFormat := convertDateFormat(format) return targetTime.Format(goFormat) }, + "base64": func(s string) string { + return base64.StdEncoding.EncodeToString([]byte(s)) + }, } } diff --git a/frontend/src/lib/components/editor/Editor.svelte b/frontend/src/lib/components/editor/Editor.svelte index a3bd88b..2fa57ea 100644 --- a/frontend/src/lib/components/editor/Editor.svelte +++ b/frontend/src/lib/components/editor/Editor.svelte @@ -60,7 +60,8 @@ { label: 'URL escape', text: '{{urlEscape "content" }}' }, { label: 'Random alphanumeric', text: '{{randAlpha 8}}' }, { label: 'Random number', text: '{{randInt 1 4}}' }, - { label: 'Date', text: '{{date "Y-m-d H:i:s" 0}}' } + { label: 'Date', text: '{{date "Y-m-d H:i:s" 0}}' }, + { label: 'Base64', text: '{{base64 "text"}}' } ] }; @@ -228,6 +229,14 @@ }); } + // handle base64 function + if (text.includes('{{base64')) { + const r = /{{base64\s+"([^"]+)"}}/g; + text = text.replace(r, (match, input) => { + return btoa(input); + }); + } + // handle date function with format and optional offset if (text.includes('{{date')) { const r = /{{date\s+"([^"]+)"\s*(-?\d+)?}}/g;