-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Tumblr integrations #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||
| const express = require('express'); | ||||||||||||||||||||||||||||||||||||||
| const router = express.Router(); | ||||||||||||||||||||||||||||||||||||||
| const axios = require('axios'); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| router.get('/', async (req, res, next) => { | ||||||||||||||||||||||||||||||||||||||
| // #swagger.tags = ['Logues'] | ||||||||||||||||||||||||||||||||||||||
| // #swagger.summary = 'returns dynamic content for the blog page' | ||||||||||||||||||||||||||||||||||||||
| // #swagger.description = '/api/v1/logues' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const CONSUMER_KEY = process.env.TUMBLR_CONSUMER_KEY; | ||||||||||||||||||||||||||||||||||||||
| const url = 'https://api.tumblr.com/v2/blog/hwakabh.tumblr.com/posts?api_key=' + CONSUMER_KEY; | ||||||||||||||||||||||||||||||||||||||
| const respPosts = await axios.get(url) | ||||||||||||||||||||||||||||||||||||||
| .then(response => { | ||||||||||||||||||||||||||||||||||||||
| return response.data.response.posts | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| .catch(error => { | ||||||||||||||||||||||||||||||||||||||
| console.log(error); | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const posts = []; | ||||||||||||||||||||||||||||||||||||||
| respPosts.forEach(p => { | ||||||||||||||||||||||||||||||||||||||
| posts.push({ | ||||||||||||||||||||||||||||||||||||||
| date: p.date, | ||||||||||||||||||||||||||||||||||||||
| body: p.body | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| console.log(posts); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove debug logging and add validation. The current implementation has production code issues:
Apply this diff: const posts = [];
- respPosts.forEach(p => {
- posts.push({
- date: p.date,
- body: p.body
- })
- });
-
- console.log(posts);
+ if (respPosts && Array.isArray(respPosts)) {
+ respPosts.forEach(p => {
+ posts.push({
+ date: p.date,
+ body: p.body
+ })
+ });
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| res.header('Content-Type', 'application/json; charset=utf-8'); | ||||||||||||||||||||||||||||||||||||||
| res.json({ | ||||||||||||||||||||||||||||||||||||||
| "path": req.originalUrl, | ||||||||||||||||||||||||||||||||||||||
| "content": posts | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add proper error handling for the entire route. The route needs comprehensive error handling to prevent crashes and provide meaningful responses to clients. Wrap the entire route logic in a try-catch block: router.get('/', async (req, res, next) => {
// #swagger.tags = ['Logues']
// #swagger.summary = 'returns dynamic content for the blog page'
// #swagger.description = '/api/v1/logues'
+ try {
const CONSUMER_KEY = process.env.TUMBLR_CONSUMER_KEY;
if (!CONSUMER_KEY) {
return res.status(500).json({ error: 'Tumblr API key not configured' });
}
const response = await axios.get('https://api.tumblr.com/v2/blog/hwakabh.tumblr.com/posts', {
params: { api_key: CONSUMER_KEY }
});
const respPosts = response.data.response.posts || [];
const posts = [];
if (respPosts && Array.isArray(respPosts)) {
respPosts.forEach(p => {
posts.push({
date: p.date,
body: p.body
})
});
}
res.header('Content-Type', 'application/json; charset=utf-8');
res.json({
"path": req.originalUrl,
"content": posts
});
+ } catch (error) {
+ console.error('Error fetching Tumblr posts:', error);
+ res.status(500).json({
+ error: 'Failed to fetch blog posts',
+ path: req.originalUrl
+ });
+ }
});
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| module.exports = router; | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,30 @@ | ||
| <template> | ||
| <section class="wrapper fullscreen"> | ||
| <div class="inner"> | ||
| <h1 class="major">Elements</h1> | ||
| <section> | ||
| <h2>Text</h2> | ||
| <p>This is <b>bold</b> and this is <strong>strong</strong>. This is <i>italic</i> and this is <em>emphasized</em>. | ||
| This is <sup>superscript</sup> text and this is <sub>subscript</sub> text. | ||
| This is <u>underlined</u> and this is code: <code>for (;;) { ... }</code>. Finally, <a href="#">this is a link</a>.</p> | ||
| <hr /> | ||
| <p>Nunc lacinia ante nunc ac lobortis. Interdum adipiscing gravida odio porttitor sem non mi integer non faucibus ornare mi ut ante amet placerat aliquet. Volutpat eu sed ante lacinia sapien lorem accumsan varius montes viverra nibh in adipiscing blandit tempus accumsan.</p> | ||
| <hr /> | ||
| <h2>Heading Level 2</h2> | ||
| <h3>Heading Level 3</h3> | ||
| <h4>Heading Level 4</h4> | ||
| <hr /> | ||
| <h3>Blockquote</h3> | ||
| <blockquote>Fringilla nisl. Donec accumsan interdum nisi, quis tincidunt felis sagittis eget tempus euismod. Vestibulum ante ipsum primis in faucibus vestibulum. Blandit adipiscing eu felis iaculis volutpat ac adipiscing accumsan faucibus. Vestibulum ante ipsum primis in faucibus lorem ipsum dolor sit amet nullam adipiscing eu felis.</blockquote> | ||
| <h3>Preformatted</h3> | ||
| <pre><code>i = 0; | ||
| <script setup> | ||
| import axios from "axios"; | ||
| import { ref } from "vue"; | ||
|
|
||
| while (!deck.isInOrder()) { | ||
| print 'Iteration ' + i; | ||
| deck.shuffle(); | ||
| i++; | ||
| } | ||
| const postData = ref([]); | ||
| axios.get('/api/v1/posts') | ||
| .then((resp) => { | ||
| postData.value = resp.data.content; | ||
| }) | ||
| .catch((err) => { | ||
| console.log(err); | ||
| }) | ||
|
|
||
| print 'It took ' + i + ' iterations to sort the deck.';</code></pre> | ||
| </section> | ||
| </script> | ||
|
|
||
| <!-- Lists --> | ||
| <section> | ||
| <h2>Lists</h2> | ||
| <div class="row"> | ||
| <div class="col-4 col-12-medium"> | ||
| <h3>Unordered</h3> | ||
| <ul> | ||
| <li>Dolor pulvinar etiam.</li> | ||
| <li>Sagittis adipiscing.</li> | ||
| <li>Felis enim feugiat.</li> | ||
| </ul> | ||
| </div> | ||
| <div class="col-4 col-12-medium"> | ||
| <h3>Alternate</h3> | ||
| <ul class="alt"> | ||
| <li>Dolor pulvinar etiam.</li> | ||
| <li>Sagittis adipiscing.</li> | ||
| <li>Felis enim feugiat.</li> | ||
| </ul> | ||
| </div> | ||
| <div class="col-4 col-12-medium"> | ||
| <h3>Ordered</h3> | ||
| <ol> | ||
| <li>Dolor pulvinar etiam.</li> | ||
| <li>Etiam vel felis viverra.</li> | ||
| <li>Felis enim feugiat.</li> | ||
| <li>Dolor pulvinar etiam.</li> | ||
| <li>Etiam vel felis lorem.</li> | ||
| <li>Felis enim et feugiat.</li> | ||
| </ol> | ||
| </div> | ||
| <template> | ||
| <section class="wrapper fullscreen"> | ||
| <div class="inner"> | ||
| <h1 class="major">Blogs</h1> | ||
| <div v-for="(p, idx) in postData" | ||
| :key="idx" | ||
| class="post-detail" | ||
| > | ||
| <div v-html="p.date"></div> | ||
| <div v-html="p.body"></div> | ||
| <hr /> | ||
| </div> | ||
| </section> | ||
|
|
||
| </div> | ||
| </section> | ||
| </template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling and API request structure.
Several issues with the current implementation:
respPostswill beundefined, causing a crash on line 21.Apply this diff to improve error handling and security:
🤖 Prompt for AI Agents