Skip to content

Commit

Permalink
feat(nuxt3): slack bot
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed Jun 7, 2023
1 parent 1fef12f commit a91c85b
Show file tree
Hide file tree
Showing 33 changed files with 742 additions and 289 deletions.
4 changes: 2 additions & 2 deletions server/nuxt3/components/ConfigFlow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const initialElements = [
* useVueFlow provides all event handlers and store properties
* You can pass the composable an object that has the same properties as the VueFlow component props
*/
const { onPaneReady, onNodeDragStop, onConnect, addEdges } = useVueFlow()
const { onPaneReady, onConnect, addEdges } = useVueFlow()
/**
* Our elements
Expand All @@ -64,7 +64,7 @@ onPaneReady(({ fitView }) => {
fitView()
})
onNodeDragStop(e => console.log('drag stop', e))
// onNodeDragStop(e => console.log('drag stop', e))
/**
* onConnect is called when a new connection is created.
Expand Down
4 changes: 2 additions & 2 deletions server/nuxt3/components/vue-flow/PreviewConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ watch(outputEl, () => {
<code>{{ `\n${JSON.stringify(store.kvConfig, null, 2)}` }}</code>
</pre>
<pre mt-2 max-h-50 style="overflow: scroll; border:1px solid #b1aeae; border-radius: 4px;">
<code>{{ `\n${store.enKvConfig}` }}</code>
<code>{{ `\n${store.encodeUserConfig}` }}</code>
</pre>
<button v-if="isSupported" @click="copy(store.enKvConfig)">
<button v-if="isSupported" @click="copy(store.encodeUserConfig)">
<span v-if="!copied">Copy</span>
<span v-else>Copied!</span>
</button>
Expand Down
8 changes: 4 additions & 4 deletions server/nuxt3/components/vue-flow/SelectConfig.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup lang="ts">
import { Handle } from '@vue-flow/core'
import type { BasicConfig, ModelConfig } from '../../composables/config'
import type { BasicConfig, ModelsConfig } from '../../composables/config'
interface Props {
data: BasicConfig<ModelConfig>
data: BasicConfig<ModelsConfig>
}
const props = defineProps<Props>()
const model = props.data
Expand Down Expand Up @@ -74,7 +74,7 @@ function updateHandler() {
{{ o.label }}
</option>
</select>
<div v-for="c in info[model.select].config" :key="c.label">
<div v-for="c in info[model.select as keyof typeof info].config" :key="c.label">
<div mt-2 text-gray>
{{ c.label }} <span v-if="c.require" text-red>*</span>
</div>
Expand All @@ -83,7 +83,7 @@ function updateHandler() {
</div>
<div mt-2 flex items-center justify-end text-10px text-gray>
<div ref="outputEl">
{{ info[model.select].output }}
{{ info[model.select as keyof typeof info].output }}
</div>
</div>
<Handle
Expand Down
144 changes: 97 additions & 47 deletions server/nuxt3/composables/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface BasicConfig<T> {
icon: string
}
handles: IHandle[]
public: boolean
userConfig: boolean
select: string
info: T
}
Expand All @@ -33,35 +35,45 @@ export interface IHandle {
position: Position
}
export interface ModelConfig {
[key: string]: {
displayName: string
fn?: string
import?: string
config: {
[key: string]: IConfig
}
output: string
displayName: string
fn?: string
import?: string
config: {
[key: string]: IConfig
}
output: string
}
export type ModelsConfig = AppConfig | Record<string, ModelConfig>
export interface OutputConfig {
select: string
config: {
[key: string]: string
}
public: boolean
userConfig: boolean
config: Record<string, any> | null
fn?: string
import?: string
}
export interface OutUserConfig {
select: string
public: boolean
config: Record<string, any> | null
}
export interface KVConfig {
[select: string]: {
[config: string]: string
}
[select: string]: Record<string, any> | null
}

export type AppName = keyof AppConfig
export interface AppConfig {
telegram: ModelConfig
slack: ModelConfig
}
// @unocss-include
export const appConfig: BasicConfig<ModelConfig> = {
export const appConfig: BasicConfig<AppConfig> = {
title: {
text: 'App',
icon: 'i-carbon-application',
},
public: true,
userConfig: true,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -89,9 +101,9 @@ export const appConfig: BasicConfig<ModelConfig> = {
value: '',
require: true,
},
botName: {
label: 'Bot Name',
value: '',
language: {
label: 'Command Language',
value: 'en',
require: true,
},
},
Expand All @@ -100,13 +112,13 @@ export const appConfig: BasicConfig<ModelConfig> = {
slack: {
displayName: 'Slack Bot',
config: {
botToken: {
label: 'Webhook URL',
appId: {
label: 'App ID',
value: '',
require: true,
},
botName: {
label: 'Bot Name',
webhook: {
label: 'Incoming Webhook',
value: '',
require: true,
},
Expand All @@ -115,11 +127,13 @@ export const appConfig: BasicConfig<ModelConfig> = {
},
},
}
export const webInfoConfig: BasicConfig<ModelConfig> = {
export const webInfoConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'Website Info',
icon: 'i-carbon-document-preliminary',
},
public: true,
userConfig: true,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -157,11 +171,13 @@ export const webInfoConfig: BasicConfig<ModelConfig> = {
},
},
}
export const webCardConfig: BasicConfig<ModelConfig> = {
export const webCardConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'Website Card',
icon: 'i-carbon-image',
},
public: true,
userConfig: true,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -199,11 +215,13 @@ export const webCardConfig: BasicConfig<ModelConfig> = {
},
},
}
export const imgStorageConfig: BasicConfig<ModelConfig> = {
export const imgStorageConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'Image Storage',
icon: 'i-carbon-save-image',
},
public: true,
userConfig: true,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -243,11 +261,13 @@ export const imgStorageConfig: BasicConfig<ModelConfig> = {
},
},
}
export const dataStorageConfig: BasicConfig<ModelConfig> = {
export const dataStorageConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'Data Storage',
icon: 'i-carbon-db2-database',
},
public: false,
userConfig: true,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -287,11 +307,13 @@ export const dataStorageConfig: BasicConfig<ModelConfig> = {
},
},
}
export const llmConfig: BasicConfig<ModelConfig> = {
export const llmConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'LLM',
icon: 'i-carbon-ai-results',
},
public: false,
userConfig: true,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -331,11 +353,13 @@ export const llmConfig: BasicConfig<ModelConfig> = {
},
},
}
export const kvStorageConfig: BasicConfig<ModelConfig> = {
export const kvStorageConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'KV Storage',
icon: 'i-carbon-virtual-column-key',
},
public: false,
userConfig: false,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -368,11 +392,13 @@ export const kvStorageConfig: BasicConfig<ModelConfig> = {
},
},
}
export const serverConfig: BasicConfig<ModelConfig> = {
export const serverConfig: BasicConfig<ModelsConfig> = {
title: {
text: 'Cloud Server',
icon: 'i-carbon-ibm-cloud-citrix-daas',
},
public: false,
userConfig: false,
handles: [
{
id: 'input',
Expand Down Expand Up @@ -437,8 +463,8 @@ export const serverConfig: BasicConfig<ModelConfig> = {
},
},
}
export type ModelName = keyof ServerConfig<BasicConfig<ModelConfig>>
export const defaultConfig: ServerConfig<BasicConfig<ModelConfig>> = {
export type ModelName = keyof ServerConfig<BasicConfig<ModelsConfig>>
export const defaultConfig: ServerConfig<BasicConfig<ModelsConfig>> = {
app: appConfig,
webInfo: webInfoConfig,
webCard: webCardConfig,
Expand All @@ -451,51 +477,75 @@ export const defaultConfig: ServerConfig<BasicConfig<ModelConfig>> = {

const cryption = new Cryption(C1, C2)

export function getConfigKV(config: Record<string, IConfig>) {
const _obj: Record<string, any> = {}
Object.keys(config).forEach((x) => {
_obj[x] = config[x].value
})

return Object.keys(_obj).length ? _obj : null
}

export const useConfigStore = defineStore('server-config', () => {
const config = ref(defaultConfig)
const outConfig = computed(() => {
const keys = Object.keys(config.value)
const obj: Record<string, any> = {}
keys.forEach((k) => {
const c = config.value[k as ModelName]
const _config = c.info[c.select].config
const _fn = c.info[c.select].fn
const _import = c.info[c.select].import
const _obj: Record<string, any> = {}
Object.keys(_config).forEach((x) => {
_obj[x] = _config[x].value
})
obj[k] = { select: c.select, config: Object.keys(_obj).length ? _obj : null }
const select = c.select as keyof typeof c.info
const _config = getConfigKV(c.info[select].config)
const _fn = c.info[select].fn
const _import = c.info[select].import

obj[k] = { select: c.select, public: c.public, userConfig: c.userConfig, config: _config }
if (_fn)
obj[k].fn = _fn
if (_import)
obj[k].import = _import
})
return obj as ServerConfig<OutputConfig>
})
const outUserConfig = computed(() => {
const keys = Object.keys(config.value)
const obj: Record<string, any> = {}
keys.forEach((k) => {
const c = config.value[k as ModelName]
const select = c.select as keyof typeof c.info
if (c.userConfig) {
const _config = getConfigKV(c.info[select].config)
obj[k] = { select: c.select, public: c.public, config: _config }
}
})
return obj as ServerConfig<OutUserConfig>
})
const kvConfig = computed(() => {
const keys = Object.keys(config.value)
const obj: Record<string, any> = {}
keys.forEach((k) => {
const c = config.value[k as ModelName]
const _config = c.info[c.select].config
const _obj: Record<string, any> = {}
Object.keys(_config).forEach((x) => {
_obj[x] = _config[x].value
})
obj[k] = { [c.select]: Object.keys(_obj).length ? _obj : null }
const select = c.select as keyof typeof c.info
if (c.userConfig) {
const _config = getConfigKV(c.info[select].config)
obj[k] = { [c.select]: _config }
}
})
return obj as ServerConfig<KVConfig>
})
const enKvConfig = computed(() => {
const encodeKvConfig = computed(() => {
return cryption.encode(JSON.stringify(kvConfig.value))
})
const encodeUserConfig = computed(() => {
return cryption.encode(JSON.stringify(outUserConfig.value))
})

return {
config,
outConfig,
outUserConfig,
kvConfig,
enKvConfig,
encodeKvConfig,
encodeUserConfig,
}
})

Expand Down
Loading

1 comment on commit a91c85b

@vercel
Copy link

@vercel vercel bot commented on a91c85b Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

star-nexus – ./

star-nexus-larchliu.vercel.app
star-nexus-git-main-larchliu.vercel.app
star-nexus.vercel.app

Please sign in to comment.