-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(API): add vice indonesia api (#19)
* add vice indonesia api * add vice to documentation list
- Loading branch information
Showing
6 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Response, Request } from 'express' | ||
import { parserRss } from '../../../utils/parser' | ||
import { RSS_VICE } from '../../../const' | ||
import { DataResponse } from '../../../types/common' | ||
|
||
interface Params { | ||
page?: string | ||
} | ||
|
||
const limitString = (str: string, limit: number):string => { | ||
const string: string = str | ||
const length: number = limit | ||
const result: string = string.length > length ? string.substring(0, length) + '....' : string; | ||
return result | ||
} | ||
|
||
class ViceNews { | ||
static async getAllNews(req: Request, res: Response) { | ||
try { | ||
const { page }: Partial<Params> = req.params | ||
const url = RSS_VICE.replace('{page}', `&page=${page}` ?? "") | ||
const result = await parserRss(url) | ||
const data = result.items.map((items) => { | ||
items.image = { | ||
small: items.enclosure.url | ||
} | ||
items.description = limitString(items.contentSnippet, 300) | ||
delete items.contentSnippet | ||
delete items.pubDate | ||
delete items.enclosure | ||
delete items.description | ||
delete items.guid | ||
delete items['content:encoded'] | ||
delete items['content:encodedSnippet'] | ||
delete items['dc:creator'] | ||
return items | ||
}) | ||
const dataResponse: DataResponse = { | ||
code: 200, | ||
status: "OK", | ||
messages: `Result of all news in Vice Indonesia`, | ||
total: data.length, | ||
data: data | ||
} | ||
return res.status(200).send(dataResponse) | ||
} catch (e) { | ||
return res.status(500).send({ | ||
message: `${e.message}` | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export default ViceNews |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a5ef51a
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.
Successfully deployed to the following URLs: