Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 28de6aa

Browse files
committed
Add command-line option for the current fqdn
- Add missing error descriptions in the docs - chage allowed gateway methods to any in preparation for h2 ws - improve contrast in the light theme of the image viewer
1 parent b8c179f commit 28de6aa

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

docs/api_documentation.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ Fetch a shared image (usually screenshots) with metadata.
555555
- `file`: `string` - The file content, encoded with standard base64
556556
- `shared_at`: `Timestamp`
557557

558+
#### Errors
559+
560+
- `404` - The provided image does not exist or has expired
561+
558562
### `GET` `/image/<id>/raw`
559563

560564
Fetch a raw image
@@ -567,6 +571,10 @@ Fetch a raw image
567571

568572
The raw bytes of the image
569573

574+
#### Errors
575+
576+
- `404` - The provided image does not exist or has expired
577+
570578
### `GET` `/image/<id>/view`
571579

572580
View an image in a browser.
@@ -579,6 +587,10 @@ View an image in a browser.
579587

580588
Html page in the style of the AxolotlClient website to display an image, with embedding support.
581589

590+
#### Errors
591+
592+
- `404` - The provided image does not exist or has expired
593+
582594
### `GET` `/image/<id>/oembed?<format>`
583595

584596
Get oEmbed information for an image. See https://oembed.com.
@@ -602,9 +614,13 @@ Get oEmbed information for an image. See https://oembed.com.
602614
- `provider_name`: `string` - The oEmbed provider name, `AxolotlClient`
603615
- `provider_url`: `string` - The oEmbed provider url, `https://axolotlclient.com`
604616

617+
#### Errors
618+
619+
- `404` - The provided image does not exist or has expired
620+
605621
### `POST` `/image/<filename>` [Authenticated](#Errors)
606622

607-
Share an image
623+
Share an image in PNG format
608624

609625
#### Path Fields
610626

@@ -618,6 +634,11 @@ The image data, in raw bytes
618634

619635
The image id, in plain text.
620636

637+
#### Errors
638+
639+
- `400` - The png file is malformed
640+
- `413` - The image is over 8MiB in size
641+
621642
### `GET` `/hypixel` [Authenticated](#Errors)
622643

623644
Query cached values from the public hypixel API

