Skip to content

Commit 7b849bd

Browse files
author
hywax
committed
chore: set option title, link
1 parent d8b9aca commit 7b849bd

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

Diff for: components/service/base/Index.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
<ServicePlaceholder v-if="loadingOverlay" />
33
<div v-else class="p-4 flex gap-4">
44
<div class="flex-shrink-0 flex">
5-
<a :href="link" :target="target" class="self-center w-16 h-16 overflow-hidden rounded-2xl border border-fg/10 dark:border-fg/15">
5+
<Component :is="isLink ? 'a' : 'div'" :href="link" :target="target" class="self-center w-16 h-16 overflow-hidden rounded-2xl border border-fg/10 dark:border-fg/15">
66
<slot name="icon" :service="data">
77
<ServiceBaseIcon v-if="icon" v-bind="icon" />
88
</slot>
9-
</a>
9+
</Component>
1010
</div>
1111
<div>
1212
<h3 class="text-lg mt-1 font-semibold line-clamp-1 flex gap-2 items-center">
1313
<slot name="title" :service="data">
14-
<a :href="link" :target="target">{{ title }}</a>
14+
<a v-if="isLink" :href="link" :target="target">{{ title }}</a>
15+
<span v-else>{{ title }}</span>
1516
</slot>
1617
<slot v-if="status" name="status" :data="data">
1718
<ServiceBaseStatus :ping="data?.ping" />
@@ -33,6 +34,7 @@ import type { Service, ServiceClient } from '~/types'
3334
const props = defineProps<ServiceClient<Service>>()
3435
3536
const { $settings } = useNuxtApp()
37+
const isLink = computed(() => isUrl(props.link || ''))
3638
const target = computed(() => props.target || $settings.behaviour.target)
3739
3840
const immediate = computed(() => props.status?.enabled || !!props.type || false)

Diff for: server/utils/config.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export function validateConfigSchema(config: any) {
4141
})
4242

4343
const service = z.object({
44-
title: z.string(),
44+
title: z.string().optional(),
4545
description: z.string().optional(),
46-
link: z.string(),
46+
link: z.string().optional(),
4747
target: z.string().optional(),
4848
icon: icon.optional(),
4949
status: status.optional(),
5050
type: z.string().optional(),
51-
options: z.record(z.string()).optional(),
52-
secrets: z.record(z.string()).optional(),
51+
options: z.record(z.any()).optional(),
52+
secrets: z.record(z.any()).optional(),
5353
})
5454

5555
const schema = z.object({

Diff for: server/utils/services.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import type { H3Event } from 'h3'
22
import type { PingServiceData, ReturnServiceWithData, Service, ServiceWithDefaultData } from '~/types'
3+
import { isUrl } from '~/utils/validation'
34

45
export async function pingService(url: string): Promise<PingServiceData> {
56
try {
7+
if (!isUrl(url)) {
8+
throw createError({
9+
statusCode: 400,
10+
statusMessage: 'URL is not valid',
11+
})
12+
}
13+
614
const startTime = new Date().getTime()
715
await $fetch(url, { timeout: 15000 })
816
const endTime = new Date().getTime()
@@ -47,7 +55,7 @@ export async function getService<T extends Service>(event: H3Event): Promise<T>
4755
export async function getServiceWithDefaultData<S extends Service>(event: H3Event): Promise<ServiceWithDefaultData<S>> {
4856
const config = await getService<S>(event)
4957
const defaultData = {
50-
ping: config?.status?.enabled ? await pingService(config.link) : undefined,
58+
ping: config?.status?.enabled ? await pingService(config.link || '') : undefined,
5159
}
5260

5361
return { config, defaultData }

Diff for: types/services.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export interface ServiceIcon {
1414
export interface Service {
1515
id: string
1616
type?: string
17-
title: string
17+
title?: string
1818
description?: string
19-
link: string
19+
link?: string
2020
target?: '_blank' | '_self' | '_parent' | '_top'
2121
icon?: ServiceIcon
2222
status?: ServiceStatus
23-
options?: Record<string, string | number | boolean>
24-
secrets?: Record<string, string | number | boolean>
25-
server?: Record<string, string | number | boolean>
23+
options?: Record<string, any>
24+
secrets?: Record<string, any>
25+
server?: Record<string, any>
2626
}
2727

2828
export type ServiceClient<T> = Omit<T, 'secrets' | 'server'>

0 commit comments

Comments
 (0)