Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions components/Forms/PublishForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script setup lang="ts">
// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import * as z from "zod";
import { TTLType } from "@throttr/sdk";
import type {FormSubmitEvent} from "@nuxt/ui";

const {t} = useI18n()

const props = defineProps(['channel']);
const emit = defineEmits(['success'])

const schema = z.object({
// @ts-ignore: This is-as documentation said.
value: z.string(),
})

type Schema = z.output<typeof schema>

const state = reactive<Partial<Schema>>({
value: '',
})

const toast = useToast()
const route = useRoute()

const submit = async (event: FormSubmitEvent<Schema>) => {
try {
const response = await $fetch(`/api/services/${route.params.id}/publish`, {
method: 'POST',
body: {
channel: props.channel,
value: event.data.value
}
})

toast.add({title: t('forms.event', { name: "Published"}), color: 'success'})
console.log("Published ⤑ Response", response)

emit('success');

} catch (error) {
toast.add({title: t('forms.event', { name: "Published ⤑ Exception"}), color: 'error'})
console.error("Published ⤑ Exception", error)

throw error;
}
}
</script>

<template>
<UForm :schema="schema" :state="state" class="space-y-4" @submit="submit">

<UFormField label="Value" name="value">
<UInput v-model="state.value" class="w-full" />
</UFormField>

<UButton label="Confirm" type="submit"/>
</UForm>
</template>
2 changes: 0 additions & 2 deletions components/Resources/Services/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import MetricCard from "~/components/Cards/MetricCard.vue";
import TimedMetricCard from "~/components/Cards/TimedMetricCard.vue";
import type {InfoResponse} from "@throttr/sdk";
import { formatDate } from "~/server/throttr/utils";
import MemoryChart from "~/components/Charts/MemoryChart.vue";

const route = useRoute()
const services = useServices()
Expand Down
16 changes: 15 additions & 1 deletion components/Tables/ChannelsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ const columns: TableColumn<ChannelItem>[] = [
open_channel.value = true;
}
}, {
label: 'Update',
label: 'Publish',
async onSelect() {
channel_publish.value = row.original.channel;
open_publish.value = true;
}
}, {
type: 'separator'
Expand Down Expand Up @@ -103,6 +105,8 @@ const columns: TableColumn<ChannelItem>[] = [

const props = defineProps(['channels'])
const open_channel = ref(false);
const open_publish = ref(false);
const channel_publish = ref('');

const sorting = ref([
{
Expand All @@ -124,5 +128,15 @@ const sorting = ref([
<TablesChannelConnectionsTable :connections="channel.connections" />
</template>
</UModal>
<!-- PUBLISH -->
<UModal v-model:open="open_publish"
title="Publish"
description="Complete the form to send a message to the connection"
:dismissible="true"
:close="true">
<template #body>
<FormsPublishForm :channel="channel_publish" v-on:success="open_publish = false;"/>
</template>
</UModal>
<UTable v-model:sorting="sorting" :data="props.channels" :columns="columns" class="w-full"/>
</template>
29 changes: 15 additions & 14 deletions components/Tables/ConnectionsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,12 @@ const columns: TableColumn<ConnectionsItem>[] = [
}, {
label: 'View',
async onSelect() {

}
}, {
label: 'Update',
async onSelect() {
}
}, {
type: 'separator'
}, {
label: 'Stats',
async onSelect() {
}
}, {
type: 'separator'
}, {
label: 'Remove',
label: 'Publish',
async onSelect() {
publish_channel.value = row.original.id;
open_publish.value = true;
}
}]

Expand All @@ -92,8 +81,20 @@ const columns: TableColumn<ConnectionsItem>[] = [

const props = defineProps(['connections'])

const open_publish = ref(false);
const publish_channel = ref('');

</script>

<template>
<UModal v-model:open="open_publish"
title="Publish"
description="Complete the form to send a message to the connection"
:dismissible="true"
:close="true">
<template #body>
<FormsPublishForm :channel="publish_channel" v-on:success="open_publish = false;"/>
</template>
</UModal>
<UTable :data="props.connections" :columns="columns" class="flex-1" />
</template>
37 changes: 37 additions & 0 deletions server/api/services/[id]/publish.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import {getServices, ServiceWrapper} from '~/server/throttr/instances'
import {RequestType, StatusResponse} from '@throttr/sdk'

export default defineEventHandler(async (event) => {
const services = getServices();
const body = await readBody(event)

const { channel, value } = body

if (!channel || !value) {
throw createError({ statusCode: 400, statusMessage: 'Missing parameters' })
}
const { id } = event.context.params!;

const index = services.findIndex((item) => item.id === id);
const service : ServiceWrapper = services[index];
return (await service.instance.send({
type: RequestType.Publish,
channel: channel,
value: value,
})) as StatusResponse;
})