From 7d8f351aa5e26df49880b451a9c97d3201a12df2 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Wed, 2 Oct 2024 05:54:24 +0000 Subject: [PATCH] fix: update swagger apis --- .../nc-gui/components/dashboard/Sidebar.vue | 4 +- .../nc-gui/composables/useGlobal/types.ts | 1 + packages/nc-gui/composables/useProductFeed.ts | 63 +++++++--- packages/nocodb/src/schema/swagger.json | 108 ++++++++++++++++++ 4 files changed, 157 insertions(+), 19 deletions(-) diff --git a/packages/nc-gui/components/dashboard/Sidebar.vue b/packages/nc-gui/components/dashboard/Sidebar.vue index 84c30a176e..ade1ab43d3 100644 --- a/packages/nc-gui/components/dashboard/Sidebar.vue +++ b/packages/nc-gui/components/dashboard/Sidebar.vue @@ -5,7 +5,7 @@ const { isWorkspaceLoading } = storeToRefs(workspaceStore) const { isSharedBase } = storeToRefs(useBase()) -const { isMobileMode } = useGlobal() +const { isMobileMode, appInfo } = useGlobal() const treeViewDom = ref() @@ -60,7 +60,7 @@ onUnmounted(() => {
- + diff --git a/packages/nc-gui/composables/useGlobal/types.ts b/packages/nc-gui/composables/useGlobal/types.ts index ccc1141dff..3d34b48bb1 100644 --- a/packages/nc-gui/composables/useGlobal/types.ts +++ b/packages/nc-gui/composables/useGlobal/types.ts @@ -39,6 +39,7 @@ export interface AppInfo { samlAuthEnabled: boolean samlProviderName: string | null giftUrl: string + feedEnabled: boolean } export interface StoredState { diff --git a/packages/nc-gui/composables/useProductFeed.ts b/packages/nc-gui/composables/useProductFeed.ts index c5a62e1d3e..2c8ae4bd17 100644 --- a/packages/nc-gui/composables/useProductFeed.ts +++ b/packages/nc-gui/composables/useProductFeed.ts @@ -1,16 +1,12 @@ -import axios from 'axios' import type { ProductFeedItem } from '../lib/types' -const axiosInstance = axios.create({ - baseURL: 'https://nocodb.com/api/v1', - headers: { - 'Content-Type': 'application/json', - }, -}) - export const useProductFeed = createSharedComposable(() => { const activeTab = ref('recents') + const { $api } = useNuxtApp() + + const { appInfo } = useGlobal() + const youtubeFeed = ref([]) const githubFeed = ref([]) @@ -23,7 +19,9 @@ export const useProductFeed = createSharedComposable(() => { social: false, }) - const loadFeed = async ({ loadMore, type }: { loadMore: boolean; type: 'youtube' | 'github' | 'all' | 'twitter' }) => { + const newFeedCount = ref(0) + + const loadFeed = async ({ loadMore, type }: { loadMore: boolean; type: 'youtube' | 'github' | 'all' }) => { try { let page = 1 @@ -41,15 +39,13 @@ export const useProductFeed = createSharedComposable(() => { } } - const response = await axiosInstance.get('/social/feed', { - params: { - per_page: 10, - page, - type, - }, - }) + const response = await $api.utils.feed2({ page, per_page: 10, type }) + + if (type === 'all' && page === 1 && response.length) { + localStorage.setItem('last_published_at', response[0]['Published Time'] as string) + } - return response.data + return response } catch (error) { switch (type) { case 'youtube': @@ -67,6 +63,39 @@ export const useProductFeed = createSharedComposable(() => { } } + const checkForNewFeed = async () => { + const lastPublishedAt = localStorage.getItem('last_published_at') + + if (!lastPublishedAt) { + return + } + + try { + const newFeeds = await $api.utils.feed({ last_published_at: lastPublishedAt }) + + newFeedCount.value = newFeeds as unknown as number + } catch (error) { + console.error(error) + } + } + + const intervalId = ref() + + const checkFeedWithInterval = async () => { + await checkForNewFeed() + intervalId.value = setTimeout(checkFeedWithInterval, 3 * 60 * 60 * 1000) + } + + onMounted(() => { + if (appInfo.value.feedEnabled) { + checkFeedWithInterval() + } + }) + + onUnmounted(() => { + if (intervalId) clearTimeout(intervalId.value) + }) + return { isErrorOccurred, activeTab, diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index b2f08423e7..74911ce560 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -16015,6 +16015,114 @@ ] } }, + "/api/v1/new-feed": { + "get": { + "summary": "Get Feed", + "operationId": "utils-feed", + "parameters": [ + { + "schema": { + "type": "string" + }, + "name": "last_published_at", + "in": "query", + "required": false + } + ], + "responses": { + "200": { + "description": "OK" + }, + "400": { + "$ref": "#/components/responses/BadRequest" + } + }, + "tags": [ + "Utils" + ] + } + }, + "/api/v1/feed": { + "get": { + "summary": "Get Feed", + "operationId": "utils-feed", + "parameters": [ + { + "schema": { + "type": "string", + "enum": [ + "all", + "github", + "youtube" + ] + }, + "name": "type", + "in": "query", + "required": false + }, + { + "schema": { + "type": "number" + }, + "name": "per_page", + "in": "query", + "required": false + }, + { + "schema": { + "type": "number" + }, + "name": "page", + "in": "query", + "required": false + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "Id": { + "type": "string" + }, + "Description": { + "type": "string" + }, + "Tags": { + "type": "string" + }, + "Images": { + "type": "array", + "items": { + "type": "object" + } + }, + "Url": { + "type": "string" + }, + "Published Time": { + "type": "string" + } + } + } + } + } + } + }, + "400": { + "$ref": "#/components/responses/BadRequest" + } + }, + "tags": [ + "Utils" + ] + } + }, "/api/v1/aggregated-meta-info": { "parameters": [ {