Skip to content

Commit

Permalink
fix(backend): add detailed schema to fetch-rss endpoint (#13764)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyoshoka authored Apr 29, 2024
1 parent e2ff5f5 commit 2ff90a8
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 11 deletions.
179 changes: 177 additions & 2 deletions packages/backend/src/server/api/endpoints/fetch-rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,188 @@ export const meta = {
res: {
type: 'object',
properties: {
image: {
type: 'object',
optional: true,
properties: {
link: {
type: 'string',
optional: true,
},
url: {
type: 'string',
optional: false,
},
title: {
type: 'string',
optional: true,
},
},
},
paginationLinks: {
type: 'object',
optional: true,
properties: {
self: {
type: 'string',
optional: true,
},
first: {
type: 'string',
optional: true,
},
next: {
type: 'string',
optional: true,
},
last: {
type: 'string',
optional: true,
},
prev: {
type: 'string',
optional: true,
},
},
},
link: {
type: 'string',
optional: true,
},
title: {
type: 'string',
optional: true,
},
items: {
type: 'array',
optional: false,
items: {
type: 'object',
properties: {
link: {
type: 'string',
optional: true,
},
guid: {
type: 'string',
optional: true,
},
title: {
type: 'string',
optional: true,
},
pubDate: {
type: 'string',
optional: true,
},
creator: {
type: 'string',
optional: true,
},
summary: {
type: 'string',
optional: true,
},
content: {
type: 'string',
optional: true,
},
isoDate: {
type: 'string',
optional: true,
},
categories: {
type: 'array',
optional: true,
items: {
type: 'string',
},
},
contentSnippet: {
type: 'string',
optional: true,
},
enclosure: {
type: 'object',
optional: true,
properties: {
url: {
type: 'string',
optional: false,
},
length: {
type: 'number',
optional: true,
},
type: {
type: 'string',
optional: true,
},
},
},
},
},
},
feedUrl: {
type: 'string',
optional: true,
},
description: {
type: 'string',
optional: true,
},
itunes: {
type: 'object',
optional: true,
additionalProperties: true,
properties: {
image: {
type: 'string',
optional: true,
},
owner: {
type: 'object',
optional: true,
properties: {
name: {
type: 'string',
optional: true,
},
email: {
type: 'string',
optional: true,
},
},
},
author: {
type: 'string',
optional: true,
},
summary: {
type: 'string',
optional: true,
},
explicit: {
type: 'string',
optional: true,
},
categories: {
type: 'array',
optional: true,
items: {
type: 'string',
},
},
keywords: {
type: 'array',
optional: true,
items: {
type: 'string',
},
},
},
}
}
},
},
},
} as const;

Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/src/ui/_common_/statusbar-rss.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref } from 'vue';
import * as Misskey from 'misskey-js';
import MarqueeText from '@/components/MkMarquee.vue';
import { useInterval } from '@/scripts/use-interval.js';
import { shuffle } from '@/scripts/shuffle.js';
Expand All @@ -42,13 +43,13 @@ const props = defineProps<{
refreshIntervalSec?: number;
}>();

const items = ref([]);
const items = ref<Misskey.entities.FetchRssResponse['items']>([]);
const fetching = ref(true);
const key = ref(0);

const tick = () => {
window.fetch(`/api/fetch-rss?url=${props.url}`, {}).then(res => {
res.json().then(feed => {
res.json().then((feed: Misskey.entities.FetchRssResponse) => {
if (props.shuffle) {
shuffle(feed.items);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/src/widgets/WidgetRss.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref, watch, computed } from 'vue';
import * as Misskey from 'misskey-js';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import { GetFormResultType } from '@/scripts/form.js';
import MkContainer from '@/components/MkContainer.vue';
Expand Down Expand Up @@ -64,7 +65,7 @@ const { widgetProps, configure } = useWidgetPropsManager(name,
emit,
);

const rawItems = ref([]);
const rawItems = ref<Misskey.entities.FetchRssResponse['items']>([]);
const items = computed(() => rawItems.value.slice(0, widgetProps.maxEntries));
const fetching = ref(true);
const fetchEndpoint = computed(() => {
Expand All @@ -79,8 +80,8 @@ const tick = () => {

window.fetch(fetchEndpoint.value, {})
.then(res => res.json())
.then(feed => {
rawItems.value = feed.items ?? [];
.then((feed: Misskey.entities.FetchRssResponse) => {
rawItems.value = feed.items;
fetching.value = false;
});
};
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/src/widgets/WidgetRssTicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref, watch, computed } from 'vue';
import * as Misskey from 'misskey-js';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import MarqueeText from '@/components/MkMarquee.vue';
import { GetFormResultType } from '@/scripts/form.js';
Expand Down Expand Up @@ -87,7 +88,7 @@ const { widgetProps, configure } = useWidgetPropsManager(name,
emit,
);

const rawItems = ref([]);
const rawItems = ref<Misskey.entities.FetchRssResponse['items']>([]);
const items = computed(() => {
const newItems = rawItems.value.slice(0, widgetProps.maxEntries);
if (widgetProps.shuffle) {
Expand All @@ -110,8 +111,8 @@ const tick = () => {

window.fetch(fetchEndpoint.value, {})
.then(res => res.json())
.then(feed => {
rawItems.value = feed.items ?? [];
.then((feed: Misskey.entities.FetchRssResponse) => {
rawItems.value = feed.items;
fetching.value = false;
key.value++;
});
Expand Down
47 changes: 46 additions & 1 deletion packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26065,7 +26065,52 @@ export type operations = {
200: {
content: {
'application/json': {
items: Record<string, never>[];
image?: {
link?: string;
url: string;
title?: string;
};
paginationLinks?: {
self?: string;
first?: string;
next?: string;
last?: string;
prev?: string;
};
link?: string;
title?: string;
items: {
link?: string;
guid?: string;
title?: string;
pubDate?: string;
creator?: string;
summary?: string;
content?: string;
isoDate?: string;
categories?: string[];
contentSnippet?: string;
enclosure?: {
url: string;
length?: number;
type?: string;
};
}[];
feedUrl?: string;
description?: string;
itunes?: {
image?: string;
owner?: {
name?: string;
email?: string;
};
author?: string;
summary?: string;
explicit?: string;
categories?: string[];
keywords?: string[];
[key: string]: unknown;
};
};
};
};
Expand Down

0 comments on commit 2ff90a8

Please sign in to comment.