fix: build error

This commit is contained in:
Hossein Mehrabi 2023-09-12 12:26:10 +03:30
parent aa4f024dea
commit 638a2cd686
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
2 changed files with 19 additions and 11 deletions

2
.env
View File

@ -2,5 +2,5 @@ UNBODY_API_KEY=
UNBODY_PROJECT_ID= UNBODY_PROJECT_ID=
SIMPLECAST_ACCESS_TOKEN= SIMPLECAST_ACCESS_TOKEN=
REVALIDATE_WEBHOOK_TOKEN= REVALIDATE_WEBHOOK_TOKEN=
DISCORD_LOGS_WEBHOOK_URL= DISCORD_WEBHOOK=
NEXT_PUBLIC_SITE_URL=https://press.logos.co NEXT_PUBLIC_SITE_URL=https://press.logos.co

View File

@ -33,16 +33,12 @@ const isBuildTime = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD
const isVercel = process.env.VERCEL === '1' const isVercel = process.env.VERCEL === '1'
const websiteUrl = getWebsiteUrl() const websiteUrl = getWebsiteUrl()
const discordWebhookURL = process.env.DISCORD_LOGS_WEBHOOK_URL || '' const discordWebhookURL = process.env.DISCORD_WEBHOOK || ''
const sendDiscordNotifications = const sendDiscordNotifications =
process.env.NODE_ENV === 'production' && process.env.NODE_ENV === 'production' &&
!!discordWebhookURL && !!discordWebhookURL &&
websiteUrl.includes('dev-') // temporary solution to avoid sending duplicate notification messages websiteUrl.includes('dev-') // temporary solution to avoid sending duplicate notification messages
const discordWebhook = new WebhookClient({
url: discordWebhookURL,
})
const articleDocument = unbodyDataTypes.get({ const articleDocument = unbodyDataTypes.get({
objectType: 'GoogleDoc', objectType: 'GoogleDoc',
classes: ['article', 'document'], classes: ['article', 'document'],
@ -214,15 +210,23 @@ export class UnbodyService {
newData.posts = [...newData.articles, ...newData.episodes] newData.posts = [...newData.articles, ...newData.episodes]
newData.allRecords = [...articles, ...episodes, ...staticPages] newData.allRecords = [...articles, ...episodes, ...staticPages]
if (!this.firstLoad && !isBuildTime && !isVercel) { const oldData = { ...this.data }
const changes = this.findChanges(this.data, newData)
if (sendDiscordNotifications)
settle(() => this.sendUpdatesToDiscord(changes))
}
this.data = newData this.data = newData
if (this.firstLoad) this.firstLoad = false if (this.firstLoad) this.firstLoad = false
callback(this.data) callback(this.data)
if (!this.firstLoad && !isBuildTime && !isVercel) {
const changes = this.findChanges(oldData, newData)
if (sendDiscordNotifications) {
const [_res, err] = await settle(() =>
this.sendUpdatesToDiscord(changes),
)
if (err) {
console.error(err)
}
}
}
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} finally { } finally {
@ -297,6 +301,10 @@ export class UnbodyService {
} }
sendUpdatesToDiscord = async (changes: PageRecordChange[]) => { sendUpdatesToDiscord = async (changes: PageRecordChange[]) => {
const discordWebhook = new WebhookClient({
url: discordWebhookURL,
})
const logs: string[] = [] const logs: string[] = []
const generateLog = async ( const generateLog = async (