Feat: Initial Setup through env vars (#1736)
* initial support for initial setup * improve setup * improve mobile view * move base admin route * admin panel mobile view * set initial host and port * add docs * properly setup everything, use for dev env * change userconfig and interface port on setup, note users afterwards
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { eq, sql } from 'drizzle-orm';
|
||||
import { userConfig } from './schema';
|
||||
import type { UserConfigUpdateType } from './types';
|
||||
import { wgInterface } from '#db/schema';
|
||||
import type { DBType } from '#db/sqlite';
|
||||
|
||||
function createPreparedStatement(db: DBType) {
|
||||
@@ -8,14 +9,6 @@ function createPreparedStatement(db: DBType) {
|
||||
get: db.query.userConfig
|
||||
.findFirst({ where: eq(userConfig.id, sql.placeholder('interface')) })
|
||||
.prepare(),
|
||||
updateHostPort: db
|
||||
.update(userConfig)
|
||||
.set({
|
||||
host: sql.placeholder('host') as never as string,
|
||||
port: sql.placeholder('port') as never as number,
|
||||
})
|
||||
.where(eq(userConfig.id, sql.placeholder('interface')))
|
||||
.prepare(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,11 +31,26 @@ export class UserConfigService {
|
||||
return userConfig;
|
||||
}
|
||||
|
||||
// TODO: wrap ipv6 host in square brackets
|
||||
|
||||
/**
|
||||
* sets host of user config
|
||||
*
|
||||
* sets port of user config and interface
|
||||
*/
|
||||
updateHostPort(host: string, port: number) {
|
||||
return this.#statements.updateHostPort.execute({
|
||||
interface: 'wg0',
|
||||
host,
|
||||
port,
|
||||
return this.#db.transaction(async (tx) => {
|
||||
await tx
|
||||
.update(userConfig)
|
||||
.set({ host, port })
|
||||
.where(eq(userConfig.id, 'wg0'))
|
||||
.execute();
|
||||
|
||||
await tx
|
||||
.update(wgInterface)
|
||||
.set({ port })
|
||||
.where(eq(wgInterface.name, 'wg0'))
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user