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