2022-06-29 16:28:52 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02: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>
|
2022-06-29 16:28:52 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import {} from "vue";
|
|
|
|
import {
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentProps,
|
2023-07-17 00:32:32 +02:00
|
|
|
useWidgetPropsManager,
|
2023-04-08 02:01:42 +02: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";
|
2022-06-29 16:28:52 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const name = "instanceCloud";
|
2022-06-29 16:28:52 +02:00
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-06-29 16:28:52 +02:00
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
2023-07-17 00:32:32 +02:00
|
|
|
// const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
// const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
2022-06-29 16:28:52 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(
|
|
|
|
name,
|
2022-06-29 16:28:52 +02:00
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
2023-07-06 03:28:27 +02:00
|
|
|
emit,
|
2022-06-29 16:28:52 +02:00
|
|
|
);
|
|
|
|
|
2023-07-17 00:32:32 +02:00
|
|
|
const cloud = $ref<InstanceType<typeof MkTagCloud> | null>();
|
2022-06-29 16:28:52 +02:00
|
|
|
let activeInstances = $shallowRef(null);
|
|
|
|
|
|
|
|
function onInstanceClick(i) {
|
|
|
|
os.pageWindow(`/instance-info/${i.host}`);
|
|
|
|
}
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
useInterval(
|
|
|
|
() => {
|
|
|
|
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-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-06-29 16:28:52 +02:00
|
|
|
|
2023-02-10 23:46:08 +01:00
|
|
|
function getInstanceIcon(instance): string {
|
2023-04-08 02:01:42 +02:00
|
|
|
return (
|
|
|
|
getProxiedImageUrlNullable(instance.iconUrl, "preview") ??
|
|
|
|
getProxiedImageUrlNullable(instance.faviconUrl, "preview") ??
|
|
|
|
"/client-assets/dummy.png"
|
|
|
|
);
|
2023-02-10 23:46:08 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 16:28:52 +02:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<style lang="scss" scoped></style>
|