8 Commits

Author SHA1 Message Date
2d859ce0a8 fix(deps): update rust crate bincode to v2
Some checks failed
renovate/artifacts Artifact file update failure
2025-05-13 02:01:43 +00:00
ngn
d7b258c8e7 ups: update to c715480 2025-05-12 23:00:56 +03:00
ngn
06035326e3 add the ups configuration
Signed-off-by: ngn <ngn@ngn.tf>
2025-05-12 22:42:29 +03:00
33c29ea1af update get_post_light to return none when no data is found, so not found error can happen 2025-05-12 22:37:58 +03:00
ngn
beda276909 add the ups workflow
Signed-off-by: ngn <ngn@ngn.tf>
2025-05-12 22:07:12 +03:00
ngn
660f95b8a5 Merge pull request 'fix(deps): update rust crate actix-rt to v2.10.0' (#9) from renovate/actix-rt-2.x-lockfile into custom
All checks were successful
Build and publish the docker image / build (push) Successful in 4m35s
Reviewed-on: #9
2025-02-12 19:50:28 +03:00
ngn
22068e46d5 Merge branch 'custom' into renovate/actix-rt-2.x-lockfile 2025-02-12 19:50:18 +03:00
98f1461706 fix(deps): update rust crate actix-rt to v2.10.0 2025-01-20 03:02:07 +00:00
8 changed files with 84 additions and 36 deletions

View File

@ -1,28 +1,34 @@
name: Build and publish the docker image
name: docker
on:
push:
branches: ["custom"]
branches:
- "main"
paths-ignore:
- "README.md"
- "LICENSE.txt"
- "docker-compose.example.yml"
- "ups.json"
env:
REGISTRY: git.ngn.tf
IMAGE: ${{gitea.repository}}
jobs:
build:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: "https://github.com/actions/checkout@v4"
uses: actions/checkout@v4
- name: Login to container repo
uses: "https://github.com/docker/login-action@v1"
uses: docker/login-action@v1
with:
registry: ${{env.REGISTRY}}
username: ${{gitea.actor}}
password: ${{secrets.PACKAGES_TOKEN}}
- name: Build image
- name: Build docker image
run: |
docker build . --tag ${{env.REGISTRY}}/${{env.IMAGE}}:latest
docker push ${{env.REGISTRY}}/${{env.IMAGE}}:latest

25
.gitea/workflows/ups.yml Normal file
View File

@ -0,0 +1,25 @@
name: ups
on:
schedule:
- cron: "@weekly"
jobs:
ups:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update -y
sudo apt install -y python3 python3-build python3-requests make
- name: Install ups
run: |
git clone https://git.ngn.tf/ngn/ups && cd ups
make && make install
- name: Run ups
run: PATH=~/.local/bin:$PATH ups-check

4
Cargo.lock generated
View File

@ -108,9 +108,9 @@ dependencies = [
[[package]]
name = "actix-rt"
version = "2.9.0"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28f32d40287d3f402ae0028a9d54bef51af15c8769492826a69d28f81893151d"
checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208"
dependencies = [
"actix-macros",
"futures-core",

View File

@ -15,7 +15,7 @@ actix-http = "3.0.4"
actix-rt = "2"
actix-web = "4.0.1"
actix-files = "0.6.6"
bincode = "1.3.3"
bincode = "2.0.0"
chrono = "0.4.23"
config = "0.13"
derive_more = "0.99"

View File

@ -1,5 +1,7 @@
# [ngn.tf] | libmedium
# libmedium - proxy for medium.com
![](https://git.ngn.tf/ngn/libmedium/actions/workflows/build.yml/badge.svg)
![](https://git.ngn.tf/ngn/libmedium/actions/workflows/docker.yml/badge.svg)
![](https://git.ngn.tf/ngn/libmedium/actions/workflows/ups.yml/badge.svg)
A fork of the [libmedium](https://github.com/realaravinth/libmedium) project, with my personal changes.
A fork of the [libmedium](https://github.com/realaravinth/libmedium) project,
with my personal changes.

View File

@ -164,14 +164,14 @@ impl Data {
}
}
pub async fn get_post_light(&self, id: &str) -> PostUrl {
pub async fn get_post_light(&self, id: &str) -> Option<PostUrl> {
match self.posts.get(id) {
Ok(Some(v)) => {
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
PostUrl {
Some(PostUrl {
slug: cached.unique_slug,
username: cached.creator.username,
}
})
}
_ => {
let vars = get_post_light::Variables { id: id.to_owned() };
@ -180,10 +180,16 @@ impl Data {
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
.await
.unwrap();
let res = res.data.expect("missing response data").post.unwrap();
PostUrl {
slug: res.unique_slug,
username: res.creator.username,
if res.data.is_none() {
None
} else {
match res.data.expect("missing response data").post {
None => None,
Some(res) => Some(PostUrl {
slug: res.unique_slug,
username: res.creator.username,
}),
}
}
}
}

View File

@ -158,29 +158,33 @@ async fn assets(path: web::Path<String>, data: AppData) -> impl Responder {
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.by_post_id")]
async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
let post_data = data.get_post_light(&path).await;
HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish()
}
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
if let Some(post_id) = path.split('-').last() {
let post_data = data.get_post_light(post_id).await;
HttpResponse::Found()
match data.get_post_light(&path).await {
None => HttpResponse::NotFound().body("Post not found"),
Some(post_data) => HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish()
.finish(),
}
}
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
if let Some(post_id) = path.split('-').last() {
match data.get_post_light(post_id).await {
None => HttpResponse::NotFound().body("Post not found"),
Some(post_data) => HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish(),
}
} else {
HttpResponse::NotFound().body("Post not found, please file bug report")
}

5
ups.json Normal file
View File

@ -0,0 +1,5 @@
{
"upstream": "https://git.batsense.net/realaravinth/libmedium",
"provider": "gitea",
"commit": "c7154807884e1bb8228a7682c5a3dee9becf5ac4"
}