|
@@ -1,14 +1,22 @@
|
|
|
import html, { HTMLElement } from "node-html-parser";
|
|
|
import request from "request-promise-native";
|
|
|
-import { db } from "../../db";
|
|
|
import { Response } from "request";
|
|
|
import { INewsItem, IAggregator } from "./aggregator";
|
|
|
+import { getRepository } from "typeorm";
|
|
|
+import { AggroNewsItem } from "../../entity/AggroNewsItem";
|
|
|
|
|
|
const kissDiaryRoot = "https://com3d2.world/r18/notices.php";
|
|
|
+const FEED_NAME = "com3d2-world-notices";
|
|
|
|
|
|
async function aggregate() {
|
|
|
- let lastDiary = db.get("latestCom3D2WorldDiaryEntry").value() as number;
|
|
|
+ let repo = getRepository(AggroNewsItem);
|
|
|
|
|
|
+ let lastPost = await repo.findOne({
|
|
|
+ select: [ "newsId" ],
|
|
|
+ where: { feedName: FEED_NAME },
|
|
|
+ order: { newsId: "DESC" }
|
|
|
+ });
|
|
|
+
|
|
|
try {
|
|
|
let mainPageRes = await request(kissDiaryRoot, {resolveWithFullResponse: true}) as Response;
|
|
|
|
|
@@ -31,7 +39,7 @@ async function aggregate() {
|
|
|
}
|
|
|
|
|
|
let result : INewsItem[] = [];
|
|
|
- let latestEntry = lastDiary;
|
|
|
+ let latestEntry = lastPost.newsId;
|
|
|
|
|
|
for(let a of diaryEntries) {
|
|
|
if(!a.rawAttributes.id)
|
|
@@ -39,7 +47,7 @@ async function aggregate() {
|
|
|
|
|
|
let id = +a.rawAttributes.id;
|
|
|
|
|
|
- if(id <= lastDiary)
|
|
|
+ if(id <= lastPost.newsId)
|
|
|
continue;
|
|
|
|
|
|
if(id > latestEntry)
|
|
@@ -63,7 +71,8 @@ async function aggregate() {
|
|
|
let contents = node.querySelectorAll("div.frame div")[1];
|
|
|
|
|
|
result.push({
|
|
|
- id: `com3d2-world-notices-${id}`,
|
|
|
+ newsId: id,
|
|
|
+ feedId: FEED_NAME,
|
|
|
link: diaryLink,
|
|
|
title: title.text,
|
|
|
author: "com3d2.world",
|
|
@@ -71,8 +80,6 @@ async function aggregate() {
|
|
|
embedColor: 0xa39869
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- db.set("latestCom3D2WorldDiaryEntry", latestEntry).write();
|
|
|
return result;
|
|
|
} catch(err) {
|
|
|
return [];
|