Browse Source

Merge branch 'feature/comment-email-config'

main
npmrun 3 weeks ago
parent
commit
649b0d7a27
  1. 12
      app/pages/me/admin/config/index.vue
  2. 13
      server/api/config/global.get.ts

12
app/pages/me/admin/config/index.vue

@ -16,6 +16,7 @@ type GlobalConfigPayload = {
commentSmtpSecure: boolean
commentSmtpUser: string
commentSmtpPass: string
commentSmtpPassConfigured?: boolean
}
}
@ -38,18 +39,20 @@ const commentSmtpPort = ref(465)
const commentSmtpSecure = ref(true)
const commentSmtpUser = ref('')
const commentSmtpPass = ref('')
const commentSmtpPassConfigured = ref(false)
const commentEmailConfigReady = computed(() => {
const from = commentMailFromEmail.value.trim()
const host = commentSmtpHost.value.trim()
const user = commentSmtpUser.value.trim()
const pass = commentSmtpPass.value.trim()
const hasPass = pass.length > 0 || commentSmtpPassConfigured.value
const port = Number(commentSmtpPort.value)
return (
from.length > 0
&& host.length > 0
&& user.length > 0
&& pass.length > 0
&& hasPass
&& Number.isFinite(port)
&& port >= 1
&& port <= 65535
@ -77,7 +80,10 @@ async function load() {
commentSmtpPort.value = cfg.commentSmtpPort
commentSmtpSecure.value = cfg.commentSmtpSecure
commentSmtpUser.value = cfg.commentSmtpUser
commentSmtpPass.value = cfg.commentSmtpPass
commentSmtpPass.value = ''
commentSmtpPassConfigured.value = typeof cfg.commentSmtpPassConfigured === 'boolean'
? cfg.commentSmtpPassConfigured
: false
} finally {
loading.value = false
}
@ -111,6 +117,8 @@ async function save() {
const nextCommentSmtpPass = commentSmtpPass.value.trim()
if (nextCommentSmtpPass.length > 0) {
await putKey('commentSmtpPass', nextCommentSmtpPass)
commentSmtpPassConfigured.value = true
commentSmtpPass.value = ''
}
await load()
await refreshGlobalConfig()

13
server/api/config/global.get.ts

@ -20,7 +20,18 @@ export default defineWrappedResponseHandler(async (event) => {
}),
);
const config = Object.fromEntries(entries);
if (!isAdmin) {
return R.success({ config });
}
const smtpPassRaw = await event.context.config.getGlobal("commentSmtpPass");
const commentSmtpPassConfigured = typeof smtpPassRaw === "string" && smtpPassRaw.trim().length > 0;
return R.success({
config: Object.fromEntries(entries),
config: {
...config,
commentSmtpPassConfigured,
},
});
});

Loading…
Cancel
Save