Skip to content

Commit

Permalink
Merge pull request #24 from exdevutem/patch/noticias
Browse files Browse the repository at this point in the history
patch: se repara endpoint de noticias
  • Loading branch information
exdevutembot authored May 10, 2024
2 parents 6592392 + 3b484ff commit ead7900
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PORT=3000
LOG_LEVEL=info

UTEM_URL="https://www.utem.cl"
NOTICIAS_UTEM_URL="https://noticias.utem.cl"
SSO_UTEM_URL="https://sso.utem.cl"
MI_UTEM_URL="https://mi.utem.cl"
PASAPORTE_UTEM_URL="https://pasaporte.utem.cl"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
yarn
yarn test
env:
NOTICIAS_UTEM_URL: ${{ vars.NOTICIAS_UTEM_URL || 'https://noticias.utem.cl' }}
UTEM_URL: ${{ vars.UTEM_URL || 'https://www.utem.cl' }}
SSO_UTEM_URL: ${{ vars.SSO_UTEM_URL || 'https://sso.utem.cl' }}
MI_UTEM_URL: ${{ vars.MI_UTEM_URL || 'https://mi.utem.cl' }}
Expand Down
12 changes: 0 additions & 12 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"readline": "^1.3.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"user-agents": "^1.1.127",
"uuid": "^9.0.1",
"winston": "^3.11.0"
},
Expand Down
18 changes: 16 additions & 2 deletions src/utem/services/utemNoticiasService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import axios from "axios";
import Noticia from "../models/noticia.model";
import * as cheerio from 'cheerio'
import {HashUtils} from "../../infrastructure/utils/hash.utils";
import {cache} from "../../app";
import randomUseragent from 'random-useragent';

export class UtemNoticiasService {
static async getNoticias(porPagina: number, desde: string, hasta: string){
const posts = await axios.get(`${process.env.UTEM_URL}/wp-json/wp/v2/posts?_embed&per_page=${porPagina}&before=${hasta}&after=${desde}`)
const cacheKey = HashUtils.sha512(`noticias:${porPagina}:${desde}:${hasta}`)
const cached = cache.get<Noticia[]>(cacheKey)
if(cached != undefined) {
return cached;
}

const posts = await axios.get(`${process.env.NOTICIAS_UTEM_URL}/wp-json/wp/v2/posts?_embed&per_page=${porPagina}&before=${hasta}&after=${desde}`, {
headers: {
'User-Agent': randomUseragent.getRandom(),
}
})
const noticias: Noticia[] = []

for (const post of posts.data) {
Expand All @@ -27,6 +40,7 @@ export class UtemNoticiasService {
noticias.push(noticia)
}

return noticias
cache.set(cacheKey, noticias, 900) // 15 minutos
return noticias;
}
}
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7887,7 +7887,6 @@ __metadata:
ts-jest: "npm:^29.1.2"
ts-node: "npm:^10.9.2"
typescript: "npm:^5.3.3"
user-agents: "npm:^1.1.127"
uuid: "npm:^9.0.1"
winston: "npm:^3.11.0"
languageName: unknown
Expand Down Expand Up @@ -10957,15 +10956,6 @@ __metadata:
languageName: node
linkType: hard

"user-agents@npm:^1.1.127":
version: 1.1.127
resolution: "user-agents@npm:1.1.127"
dependencies:
lodash.clonedeep: "npm:^4.5.0"
checksum: 10/630eed3c5df62b4b5a21e323548f0070e72cd5dc97cd94a9131b46e5e0957f059e879a6654fcd409d600fb9c83a80cd808a09b5d4f9b99c28a9a5db4f08fc0d2
languageName: node
linkType: hard

"util-deprecate@npm:^1.0.1, util-deprecate@npm:^1.0.2, util-deprecate@npm:~1.0.1":
version: 1.0.2
resolution: "util-deprecate@npm:1.0.2"
Expand Down

0 comments on commit ead7900

Please sign in to comment.