src/endpoints/global_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl GlobalData {
6262
impl Clone for GlobalData {
6363
fn clone(&self) -> Self {
6464
Self {
65-
total_players: self.total_players.clone(),
66-
online_players: self.online_players.clone(),
65+
total_players: self.total_players,
66+
online_players: self.online_players,
6767
modrinth_data: self.modrinth_data.clone(),
6868
notes: self.notes.clone(),
6969
}

src/endpoints/image.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ pub async fn evict_expired(database: &PgPool) -> Result<(), TaskError> {
8787
Ok(())
8888
}
8989

90+
const PAGE_TEMPLATE: &str = include_str!("image_view.html");
91+
9092
pub async fn get_view(
91-
State(ApiState { database, .. }): State<ApiState>,
93+
State(ApiState { database, cl_args, .. }): State<ApiState>,
9294
Path(id): Path<Id>,
9395
) -> Result<Html<String>, ApiError> {
9496
let image = query!("SELECT filename, player, timestamp, file FROM images WHERE id = $1", id as _)
@@ -97,7 +99,17 @@ pub async fn get_view(
9799
.ok_or(StatusCode::NOT_FOUND)?;
98100

99101
let filename = String::from_utf8(image.filename).unwrap();
100-
let base_url = "https://api.axolotlclient.com/v1/";
102+
let base_url = match &cl_args.domain_name {
103+
Some(name) => {
104+
let n = name.to_owned();
105+
if !n.ends_with("/") {
106+
n + "/"
107+
} else {
108+
n
109+
}
110+
}
111+
None => "https://api.axolotlclient.com/v1/".to_owned(),
112+
};
101113
let image_url = base_url.to_string() + "image/" + &id.to_string();
102114

103115
let username = query!("SELECT username FROM players WHERE uuid = $1", image.player)
@@ -108,9 +120,9 @@ pub async fn get_view(
108120
let time = image.timestamp.and_utc().format("%Y/%m/%d %H:%M").to_string();
109121
let png = PngInfo::create(&Bytes::from(image.file.clone())).await.unwrap();
110122
Ok(Html(
111-
include_str!("image_view.html")
123+
PAGE_TEMPLATE
112124
.replace("{filename}", &filename)
113-
.replace("{image_data}", &("data:image/png;base64,".to_string() + &STANDARD_NO_PAD.encode(image.file)))
125+
.replace("{image_data}", (image_url.clone() + "/raw").as_str())
114126
.replace("{image_url}", &image_url)
115127
.replace("{image_width}", &png.width.to_string())
116128
.replace("{image_height}", &png.height.to_string())
@@ -144,7 +156,7 @@ impl OEmbed {
144156
OEmbed {
145157
version: "1.0",
146158
_type: "photo",
147-
title,
159+
title: title + " | AxolotlClient",
148160
url,
149161
width: png.width,
150162
height: png.height,
@@ -160,7 +172,7 @@ pub struct OEmbedQuery {
160172
}
161173

162174
pub async fn get_oembed(
163-
State(ApiState { database, .. }): State<ApiState>,
175+
State(ApiState { database, cl_args, .. }): State<ApiState>,
164176
Path(id): Path<Id>,
165177
Query(OEmbedQuery { format }): Query<OEmbedQuery>,
166178
) -> Result<Json<OEmbed>, ApiError> {
@@ -176,11 +188,19 @@ pub async fn get_oembed(
176188

177189
let filename = String::from_utf8(image.filename).unwrap();
178190

179-
let embed = OEmbed::create(
180-
filename,
181-
"https://api.axolotlclient.com/v1/image/".to_owned() + &id.to_string() + "/raw",
182-
png.unwrap(),
183-
);
191+
let base_url = match &cl_args.domain_name {
192+
Some(name) => {
193+
let n = name.to_owned();
194+
if !n.ends_with("/") {
195+
n + "/"
196+
} else {
197+
n
198+
}
199+
}
200+
None => "https://api.axolotlclient.com/v1/".to_owned(),
201+
};
202+
203+
let embed = OEmbed::create(filename, base_url + &id.to_string() + "/raw", png.unwrap());
184204
Ok(if format == "json" {
185205
Json(embed)
186206
} else {

src/endpoints/image_view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
--about-text: #2a2a2a;
6060
--switcher-color: invert(6%) sepia(1%) saturate(751%) hue-rotate(314deg)
6161
brightness(101%) contrast(71%);
62-
--bg-brightness: 0.8;
62+
--bg-brightness: 1;
6363
}
6464
:root {
6565
--default-transition: color 0.3s ease-in-out,

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::endpoints::user::{self, Activity};
33
use crate::endpoints::{account, brew_coffee, channel, get_authenticate, image, not_found};
44
use crate::gateway::gateway;
55
use axum::extract::DefaultBodyLimit;
6+
use axum::routing::any;
67
use axum::{routing::get, routing::post, serve, Router};
78
use clap::{Args, Parser};
89
use dashmap::DashMap;
@@ -35,6 +36,9 @@ pub struct ClArgs {
3536

3637
#[arg(long)]
3738
pub notes_file: Option<PathBuf>,
39+
40+
#[arg(long)]
41+
pub domain_name: Option<String>,
3842
}
3943

4044
#[derive(Args)]
@@ -112,7 +116,7 @@ async fn main() -> anyhow::Result<()> {
112116
let router = Router::new()
113117
.route("/global_data", get(global_data::get))
114118
.route("/authenticate", get(get_authenticate))
115-
.route("/gateway", get(gateway))
119+
.route("/gateway", any(gateway))
116120
.route("/user/:uuid", get(user::get).post(user::post))
117121
.route("/user/:uuid/images", get(user::get_images))
118122
.route("/channels", get(account::get_channels))

0 commit comments

Comments
 (0)