8 Commits

Author SHA1 Message Date
a2a352efe0 Remove logs
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2023-04-26 19:48:59 +02:00
7647399159 Add timeout to fetching posts 2023-04-26 19:48:27 +02:00
1f4f8003f2 Fix path for real now
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-26 19:25:13 +02:00
e6ac97bd3e Fix wrong path
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-26 19:22:47 +02:00
79a385b9d4 Fix copy from builder
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-26 19:15:51 +02:00
2419f308fc add tsconfig to docker file
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-26 00:09:03 +02:00
ab073fe7ec Copy .yarn folder into docker container
Some checks failed
continuous-integration/drone/push Build is failing
2023-04-26 00:06:49 +02:00
f09b8c893d Move build step into Dockerfile and remove from drone 2023-04-26 00:06:01 +02:00
6 changed files with 109 additions and 16 deletions

View File

@ -3,12 +3,12 @@ type: docker
name: default
steps:
- name: Build with node
image: node:19
commands:
- yarn install
- yarn build
- name: Publish to docker
# - name: Build with node
# image: node:19
# commands:
# - yarn install
# - yarn build
- name: Build and publish to docker
image: plugins/docker
settings:
username:

View File

@ -3,9 +3,11 @@ FROM node:19 as builder
RUN mkdir -p /app
WORKDIR /app
COPY ["package.json", "yarn.lock", ".yarnrc.yml", "/app/"]
COPY ["package.json", "yarn.lock", ".yarnrc.yml", "tsconfig.json", "/app/"]
COPY [".yarn", "/app/.yarn"]
COPY ["src", "/app/src"]
RUN yarn install
RUN yarn build
@ -18,11 +20,12 @@ WORKDIR /app
ENV NODE_ENV=production
COPY ["package.json", "yarn.lock", ".yarnrc.yml", "/usr/src/app/"]
COPY ["package.json", "yarn.lock", ".yarnrc.yml", "/app/"]
COPY [".yarn", "/app/.yarn"]
RUN yarn install
COPY --from=builder lib/ /app/lib
COPY --from=builder /app/lib/ /app/lib
VOLUME [ "/app/logs", "/app/persist"]

View File

@ -1,6 +1,6 @@
{
"name": "rss-telegram-bot",
"version": "1.0.8",
"version": "2.0.0",
"main": "lib/index.js",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT",

View File

@ -41,7 +41,15 @@ function calculateHash(item: RSSFeedItem) {
async function checkFeed(feed: Feed) {
Logging.info("Fetching feed: %s", feed.url);
let data = await fetch(feed.url).then(res => res.text());
let timeoutSignal = new AbortController();
let to = setTimeout(() => {
Logging.warn("Feed %s fetch timed out", feed.url);
timeoutSignal.abort();
}, 10000);
let data = await fetch(feed.url, {
signal: timeoutSignal.signal
}).then(res => res.text());
clearTimeout(to);
Logging.info("Received Data");
Logging.debug(data);
@ -109,9 +117,14 @@ export default async function checkFeeds() {
continue;
}
await checkFeed(feed);
feed.lastCheck = new Date();
await AppDataSource.manager.save(feed);
Promise.resolve(async () => {
await checkFeed(feed);
}).catch(err => {
Logging.warn("Error while checking feed: %s", feed.url);
Logging.error(err);
})
}
}

78
src/import_old.ts Normal file
View File

@ -0,0 +1,78 @@
import { readFileSync } from "fs";
import { AppDataSource, appDataSourceReady } from "./data_source.js";
import { Feed } from "./models/Feed.js";
import { Post } from "./models/Post.js";
import { User } from "./models/User.js";
interface IOld {
feeds: {
url: string;
oldEntries: string[];
subscriber: number[];
}[];
}
appDataSourceReady.then(async () => {
let old = JSON.parse(readFileSync("./old.json", "utf-8")) as IOld;
for (let feed of old.feeds) {
let f = await AppDataSource.manager.findOne(Feed, {
where: {
url: feed.url
}
})
if (!f) {
f = AppDataSource.manager.create(Feed, {
url: feed.url,
lastCheck: new Date(0),
oldEntries: [],
subscriber: [],
})
await AppDataSource.manager.save(f);
}
for (let oldEntry of feed.oldEntries) {
let existing = await AppDataSource.manager.findOne(Post, {
where: {
feed: f,
hash: oldEntry
}
})
if (!existing) {
let post = AppDataSource.manager.create(Post, {
feed: f,
hash: oldEntry
})
await AppDataSource.manager.save(post);
}
}
for (let subscriber of feed.subscriber) {
let user = await AppDataSource.manager.findOne(User, {
where: {
chatid: subscriber
},
relations: {
feeds: true
}
});
if (!user) {
user = AppDataSource.manager.create(User, {
chatid: subscriber,
feeds: [f],
})
} else {
user.feeds.push(f)
}
await AppDataSource.manager.save(user);
}
}
})

View File

@ -62,8 +62,7 @@ bot.command("delete", botHandler(async ctx => {
}));
bot.on("callback_query", botHandler(async ctx => {
Logging.info("Callback Query:");
Logging.info(ctx.callbackQuery);
Logging.info("Callback Query received");
const remove_options = () => {
ctx.editMessageReplyMarkup({