Compare commits
45 Commits
993a1dd373
...
main
Author | SHA1 | Date | |
---|---|---|---|
07e3fdbe87 | |||
f17b08a586 | |||
0377feebca | |||
43538ba58f | |||
a62a71fc6f | |||
660ed02870 | |||
d7b258c8e7
|
|||
06035326e3
|
|||
33c29ea1af
|
|||
beda276909
|
|||
660f95b8a5 | |||
22068e46d5 | |||
4f9a4a3f47 | |||
a77526cfb3 | |||
552abfe6d8 | |||
79a76f850a | |||
4fd5b9ca6a | |||
729223f262 | |||
f76e30020a | |||
4fd1493c02 | |||
85cef58653
|
|||
6e4ac477dc | |||
bf64021798 | |||
47866713b0 | |||
9c8ac3faf3 | |||
6adc6adf66
|
|||
1dceac0e1b | |||
1dcd745185 | |||
0c72e12ceb | |||
f8443638bc | |||
7b8376cd26 | |||
445083d613 | |||
8617190dd9 | |||
641ed35a2a | |||
345ddeeabb | |||
b80a4c4ee8 | |||
27665b8436
|
|||
0cc19bf98d
|
|||
98f1461706 | |||
1f36575f1f | |||
9301d2bccd | |||
d10a0e5f41 | |||
17de2c7214 | |||
1629ad451f | |||
f70f3ab8ac |
@ -1,28 +1,34 @@
|
|||||||
name: Build and publish the docker image
|
name: docker
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["custom"]
|
branches:
|
||||||
|
- "main"
|
||||||
|
paths-ignore:
|
||||||
|
- "README.md"
|
||||||
|
- "LICENSE.txt"
|
||||||
|
- "docker-compose.example.yml"
|
||||||
|
- "ups.json"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.ngn.tf
|
REGISTRY: git.ngn.tf
|
||||||
IMAGE: ${{gitea.repository}}
|
IMAGE: ${{gitea.repository}}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: "https://github.com/actions/checkout@v4"
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Login to container repo
|
- name: Login to container repo
|
||||||
uses: "https://github.com/docker/login-action@v1"
|
uses: docker/login-action@v1
|
||||||
with:
|
with:
|
||||||
registry: ${{env.REGISTRY}}
|
registry: ${{env.REGISTRY}}
|
||||||
username: ${{gitea.actor}}
|
username: ${{gitea.actor}}
|
||||||
password: ${{secrets.PACKAGES_TOKEN}}
|
password: ${{secrets.PACKAGES_TOKEN}}
|
||||||
|
|
||||||
- name: Build image
|
- name: Build docker image
|
||||||
run: |
|
run: |
|
||||||
docker build . --tag ${{env.REGISTRY}}/${{env.IMAGE}}:latest
|
docker build . --tag ${{env.REGISTRY}}/${{env.IMAGE}}:latest
|
||||||
docker push ${{env.REGISTRY}}/${{env.IMAGE}}:latest
|
docker push ${{env.REGISTRY}}/${{env.IMAGE}}:latest
|
25
.gitea/workflows/ups.yml
Normal file
25
.gitea/workflows/ups.yml
Normal 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
|
592
Cargo.lock
generated
592
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@ version = "0.1.0"
|
|||||||
actix-http = "3.0.4"
|
actix-http = "3.0.4"
|
||||||
actix-rt = "2"
|
actix-rt = "2"
|
||||||
actix-web = "4.0.1"
|
actix-web = "4.0.1"
|
||||||
|
actix-files = "0.6.6"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
config = "0.13"
|
config = "0.13"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# [ngn.tf] | libmedium
|
# libmedium - proxy for medium.com
|
||||||
|
|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
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.
|
||||||
|
20
src/data.rs
20
src/data.rs
@ -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) {
|
match self.posts.get(id) {
|
||||||
Ok(Some(v)) => {
|
Ok(Some(v)) => {
|
||||||
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
|
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
|
||||||
PostUrl {
|
Some(PostUrl {
|
||||||
slug: cached.unique_slug,
|
slug: cached.unique_slug,
|
||||||
username: cached.creator.username,
|
username: cached.creator.username,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let vars = get_post_light::Variables { id: id.to_owned() };
|
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)
|
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = res.data.expect("missing response data").post.unwrap();
|
if res.data.is_none() {
|
||||||
PostUrl {
|
None
|
||||||
slug: res.unique_slug,
|
} else {
|
||||||
username: res.creator.username,
|
match res.data.expect("missing response data").post {
|
||||||
|
None => None,
|
||||||
|
Some(res) => Some(PostUrl {
|
||||||
|
slug: res.unique_slug,
|
||||||
|
username: res.creator.username,
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
src/proxy.rs
38
src/proxy.rs
@ -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")]
|
#[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 {
|
async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
|
||||||
let post_data = data.get_post_light(&path).await;
|
match data.get_post_light(&path).await {
|
||||||
HttpResponse::Found()
|
None => HttpResponse::NotFound().body("Post not found"),
|
||||||
.append_header((
|
Some(post_data) => HttpResponse::Found()
|
||||||
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()
|
|
||||||
.append_header((
|
.append_header((
|
||||||
header::LOCATION,
|
header::LOCATION,
|
||||||
crate::V1_API_ROUTES
|
crate::V1_API_ROUTES
|
||||||
.proxy
|
.proxy
|
||||||
.get_page(&post_data.username, &post_data.slug),
|
.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 {
|
} else {
|
||||||
HttpResponse::NotFound().body("Post not found, please file bug report")
|
HttpResponse::NotFound().body("Post not found, please file bug report")
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ impl Settings {
|
|||||||
if let Ok(path) = env::var("LIBMEDIUM") {
|
if let Ok(path) = env::var("LIBMEDIUM") {
|
||||||
s = s.add_source(File::with_name(&path));
|
s = s.add_source(File::with_name(&path));
|
||||||
} else if Path::new("./config.toml").exists() {
|
} else if Path::new("./config.toml").exists() {
|
||||||
s = s.add_source(File::with_name("./config.toml");
|
s = s.add_source(File::with_name("./config.toml"));
|
||||||
} else {
|
} else {
|
||||||
log::warn!("configuration file not found");
|
log::warn!("configuration file not found");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user