Skip to content

Commit 121e37f

Browse files
committed
Add support for online status in Media Providers
1 parent 3626533 commit 121e37f

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

AiServer.ServiceInterface/MediaProviderServices.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public object Any(QueryMediaProviders request)
3535
using var db = autoQuery.GetDb(request, base.Request);
3636
var q = autoQuery.CreateQuery(request, base.Request, db);
3737
var r = autoQuery.Execute(request, q, base.Request, db);
38-
r.Results.ForEach(x => x.MediaType = appData.MediaTypes.GetAll()
39-
.FirstOrDefault(t => t.Id == x.MediaTypeId));
38+
var providers = appData.MediaProviders.ToDictionary(x => x.Id);
39+
r.Results.ForEach(x =>
40+
{
41+
x.OfflineDate = providers.GetValueOrDefault(x.Id)?.OfflineDate;
42+
x.MediaType = appData.MediaTypes.GetAll().FirstOrDefault(t => t.Id == x.MediaTypeId);
43+
});
4044
return r;
4145
}
4246

AiServer.ServiceInterface/OpenAiChatServices.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public object Any(QueryAiProviders query)
8686
var q = autoQuery.CreateQuery(query, base.Request, db);
8787
var r = autoQuery.Execute(query, q, base.Request, db);
8888
var aiTypes = appData.AiTypes.GetAll().ToDictionary(x => x.Id);
89-
var aiProviders = appData.AiProviders.ToDictionary(x => x.Id);
89+
var providers = appData.AiProviders.ToDictionary(x => x.Id);
9090
r.Results.ForEach(x =>
9191
{
92-
x.OfflineDate = aiProviders.GetValueOrDefault(x.Id)?.OfflineDate;
92+
x.OfflineDate = providers.GetValueOrDefault(x.Id)?.OfflineDate;
9393
x.AiType = aiTypes.GetValueOrDefault(x.AiTypeId);
9494
});
9595
return r;

AiServer/wwwroot/mjs/components/AiProviders.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ export default {
175175
const selectedModels = ref([])
176176
const providerBaseUrls = {}
177177
const formModel = computed(() => (grid.value?.createForm ?? grid.value?.editForm)?.model)
178-
const checking = ref(false)
179178
let isEdit = false
179+
const checking = ref(false)
180180
const { formatDate, relativeTime } = useFormatters()
181181

182182
onMounted(async () => {

AiServer/wwwroot/mjs/components/MediaProviders.mjs

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ref, computed, onMounted, watch } from "vue"
2-
import { useClient } from "@servicestack/vue"
3-
import { QueryMediaModels, QueryMediaTypes, GetComfyModels } from "../dtos.mjs"
2+
import { useClient, useFormatters } from "@servicestack/vue"
3+
import {QueryMediaModels, QueryMediaTypes, GetComfyModels, CheckMediaProviderStatus} from "../dtos.mjs"
44

55
const SelectModels = {
66
template: `
@@ -255,12 +255,13 @@ export default {
255255
SelectModels,
256256
},
257257
template: `
258-
<AutoQueryGrid ref="grid" :type="type" selectedColumns="id,enabled,name,type,mediaTypeId,apiKey,models"
259-
:visibleFrom="{ id:'never', enabled:'never', mediaTypeId:'never'}" modelTitle="Generation Provider" @nav="onNav">
260-
<template #name="{ id, name, enabled }">
258+
<AutoQueryGrid ref="grid" :type="type" selectedColumns="id,enabled,offlineDate,name,type,mediaTypeId,apiKey,models"
259+
:visibleFrom="{ id:'never', enabled:'never', offlineDate:'never', mediaTypeId:'never'}" modelTitle="Generation Provider" @nav="onNav">
260+
<template #name="{ id, name, enabled, offlineDate }">
261261
<div class="flex">
262262
<svg v-if="enabled" class="w-6 h-6 text-green-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="M17 7H7a5 5 0 0 0-5 5a5 5 0 0 0 5 5h10a5 5 0 0 0 5-5a5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3a3 3 0 0 1 3-3a3 3 0 0 1 3 3a3 3 0 0 1-3 3"/></svg>
263263
<svg v-else class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6m0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4M7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3s3-1.34 3-3s-1.34-3-3-3"/></svg>
264+
<span :title="!enabled ? 'disabled' : offlineDate ? 'offline ' + relativeTime(offlineDate) : 'online'"><svg :class="['h-6 w-6', !enabled ? 'text-grey-500' : offlineDate ? 'text-red-500' : 'text-green-500']" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="8" fill="currentColor"/></svg></span>
264265
<div class="ml-1">{{name}}</div>
265266
</div>
266267
</template>
@@ -298,6 +299,13 @@ export default {
298299
</div>
299300
</template>
300301
<template #formfooter="{ form, formInstance, apis, model, editId, updateModel }">
302+
<div v-if="form=='edit'" class="pl-6 mb-2 text-gray-500">
303+
<div class="flex">
304+
<svg :class="['h-6 w-6', !model.enabled ? 'text-grey-500' : model.offlineDate ? 'text-red-500' : 'text-green-500']" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="8" fill="currentColor"/></svg>
305+
<span>{{!model.enabled ? 'disabled' : model.offlineDate ? 'offline ' + relativeTime(model.offlineDate) : 'online'}}</span>
306+
<button type="button" @click="checkStatus(model.name)" class="ml-2 rounded-full bg-white px-2.5 py-1 text-xs font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" :disabled="checking">{{checking ? 'checking...' : 'check status'}}</button>
307+
</div>
308+
</div>
301309
<div class="pl-6">
302310
<SelectModels
303311
v-if="formModel"
@@ -324,6 +332,8 @@ export default {
324332
const selectedModels = ref([])
325333
const providerTypes = ref({})
326334
const formModel = computed(() => (grid.value?.createForm ?? grid.value?.editForm)?.model)
335+
const checking = ref(false)
336+
const { formatDate, relativeTime } = useFormatters()
327337

328338
onMounted(async () => {
329339
const api = await client.api(new QueryMediaTypes())
@@ -353,6 +363,18 @@ export default {
353363
}
354364
}
355365

366+
async function checkStatus(provider) {
367+
checking.value = true
368+
const api = await client.api(new CheckMediaProviderStatus({ provider }))
369+
if (api.response) {
370+
grid.value?.setEdit({
371+
offlineDate: api.response.result ? null : new Date(),
372+
})
373+
grid.value?.update()
374+
}
375+
checking.value = false
376+
}
377+
356378
watch(() => providerType.value, () => {
357379
if (!providerTypes.value[providerType.value]) return
358380
let providerTypeDefaults = providerTypes.value[providerType.value]
@@ -377,7 +399,8 @@ export default {
377399

378400
return {
379401
grid, apiTypes, providerTypes, providerType, providerModels, formModel, selectedModels,
380-
allProviderModels, updateSelected, onNav
402+
allProviderModels, updateSelected, onNav,
403+
checkStatus, checking,
381404
}
382405
}
383406
}

0 commit comments

Comments
 (0)