Skip to content

Commit b163c34

Browse files
committed
put back youtube and spotify
1 parent cdb7d7f commit b163c34

1 file changed

Lines changed: 89 additions & 76 deletions

File tree

‎backend/firebase/functions/src/hashnode/scheduledNotionToHashNode.ts‎

Lines changed: 89 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@ import { createPublicationStory } from '../utilities/hashnode';
1010

1111
const topicId = 'hashnodeCreateFromNotion';
1212

13-
export const scheduledNotionToHashnode = functions.pubsub
14-
.schedule('every 5 minutes')
15-
.onRun(async () => {
16-
// Check to see if ther are scheduled pods
17-
console.log('Checking for scheduled pods');
18-
const scheduledRes = await queryPurrfectStreamHashnode(1);
19-
console.log('Scheduled Result:', JSON.stringify(scheduledRes));
20-
21-
if (scheduledRes?.results) {
22-
const needCloudinaryPods = scheduledRes?.results;
23-
console.log('Pods to add to pub/sub', JSON.stringify(needCloudinaryPods));
24-
25-
for (const pod of needCloudinaryPods) {
26-
await sendTopic(topicId, pod);
27-
}
13+
const scheduleCheck = async () => {
14+
// Check to see if ther are scheduled pods
15+
console.log('Checking for scheduled pods');
16+
const scheduledRes = await queryPurrfectStreamHashnode(1);
17+
console.log('Scheduled Result:', JSON.stringify(scheduledRes));
18+
19+
if (scheduledRes?.results) {
20+
const needCloudinaryPods = scheduledRes?.results;
21+
console.log('Pods to add to pub/sub', JSON.stringify(needCloudinaryPods));
22+
23+
for (const pod of needCloudinaryPods) {
24+
await sendTopic(topicId, pod);
2825
}
26+
}
2927

28+
for (const _type of ['post', 'tutorial']) {
3029
console.log('Checking for hashnode missing');
31-
const posts = await queryByHashnode('post', 1);
30+
const posts = await queryByHashnode(_type, 1);
3231
console.log('Posts:', JSON.stringify(posts));
3332

3433
if (posts?.results) {
@@ -39,7 +38,13 @@ export const scheduledNotionToHashnode = functions.pubsub
3938
await sendTopic(topicId, p);
4039
}
4140
}
41+
}
42+
};
4243

44+
export const scheduledNotionToHashnode = functions.pubsub
45+
.schedule('every 5 minutes')
46+
.onRun(async () => {
47+
await scheduleCheck();
4348
return true;
4449
});
4550

@@ -52,18 +57,73 @@ export const hashnodeToNotionPubSub = functions.pubsub
5257
console.log('page', page);
5358

5459
let input;
55-
switch (page._type) {
56-
case 'post':
57-
const post = await getNotionPageMarkdown({
58-
_type: page._type,
59-
slug: page?.properties?.slug?.url,
60-
preview: false,
61-
});
62-
63-
if (!post || !post.content) {
64-
break;
60+
if (page._type === 'podcast') {
61+
input = {
62+
title: page.title,
63+
subtitle: page.excerpt,
64+
slug: `${page._type}-${page.slug}`,
65+
contentMarkdown: `Original: https://codingcat.dev/${page._type}/${page.slug}
66+
67+
%[${page.properties.youtube.url}]
68+
69+
%[${page.properties.spotify.url}]
70+
`,
71+
coverImageURL: `https://media.codingcat.dev/image/upload/f_auto,c_limit,w_1920,q_auto/${page?.coverPhoto?.public_id}`,
72+
isRepublished: {
73+
originalArticleURL: `https://codingcat.dev/${page._type}/${page.slug}`,
74+
},
75+
tags: [
76+
{
77+
_id: '56744722958ef13879b950d3',
78+
name: 'podcast',
79+
slug: 'podcast',
80+
},
81+
{
82+
_id: '56744721958ef13879b94cad',
83+
name: 'JavaScript',
84+
slug: 'javascript',
85+
},
86+
{
87+
_id: '56744722958ef13879b94f1b',
88+
name: 'Web Development',
89+
slug: 'web-development',
90+
},
91+
{
92+
_id: '56744723958ef13879b955a9',
93+
name: 'Beginner Developers',
94+
slug: 'beginners',
95+
},
96+
],
97+
};
98+
} else {
99+
console.log(
100+
`Getting ${page._type}: ${page.id} markdown, with slug ${page?.properties?.slug?.url}`
101+
);
102+
const post = await getNotionPageMarkdown({
103+
_type: page._type,
104+
slug: page?.properties?.slug?.url,
105+
preview: false,
106+
});
107+
108+
console.log('Block Result', post);
109+
if (post && post?.content) {
110+
if (page?.properties?.spotify?.url) {
111+
post.content = `
112+
%[${page.properties.spotify.url}]
113+
114+
${post.content}`;
115+
}
116+
if (page?.properties?.youtube?.url) {
117+
post.content = `
118+
%[${page.properties.youtube.url}]
119+
120+
${post.content}`;
65121
}
122+
post.content = `
123+
Original: https://codingcat.dev/${page._type}/${page.slug}
66124
125+
${post.content}
126+
`;
67127
input = {
68128
title: page.title,
69129
subtitle: page.excerpt,
@@ -73,40 +133,6 @@ export const hashnodeToNotionPubSub = functions.pubsub
73133
isRepublished: {
74134
originalArticleURL: `https://codingcat.dev/${page._type}/${page.slug}`,
75135
},
76-
tags: [
77-
{
78-
_id: '56744721958ef13879b94cad',
79-
name: 'JavaScript',
80-
slug: 'javascript',
81-
},
82-
{
83-
_id: '56744722958ef13879b94f1b',
84-
name: 'Web Development',
85-
slug: 'web-development',
86-
},
87-
{
88-
_id: '56744723958ef13879b955a9',
89-
name: 'Beginner Developers',
90-
slug: 'beginners',
91-
},
92-
],
93-
};
94-
break;
95-
case 'podcast':
96-
input = {
97-
title: page.title,
98-
subtitle: page.excerpt,
99-
slug: `${page._type}-${page.slug}`,
100-
contentMarkdown: `Original: https://codingcat.dev/${page._type}/${page.slug}
101-
102-
%[${page.properties.youtube.url}]
103-
104-
%[${page.properties.spotify.url}]
105-
`,
106-
coverImageURL: `https://media.codingcat.dev/image/upload/f_auto,c_limit,w_1920,q_auto/${page?.coverPhoto?.public_id}`,
107-
isRepublished: {
108-
originalArticleURL: `https://codingcat.dev/${page._type}/${page.slug}`,
109-
},
110136
tags: [
111137
{
112138
_id: '56744722958ef13879b950d3',
@@ -130,9 +156,7 @@ export const hashnodeToNotionPubSub = functions.pubsub
130156
},
131157
],
132158
};
133-
break;
134-
default:
135-
break;
159+
}
136160
}
137161

138162
if (input) {
@@ -167,26 +191,15 @@ export const hashnodeToNotionPubSub = functions.pubsub
167191
return purrfectPagePatchRes;
168192
} else {
169193
console.log('No Data matched for article');
170-
return;
171194
}
195+
return;
172196
});
173197

174198
// Used for testing don't forget to remove for production
175199
export const httpNotionToHashnode = functions.https.onRequest(
176200
async (req, res) => {
177-
// Check to see if ther are scheduled pods
178-
console.log('Checking for scheduled pods');
179-
const scheduledRes = await queryPurrfectStreamHashnode(1);
180-
console.log('Scheduled Result:', JSON.stringify(scheduledRes));
181-
182-
if (scheduledRes?.results) {
183-
const needCloudinaryPods = scheduledRes?.results;
184-
console.log('Pods to add to pub/sub', JSON.stringify(needCloudinaryPods));
201+
await scheduleCheck();
185202

186-
for (const pod of needCloudinaryPods) {
187-
await sendTopic(topicId, pod);
188-
}
189-
}
190203
res.send({ msg: 'started' });
191204
}
192205
);

0 commit comments

Comments
 (0)