2023-07-07 19:22:30 +00:00
|
|
|
<template>
|
2023-07-23 13:31:28 +00:00
|
|
|
<MkContainer
|
|
|
|
:naked="widgetProps.transparent"
|
|
|
|
:show-header="false"
|
|
|
|
class="mkw-instance-cloud"
|
|
|
|
>
|
|
|
|
<div class="">
|
|
|
|
<MkTagCloud v-if="activeInstances">
|
|
|
|
<li v-for="instance in activeInstances" :key="instance.id">
|
|
|
|
<a @click.prevent="onInstanceClick(instance)">
|
|
|
|
<img
|
|
|
|
style="width: 32px"
|
|
|
|
:src="getInstanceIcon(instance)"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</MkTagCloud>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2023-07-07 19:22:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import {} from "vue";
|
|
|
|
import {
|
2023-07-23 13:31:28 +00:00
|
|
|
useWidgetPropsManager,
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentProps,
|
2023-07-07 19:22:30 +00:00
|
|
|
} from "./widget";
|
|
|
|
import type { Widget, WidgetComponentExpose } from "./widget";
|
|
|
|
import type { GetFormResultType } from "@/scripts/form";
|
|
|
|
import MkContainer from "@/components/MkContainer.vue";
|
|
|
|
import MkTagCloud from "@/components/MkTagCloud.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { useInterval } from "@/scripts/use-interval";
|
|
|
|
import { getProxiedImageUrlNullable } from "@/scripts/media-proxy";
|
|
|
|
|
|
|
|
const name = "instanceCloud";
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
2023-07-23 13:31:28 +00:00
|
|
|
transparent: {
|
|
|
|
type: "boolean" as const,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-07-07 19:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(
|
2023-07-23 13:31:28 +00:00
|
|
|
name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit
|
2023-07-07 19:22:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
let cloud = $ref<InstanceType<typeof MkTagCloud> | null>();
|
|
|
|
let activeInstances = $shallowRef(null);
|
|
|
|
|
|
|
|
function onInstanceClick(i) {
|
2023-07-23 13:31:28 +00:00
|
|
|
os.pageWindow(`/instance-info/${i.host}`);
|
2023-07-07 19:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
useInterval(
|
2023-07-23 13:31:28 +00:00
|
|
|
() => {
|
|
|
|
os.api("federation/instances", {
|
|
|
|
sort: "+lastCommunicatedAt",
|
|
|
|
limit: 25,
|
|
|
|
}).then((res) => {
|
|
|
|
activeInstances = res;
|
|
|
|
if (cloud) cloud.update();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
1000 * 60 * 3,
|
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
|
|
|
}
|
2023-07-07 19:22:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function getInstanceIcon(instance): string {
|
2023-07-23 13:31:28 +00:00
|
|
|
return (
|
|
|
|
getProxiedImageUrlNullable(instance.iconUrl, "preview") ??
|
|
|
|
getProxiedImageUrlNullable(instance.faviconUrl, "preview") ??
|
|
|
|
"/client-assets/dummy.png"
|
|
|
|
);
|
2023-07-07 19:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
2023-07-23 13:31:28 +00:00
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2023-07-07 19:22:30 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped></style>
|