fix: return an error if image location was not provided by fxtwitter

This commit is contained in:
dusk 2024-06-11 00:12:11 +03:00
parent 642ae9acda
commit 5465c4a622
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
3 changed files with 66 additions and 8 deletions

View File

@ -38,6 +38,24 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1716715802, "lastModified": 1716715802,
@ -58,7 +76,29 @@
"inputs": { "inputs": {
"crane": "crane", "crane": "crane",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1717985971,
"narHash": "sha256-24h/qKp0aeI+Ew13WdRF521kY24PYa5HOvw0mlrABjk=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "abfe5b3126b1b7e9e4daafc1c6478d17f0b584e7",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
} }
}, },
"systems": { "systems": {
@ -75,6 +115,21 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -9,13 +9,18 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, crane, flake-utils, ... }: outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system}.appendOverlays [(import rust-overlay)];
craneLib = crane.mkLib pkgs; craneLib = crane.mkLib pkgs;
my-crate = craneLib.buildPackage { my-crate = craneLib.buildPackage {
src = craneLib.cleanCargoSource (craneLib.path ./.); src = craneLib.cleanCargoSource (craneLib.path ./.);
@ -39,9 +44,7 @@
packages = with pkgs; [ packages = with pkgs; [
cargo cargo
rustc (rust-bin.stable.latest.default.override {extensions = ["rust-src"];})
rust-analyzer
rustfmt
]; ];
}; };
}); });

View File

@ -128,12 +128,12 @@ async fn fetch_twitter_image_link(http: &reqwest::Client, url: &Uri) -> AppResul
.path_and_query(url.path_and_query().unwrap().clone()) .path_and_query(url.path_and_query().unwrap().clone())
.build()? .build()?
.to_string(); .to_string();
let req = http.get(fxurl).build()?; let req = http.get(&fxurl).build()?;
let resp = http.execute(req).await?.error_for_status()?; let resp = http.execute(req).await?.error_for_status()?;
let link = resp let link = resp
.headers() .headers()
.get(http::header::LOCATION) .get(http::header::LOCATION)
.unwrap() .ok_or_else(|| format!("twitter link {fxurl} did not return an image location"))?
.to_str()?; .to_str()?;
// use webp format for direct twitter links since webp is cheaper // use webp format for direct twitter links since webp is cheaper
Ok(format!("{link}?format=webp")) Ok(format!("{link}?format=webp"))