From 8391baa8daae99efdf346343253a0972adc6aea8 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:06:18 +0800 Subject: [PATCH 1/9] add random relay by ChatGPT --- Cargo.toml | 1 + src/update.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f7b5bf2..13872cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ rusqlite = { version = "0.30", features = ["bundled"] } serde = { version = "1", features = ["derive"] } threadpool = "1" toml = "0.8" +rand = "0.8" [dependencies.log4rs] version = "1" diff --git a/src/update.rs b/src/update.rs index cae83f3..5e5ef92 100644 --- a/src/update.rs +++ b/src/update.rs @@ -17,6 +17,10 @@ pub fn update(feed: &Feed) { let connection = sqlite::open(); loop { + // 随机延迟0到60秒 + let sleep_time = thread_rng().gen_range(0..60); + std::thread::sleep(Duration::from_secs(sleep_time)); + let url = &feed.url; let rss = Rss::new(url); From 181d1a4c16f7b2274474ae30a035ce09681926a1 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:08:19 +0800 Subject: [PATCH 2/9] increase relay limit to 600 secs. --- src/update.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/update.rs b/src/update.rs index 5e5ef92..d97aeaa 100644 --- a/src/update.rs +++ b/src/update.rs @@ -17,10 +17,10 @@ pub fn update(feed: &Feed) { let connection = sqlite::open(); loop { - // 随机延迟0到60秒 - let sleep_time = thread_rng().gen_range(0..60); + // 随机延迟0到600秒 + let sleep_time = thread_rng().gen_range(0..600); std::thread::sleep(Duration::from_secs(sleep_time)); - + let url = &feed.url; let rss = Rss::new(url); From 772522a58acda3fb951e5581ead36c7b2e6fe996 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:14:09 +0800 Subject: [PATCH 3/9] debug --- src/update.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/update.rs b/src/update.rs index d97aeaa..9508de5 100644 --- a/src/update.rs +++ b/src/update.rs @@ -13,6 +13,9 @@ use crate::{ writer, }; +use std::time::Duration; +use rand::{thread_rng, Rng}; + pub fn update(feed: &Feed) { let connection = sqlite::open(); From 08dd44ef1ce0921f9192a3ed448a7a4d300886c8 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:21:28 +0800 Subject: [PATCH 4/9] modify dockerfile for amd64 --- Dockerfile | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index c047f28..47431da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,29 @@ FROM rust:alpine as builder -RUN apk add -qq --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community musl-dev libc6-compat openssl-dev sqlite-dev tzdata - WORKDIR /app - COPY . . - -RUN RUSTFLAGS="-C target-cpu=native" cargo build --release -q +RUN RUSTFLAGS="-C target-cpu=native" cargo build --release FROM alpine:latest +LABEL org.opencontainers.image.source = "https://github.com/Felix2yu/docker_build" \ + maintainer="Felix2yu " \ + org.opencontainers.image.authors="Felix2yu "\ + org.opencontainers.image.authors2="ArenaDruid" WORKDIR /app COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime COPY --from=builder /app/target/release/bilibili-webhook /usr/local/bin/ -COPY log.yml . +COPY --from=builder /app/log.yml . -RUN apk add -qq --update --no-cache --virtual .build-deps gcc g++ python3-dev libc-dev libffi-dev && \ - apk add -qq --update --no-cache ffmpeg python3 py3-pip sqlite-dev libc6-compat && \ +RUN apk add --update --no-cache --virtual .build-deps gcc g++ python3-dev libc-dev libffi-dev && \ + apk add --update --no-cache ffmpeg python3 py3-pip sqlite-dev libc6-compat && \ pip3 install --no-cache-dir yutto --pre --break-system-packages && \ - apk del --purge .build-deps - -RUN addgroup -g 1000 pi && adduser -D -s /bin/sh -u 1000 -G pi pi && chown -R pi:pi . + apk del --purge .build-deps sqlite-dev && \ + adduser -D -s /bin/sh -u 1000 -G users pi && chown -R pi:users . USER pi VOLUME ["/app/config", "/app/downloads"] -CMD bilibili-webhook +CMD ["bilibili-webhook"] \ No newline at end of file From a3cfccf66584e3b30a65a98a0c9c53d71d432169 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:24:24 +0800 Subject: [PATCH 5/9] debug --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 47431da..a20e679 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM rust:alpine as builder WORKDIR /app +RUN apk add musl-dev libc6-compat openssl-dev sqlite-dev tzdata COPY . . RUN RUSTFLAGS="-C target-cpu=native" cargo build --release From 9980d6194a9bd926542846dd1b6731668a2826c7 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:50:18 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile=E4=BB=A5?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E7=BC=96=E8=AF=91=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index a20e679..95cd49d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,30 @@ FROM rust:alpine as builder +RUN apk add -qq --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community musl-dev libc6-compat openssl-dev sqlite-dev tzdata + WORKDIR /app -RUN apk add musl-dev libc6-compat openssl-dev sqlite-dev tzdata + COPY . . -RUN RUSTFLAGS="-C target-cpu=native" cargo build --release + +RUN RUSTFLAGS="-C target-cpu=generic" cargo build --release -q FROM alpine:latest -LABEL org.opencontainers.image.source = "https://github.com/Felix2yu/docker_build" \ - maintainer="Felix2yu " \ - org.opencontainers.image.authors="Felix2yu "\ - org.opencontainers.image.authors2="ArenaDruid" WORKDIR /app COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime COPY --from=builder /app/target/release/bilibili-webhook /usr/local/bin/ -COPY --from=builder /app/log.yml . +COPY log.yml . -RUN apk add --update --no-cache --virtual .build-deps gcc g++ python3-dev libc-dev libffi-dev && \ - apk add --update --no-cache ffmpeg python3 py3-pip sqlite-dev libc6-compat && \ +RUN apk add -qq --update --no-cache --virtual .build-deps gcc g++ python3-dev libc-dev libffi-dev && \ + apk add -qq --update --no-cache ffmpeg python3 py3-pip sqlite-dev libc6-compat && \ pip3 install --no-cache-dir yutto --pre --break-system-packages && \ - apk del --purge .build-deps sqlite-dev && \ - adduser -D -s /bin/sh -u 1000 -G users pi && chown -R pi:users . + apk del --purge .build-deps + +RUN addgroup -g 1000 pi && adduser -D -s /bin/sh -u 1000 -G pi pi && chown -R pi:pi . USER pi VOLUME ["/app/config", "/app/downloads"] -CMD ["bilibili-webhook"] \ No newline at end of file +CMD bilibili-webhook \ No newline at end of file From 85702de31e7deadc603eeb0df81974dd32a009cd Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:58:00 +0800 Subject: [PATCH 7/9] Recover Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 95cd49d..901531c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /app COPY . . -RUN RUSTFLAGS="-C target-cpu=generic" cargo build --release -q +RUN RUSTFLAGS="-C target-cpu=native" cargo build --release -q FROM alpine:latest From 8a90489bf0349d9640d88fc4fe8b16821bda68d5 Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Thu, 18 Apr 2024 01:04:34 +0800 Subject: [PATCH 8/9] Recover Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 901531c..c047f28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,4 +27,4 @@ USER pi VOLUME ["/app/config", "/app/downloads"] -CMD bilibili-webhook \ No newline at end of file +CMD bilibili-webhook From 577c786cf65f500a9a11671662f3a31fa577b7ca Mon Sep 17 00:00:00 2001 From: ArenaDruid <95113209+ArenaDruid@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:09:20 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=87=AA=E8=A1=8C?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.toml.example | 3 +++ src/config.rs | 1 + src/update.rs | 7 +++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config.toml.example b/config.toml.example index bee3c06..a9dc046 100644 --- a/config.toml.example +++ b/config.toml.example @@ -13,6 +13,8 @@ option = "--no-danmaku --proxy=no" path = "bilibili/Gamker" # 是否更新,设为 false 即不更新 update = true +# 是否需要一个随机的延迟,设为false即无延迟 +delay = true [[feed]] url = "https://rsshub.app/bilibili/user/video/96639395" @@ -20,3 +22,4 @@ interval = 60 option = "--no-danmaku --proxy=no" path = "bilibili/Academia" update = false +delay = true diff --git a/src/config.rs b/src/config.rs index b97c5e7..31a2349 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,6 +14,7 @@ pub struct Feed { pub option: String, pub path: String, pub update: bool, + pub delay: bool, } impl Config { diff --git a/src/update.rs b/src/update.rs index 9508de5..722ed06 100644 --- a/src/update.rs +++ b/src/update.rs @@ -21,8 +21,11 @@ pub fn update(feed: &Feed) { loop { // 随机延迟0到600秒 - let sleep_time = thread_rng().gen_range(0..600); - std::thread::sleep(Duration::from_secs(sleep_time)); + let delay = &feed.delay; + if *delay == true { + let sleep_time = thread_rng().gen_range(0..600); + std::thread::sleep(Duration::from_secs(sleep_time)); + } let url = &feed.url;