2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-06-29 14:28:52 +00:00
|
|
|
<template>
|
2023-05-19 07:20:53 +00:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :showHeader="false" class="mkw-instance-cloud">
|
2022-06-29 14:28:52 +00:00
|
|
|
<div class="">
|
|
|
|
<MkTagCloud v-if="activeInstances">
|
2022-07-07 11:19:50 +00:00
|
|
|
<li v-for="instance in activeInstances" :key="instance.id">
|
2022-06-29 14:28:52 +00:00
|
|
|
<a @click.prevent="onInstanceClick(instance)">
|
2022-12-08 08:33:04 +00:00
|
|
|
<img style="width: 32px;" :src="getInstanceIcon(instance)">
|
2022-06-29 14:28:52 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</MkTagCloud>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2023-09-29 02:22:59 +00:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2022-09-06 09:21:49 +00:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-08-30 15:24:33 +00:00
|
|
|
import MkTagCloud from '@/components/MkTagCloud.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { useInterval } from '@/scripts/use-interval.js';
|
|
|
|
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js';
|
2022-06-29 14:28:52 +00:00
|
|
|
|
|
|
|
const name = 'instanceCloud';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 07:20:53 +00:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-06-29 14:28:52 +00:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-01-03 04:37:32 +00:00
|
|
|
let cloud = $shallowRef<InstanceType<typeof MkTagCloud> | null>();
|
2022-06-29 14:28:52 +00:00
|
|
|
let activeInstances = $shallowRef(null);
|
|
|
|
|
|
|
|
function onInstanceClick(i) {
|
|
|
|
os.pageWindow(`/instance-info/${i.host}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
useInterval(() => {
|
|
|
|
os.api('federation/instances', {
|
2023-01-03 00:00:42 +00:00
|
|
|
sort: '+latestRequestReceivedAt',
|
2022-06-29 14:28:52 +00:00
|
|
|
limit: 25,
|
|
|
|
}).then(res => {
|
|
|
|
activeInstances = res;
|
|
|
|
if (cloud) cloud.update();
|
|
|
|
});
|
|
|
|
}, 1000 * 60 * 3, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
2022-12-08 08:33:04 +00:00
|
|
|
function getInstanceIcon(instance): string {
|
|
|
|
return getProxiedImageUrlNullable(instance.iconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? '/client-assets/dummy.png';
|
|
|
|
}
|
|
|
|
|
2022-06-29 14:28:52 +00:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
|
|
|
});
|
|
|
|
</script>
|