From adb012e9cfff500e36a39cd91e0ea33114a0dbf7 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Tue, 18 Nov 2025 12:37:26 +0200 Subject: [PATCH] refactor: Simplify default server retrieval - Remove unused logic for default server lookup - Consolidate server retrieval for Cryptpad and ElementChat - Update default server assignment logic --- lib/installers/k8s/cryptpad/.heroscript | 12 ++++++------ .../k8s/cryptpad/cryptpad_factory_.v | 19 +++++-------------- .../k8s/element_chat/element_chat_factory_.v | 8 ++------ 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/installers/k8s/cryptpad/.heroscript b/lib/installers/k8s/cryptpad/.heroscript index 5956e3a6..9e7360c0 100644 --- a/lib/installers/k8s/cryptpad/.heroscript +++ b/lib/installers/k8s/cryptpad/.heroscript @@ -1,10 +1,10 @@ !!hero_code.generate_installer name:'cryptpad' classname:'CryptpadServer' - singleton:0 //there can only be 1 object in the globals, is called 'default' - templates:1 //are there templates for the installer - default:0 //can we create a default when the factory is used + singleton:0 + default:0 title:'' - supported_platforms:'' //osx, ... (empty means all) - reset:0 // regenerate all, dangerous !!! - startupmanager:0 //not managed by a startup manager + supported_platforms:'' + startupmanager:0 + hasconfig:1 + build:0 \ No newline at end of file diff --git a/lib/installers/k8s/cryptpad/cryptpad_factory_.v b/lib/installers/k8s/cryptpad/cryptpad_factory_.v index e448cb1e..b5e20dcf 100644 --- a/lib/installers/k8s/cryptpad/cryptpad_factory_.v +++ b/lib/installers/k8s/cryptpad/cryptpad_factory_.v @@ -28,12 +28,9 @@ pub fn new(args ArgsGet) !&CryptpadServer { return get(name: args.name)! } -pub fn get(args_ ArgsGet) !&CryptpadServer { - mut args := args_ +pub fn get(args ArgsGet) !&CryptpadServer { mut context := base.context()! - if args.name == 'cryptpad' && cryptpad_default != '' { - args.name = cryptpad_default - } + cryptpad_default = args.name if args.fromdb || args.name !in cryptpad_global { mut r := context.redis()! if r.hexists('context:cryptpad', args.name)! { @@ -52,17 +49,12 @@ pub fn get(args_ ArgsGet) !&CryptpadServer { return error("CryptpadServer with name '${args.name}' does not exist") } } - return get( - name: args.name - fromdb: args.fromdb - create: args.create - )! // no longer from db nor create + return get(name: args.name)! // no longer from db nor create } - result := cryptpad_global[args.name] or { + return cryptpad_global[args.name] or { print_backtrace() return error('could not get config for cryptpad with name:${args.name}') } - return result } // register the config for the future @@ -71,8 +63,7 @@ pub fn set(o CryptpadServer) ! { cryptpad_default = o2.name mut context := base.context()! mut r := context.redis()! - encoded := json.encode(o2) - r.hset('context:cryptpad', o2.name, encoded)! + r.hset('context:cryptpad', o2.name, json.encode(o2))! } // does the config exists? diff --git a/lib/installers/k8s/element_chat/element_chat_factory_.v b/lib/installers/k8s/element_chat/element_chat_factory_.v index 38216d3e..2e0e9541 100644 --- a/lib/installers/k8s/element_chat/element_chat_factory_.v +++ b/lib/installers/k8s/element_chat/element_chat_factory_.v @@ -28,13 +28,9 @@ pub fn new(args ArgsGet) !&ElementChat { return get(name: args.name)! } -pub fn get(args_ ArgsGet) !&ElementChat { +pub fn get(args ArgsGet) !&ElementChat { mut context := base.context()! - mut args := args_ - - if args.name == 'element_chat' && element_chat_default != '' { - args.name = element_chat_default - } + element_chat_default = args.name if args.fromdb || args.name !in element_chat_global { mut r := context.redis()! if r.hexists('context:element_chat', args.name)! {