Skip to content

Commit

Permalink
makes server settings overwrite local
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Oct 26, 2023
1 parent a3756a0 commit 821cd3b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion assets/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ declare global {
// for type re-export
declare global {
// @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode } from 'vue'
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
}
// for vue template auto import
import { UnwrapRef } from 'vue'
Expand Down
4 changes: 2 additions & 2 deletions assets/composables/eventsource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function useLogStream() {
console.debug(`Connecting to ${containerId} with params`, params);

es = new EventSource(
`${config.base}/api/logs/stream/${container.value.host}/${containerId}?${new URLSearchParams(params).toString()}`,
withBase(`/api/logs/stream/${container.value.host}/${containerId}?${new URLSearchParams(params).toString()}`),
);
es.addEventListener("container-stopped", () => {
close();
Expand Down Expand Up @@ -118,7 +118,7 @@ export function useLogStream() {

const logs = await (
await fetch(
`${config.base}/api/logs/${container.value.host}/${containerId}?${new URLSearchParams(params).toString()}`,
withBase(`/api/logs/${container.value.host}/${containerId}?${new URLSearchParams(params).toString()}`),
)
).text();
if (logs) {
Expand Down
2 changes: 1 addition & 1 deletion assets/modules/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const install = (app: App) => {
const routes = setupLayouts(pages);

const router = createRouter({
history: createWebHistory(`${config.base}/`),
history: createWebHistory(withBase("/")),
routes,
});

Expand Down
4 changes: 2 additions & 2 deletions assets/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ let password = $ref("");
let form: HTMLFormElement | undefined = $ref();
async function onLogin() {
const response = await fetch(`${config.base}/api/validateCredentials`, {
const response = await fetch(withBase("/api/validateCredentials"), {
body: new FormData(form),
method: "post",
});
if (response.status == 200) {
error = false;
window.location.href = `${config.base}/`;
window.location.href = withBase("/");
} else {
error = true;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/stores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Config {
name: string;
avatar: string;
};
settings?: Settings;
serverSettings?: Settings;
}

const pageConfig = JSON.parse(text);
Expand Down
2 changes: 1 addition & 1 deletion assets/stores/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useContainerStore = defineStore("container", () => {
function connect() {
es?.close();
ready.value = false;
es = new EventSource(`${config.base}/api/events/stream`);
es = new EventSource(withBase("/api/events/stream"));
es.addEventListener("error", (e) => {
if (es?.readyState === EventSource.CLOSED) {
showToast(
Expand Down
3 changes: 1 addition & 2 deletions assets/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export const DEFAULT_SETTINGS: Settings = {
softWrap: true,
collapseNav: false,
automaticRedirect: true,
...config.settings,
};

export const settings = useStorage(DOZZLE_SETTINGS_KEY, DEFAULT_SETTINGS);
settings.value = { ...DEFAULT_SETTINGS, ...settings.value };
settings.value = { ...DEFAULT_SETTINGS, ...settings.value, ...config.serverSettings };

watch(settings, (value) => {
fetch(withBase("/api/profile/settings"), {
Expand Down
4 changes: 2 additions & 2 deletions internal/web/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
}
config["user"] = user
if settings, err := profile.LoadUserSettings(user); err == nil {
config["settings"] = settings
config["serverSettings"] = settings
} else {
config["settings"] = struct{}{}
config["serverSettings"] = struct{}{}
}
}

Expand Down

0 comments on commit 821cd3b

Please sign in to comment.