diff --git a/doc/api.oa3 b/doc/api.oa3 index de646cae..f715f3af 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -3897,6 +3897,8 @@ components: type: boolean allowUnsealed: type: boolean + transformSupported: + type: boolean enableIce: type: boolean iceUrl: @@ -3953,6 +3955,8 @@ components: type: string searchable: type: boolean + allowUnsealed: + type: boolean pushEnabled: type: boolean sealable: @@ -4291,8 +4295,6 @@ components: updated: type: integer format: int64 - allowUnsealed: - type: boolean enableImage: type: boolean enableAudio: diff --git a/net/host/entrypoint.sh b/net/host/entrypoint.sh index 75b3e388..f38fcfd8 100755 --- a/net/host/entrypoint.sh +++ b/net/host/entrypoint.sh @@ -4,8 +4,6 @@ set -e sqlite3 /var/lib/databag/databag.db "VACUUM;" sqlite3 /var/lib/databag/databag.db "CREATE TABLE IF NOT EXISTS 'configs' ('id' integer NOT NULL UNIQUE,'config_id' text NOT NULL,'str_value' text,'num_value' integer,'bool_value' numeric,'bin_value' blob,PRIMARY KEY ('id'));" sqlite3 /var/lib/databag/databag.db "CREATE UNIQUE INDEX IF NOT EXISTS 'idx_configs_config_id' ON 'configs'('config_id');" -sqlite3 /var/lib/databag/databag.db "delete from configs where config_id='script_path';" -sqlite3 /var/lib/databag/databag.db "insert into configs (config_id, str_value) values ('script_path', '/opt/databag/transform/');" if [[ -v ADMIN ]]; then sqlite3 /var/lib/databag/databag.db "delete from configs where config_id='configured';" @@ -20,5 +18,5 @@ if [ "$DEV" == "1" ]; then done else cd /app/databag/net/server - /usr/local/go/bin/go run databag -p 7000 -w /app/databag/net/web/build -s /var/lib/databag + /usr/local/go/bin/go run databag -p 7000 -w /app/databag/net/web/build -s /var/lib/databag -t /opt/databag/transform fi diff --git a/net/server/internal/api_getNodeConfig.go b/net/server/internal/api_getNodeConfig.go index ffe3d0c2..41cbae5b 100644 --- a/net/server/internal/api_getNodeConfig.go +++ b/net/server/internal/api_getNodeConfig.go @@ -29,6 +29,7 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) { config.IcePassword = getStrConfigValue(CNFIcePassword, "") config.EnableOpenAccess = getBoolConfigValue(CNFEnableOpenAccess, false); config.OpenAccessLimit = getNumConfigValue(CNFOpenAccessLimit, 0); + config.TransformSupported = getStrConfigValue(CNFScriptPath, "") != ""; WriteResponse(w, config) } diff --git a/net/server/internal/models.go b/net/server/internal/models.go index 6dd602ea..0a16341b 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -372,6 +372,8 @@ type NodeConfig struct { AccountStorage int64 `json:"accountStorage"` + TransformSupported bool `json:"transformSupported"` + AllowUnsealed bool `json:"allowUnsealed"` PushSupported bool `json:"pushSupported"` diff --git a/net/server/internal/store/alloc.go b/net/server/internal/store/alloc.go index a1021959..30c678c9 100644 --- a/net/server/internal/store/alloc.go +++ b/net/server/internal/store/alloc.go @@ -10,8 +10,8 @@ import ( var DB *gorm.DB; -func SetPath(path string) { - db, err := gorm.Open(sqlite.Open(path + "/databag.db"), &gorm.Config{ +func SetPath(storePath string, transformPath string) { + db, err := gorm.Open(sqlite.Open(storePath + "/databag.db"), &gorm.Config{ Logger: logger.Default.LogMode(logger.Silent), }) if err != nil { @@ -20,12 +20,27 @@ func SetPath(path string) { } AutoMigrate(db) - // upsert key type + // upsert asset path err = db.Transaction(func(tx *gorm.DB) error { if res := tx.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "config_id"}}, DoUpdates: clause.AssignmentColumns([]string{"str_value"}), - }).Create(&Config{ConfigID: "asset_path", StrValue: path + "/assets"}).Error; res != nil { + }).Create(&Config{ConfigID: "asset_path", StrValue: storePath + "/assets"}).Error; res != nil { + return res + } + return nil + }) + if err != nil { + fmt.Println(err); + panic("failed to set database path") + } + + // upsert script path + err = db.Transaction(func(tx *gorm.DB) error { + if res := tx.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "config_id"}}, + DoUpdates: clause.AssignmentColumns([]string{"str_value"}), + }).Create(&Config{ConfigID: "script_path", StrValue: transformPath}).Error; res != nil { return res } return nil diff --git a/net/server/main.go b/net/server/main.go index e88e5819..74d07c8c 100644 --- a/net/server/main.go +++ b/net/server/main.go @@ -12,6 +12,7 @@ import ( func main() { var cert string var key string + var transformPath string port := ":443" storePath := "/var/lib/databag" @@ -29,19 +30,21 @@ func main() { cert = args[i + 1] } else if args[i] == "-k" { key = args[i + 1] + } else if args[i] == "-t" { + transformPath = args[i + 1] } } - store.SetPath(storePath); + store.SetPath(storePath, transformPath); router := app.NewRouter(webApp) origins := handlers.AllowedOrigins([]string{"*"}) methods := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"}) if cert != "" && key != "" { - log.Printf("using args:" + " -s " + storePath + " -w " + webApp + " -p " + port[1:] + " -c " + cert + " -k " + key) + log.Printf("using args:" + " -s " + storePath + " -w " + webApp + " -p " + port[1:] + " -c " + cert + " -k " + key + " -t " + transformPath) log.Fatal(http.ListenAndServeTLS(port, cert, key, handlers.CORS(origins, methods)(router))) } else { - log.Printf("using args:" + " -s " + storePath + " -w " + webApp + " -p " + port[1:]); + log.Printf("using args:" + " -s " + storePath + " -w " + webApp + " -p " + port[1:] + " -t " + transformPath) log.Fatal(http.ListenAndServe(port, handlers.CORS(origins, methods)(router))) } } diff --git a/net/web/src/dashboard/Dashboard.jsx b/net/web/src/dashboard/Dashboard.jsx index 93b1806b..66e65146 100644 --- a/net/web/src/dashboard/Dashboard.jsx +++ b/net/web/src/dashboard/Dashboard.jsx @@ -139,11 +139,13 @@ export function Dashboard() { actions.setPushSupported(e)} size="small" defaultChecked={true} checked={state.pushSupported} /> -
-
Allow Unsealed Topics: 
- actions.setAllowUnsealed(e)} size="small" - defaultChecked={true} checked={state.allowUnsealed} /> -
+ { state.transformSupported && ( +
+
Allow Unsealed Topics: 
+ actions.setAllowUnsealed(e)} size="small" + defaultChecked={true} checked={state.allowUnsealed} /> +
+ )}
Topic Content:
diff --git a/net/web/src/dashboard/useDashboard.hook.js b/net/web/src/dashboard/useDashboard.hook.js index f7eb09ce..ca9e942f 100644 --- a/net/web/src/dashboard/useDashboard.hook.js +++ b/net/web/src/dashboard/useDashboard.hook.js @@ -15,6 +15,7 @@ export function useDashboard() { keyType: null, pushSupported: null, allowUnsealed: null, + transformSupported: false, enableImage: null, enableAudio: null, enableVideo: null, @@ -129,7 +130,7 @@ export function useDashboard() { if (!state.busy) { updateState({ busy: true }); try { - const { domain, keyType, accountStorage, pushSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = state; + const { domain, keyType, accountStorage, pushSupported, transformSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = state; const storage = accountStorage * 1073741824; const config = { domain, accountStorage: storage, keyType, enableImage, enableAudio, enableVideo, pushSupported, allowUnsealed, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit }; await setNodeConfig(app.state.adminToken, config); @@ -147,9 +148,9 @@ export function useDashboard() { const syncConfig = async () => { try { const config = await getNodeConfig(app.state.adminToken); - const { storage, domain, keyType, pushSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = config; + const { storage, domain, keyType, pushSupported, transformSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = config; const accountStorage = Math.ceil(storage / 1073741824); - updateState({ configError: false, domain, accountStorage, keyType, enableImage, enableAudio, enableVideo, pushSupported, allowUnsealed, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit }); + updateState({ configError: false, domain, accountStorage, keyType, enableImage, enableAudio, enableVideo, pushSupported, transformSupported, allowUnsealed, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit }); } catch(err) { console.log(err);