diff --git a/packages/nc-gui/components/dashboard/Sidebar/Feed.vue b/packages/nc-gui/components/dashboard/Sidebar/Feed.vue index 0e0bd3c14f..dc55ae51fc 100644 --- a/packages/nc-gui/components/dashboard/Sidebar/Feed.vue +++ b/packages/nc-gui/components/dashboard/Sidebar/Feed.vue @@ -7,25 +7,49 @@ const { navigateToFeed } = workspaceStore const { isFeedPageOpened } = storeToRefs(workspaceStore) +const { appInfo } = useGlobal() + const { loadFeed, socialFeed } = useProductFeed() const isNewFeedAvailable = ref(false) const checkNewFeed = async () => { - await loadFeed({ type: 'all', loadMore: false }) - if (!socialFeed.value.length) return + try { + await loadFeed({ type: 'all', loadMore: false }) + if (!socialFeed.value.length) return - const [latestFeed] = socialFeed.value - const lastFeedTime = localStorage.getItem('lastFeedPublishedTime') - const lastFeed = dayjs(lastFeedTime) + const [latestFeed] = socialFeed.value + const lastFeedTime = localStorage.getItem('lastFeedPublishedTime') + const lastFeed = dayjs(lastFeedTime) - if (!lastFeed.isValid() || dayjs(latestFeed['Published Time']).isAfter(lastFeed)) { - isNewFeedAvailable.value = true - localStorage.setItem('lastFeedPublishedTime', latestFeed['Published Time']) + if (!lastFeed.isValid() || dayjs(latestFeed['Published Time']).isAfter(lastFeed)) { + isNewFeedAvailable.value = true + localStorage.setItem('lastFeedPublishedTime', latestFeed['Published Time']) + } + } catch (error) { + console.error('Error while checking new feed', error) } } -onMounted(checkNewFeed) +const intervalId = ref() + +const checkFeedWithInterval = async () => { + await checkNewFeed() + intervalId.value = setTimeout(checkFeedWithInterval, 3 * 60 * 60 * 1000) +} + +onMounted(() => { + if (appInfo.value.feedEnabled) { + checkFeedWithInterval() + } +}) + +onUnmounted(() => { + if (intervalId.value) { + clearTimeout(intervalId.value) + intervalId.value = null + } +}) const gotoFeed = () => navigateToFeed() diff --git a/packages/nc-gui/composables/useProductFeed.ts b/packages/nc-gui/composables/useProductFeed.ts index 8c655ae989..fdd02ec1a7 100644 --- a/packages/nc-gui/composables/useProductFeed.ts +++ b/packages/nc-gui/composables/useProductFeed.ts @@ -5,8 +5,6 @@ export const useProductFeed = createSharedComposable(() => { const { $api } = useNuxtApp() - const { appInfo } = useGlobal() - const youtubeFeed = ref([]) const githubFeed = ref([]) @@ -19,8 +17,6 @@ export const useProductFeed = createSharedComposable(() => { social: false, }) - const newFeedCount = ref(0) - const loadFeed = async ({ loadMore, type }: { loadMore: boolean; type: 'youtube' | 'github' | 'all' }) => { try { let page = 1 @@ -73,42 +69,6 @@ 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 }) - if (typeof newFeeds === 'number') { - newFeedCount.value = newFeeds - } else if (typeof newFeeds === 'string') { - newFeedCount.value = 100 - } - } 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.value) clearTimeout(intervalId.value) - }) - return { isErrorOccurred, activeTab, diff --git a/packages/nocodb/src/controllers/utils.controller.ts b/packages/nocodb/src/controllers/utils.controller.ts index 694ac02161..c68b00f3f7 100644 --- a/packages/nocodb/src/controllers/utils.controller.ts +++ b/packages/nocodb/src/controllers/utils.controller.ts @@ -173,10 +173,4 @@ export class UtilsController { async feed(@Request() req: NcRequest) { return await this.utilsService.feed(req); } - - @UseGuards(PublicApiLimiterGuard) - @Get('/api/v2/new-feed') - async newFeed(@Request() req: NcRequest) { - return await this.utilsService.getLatestFeed(req); - } } diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index f78b33b8f9..5d236a25af 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -16015,33 +16015,6 @@ ] } }, - "/api/v2/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/v2/feed": { "get": { "summary": "Get Feed", diff --git a/packages/nocodb/src/services/utils.service.ts b/packages/nocodb/src/services/utils.service.ts index dcd6fa90e0..bb11381ec3 100644 --- a/packages/nocodb/src/services/utils.service.ts +++ b/packages/nocodb/src/services/utils.service.ts @@ -544,45 +544,4 @@ export class UtilsService { return response.data; } - - async getLatestFeed(req: NcRequest) { - const { last_published_at } = req.query as { - last_published_at: string; - }; - - if (!last_published_at) { - return 0; - } - - const utils = { - found: false, - page: 1, - missedItems: 0, - }; - const feed = await this.feed({ - query: { - type: 'all', - page: utils.page.toString(), - per_page: '100', - }, - } as unknown as NcRequest); - - if (!feed || !feed?.length) { - return 0; - } - - for (const item of feed) { - if (item['Published Time'] === last_published_at) { - utils.found = true; - break; - } - utils.missedItems++; - } - - if (utils.found) { - return utils.missedItems; - } - - return `${utils.missedItems}+`; - } }