Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make QR code as short as possible #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/endpoints/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResp

if found {
// generate the QR code as an SVG - if its a file or text pastas, this will point to the /upload endpoint, otherwise to the /url endpoint, essentially directly taking the user to the url stored in the pasta
let svg: String = match pastas[index].pasta_type.as_str() {
"url" => misc::string_to_qr_svg(
format!("{}/url/{}", &ARGS.public_path_as_str(), &id).as_str(),
),
_ => misc::string_to_qr_svg(
format!("{}/upload/{}", &ARGS.public_path_as_str(), &id).as_str(),
),
};
let svg = misc::string_to_qr_svg(&match pastas[index].pasta_type.as_str() {
"url" => match ARGS.short_path.as_ref() {
Some(short) => format!("{short}/u/{id}"),
_ => format!("{}/url/{}", &ARGS.public_path_as_str(), &id),
},
_ => match ARGS.short_path.as_ref() {
Some(short) => format!("{short}/p/{id}"),
_ => format!("{}/upload/{}", &ARGS.public_path_as_str(), &id),
},
});

// serve qr code in template
return HttpResponse::Ok().content_type("text/html").body(
Expand Down