1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2025-04-19 19:30:01 -05:00

Compare commits

..

1 commit

Author SHA1 Message Date
SolninjaA
6b9b230d2a
Merge 9a0cdec646 into 756d675f06 2025-01-01 19:10:01 +10:00
3 changed files with 5 additions and 6 deletions

View file

@ -193,17 +193,17 @@ If the API key is insecure, a warning will be outputted along with a generated A
To add a link: To add a link:
``` bash ``` bash
curl -X POST -H "X-API-Key: <YOUR_API_KEY>" -d '{"shortlink":"<shortlink>", "longlink":"<longlink>"}' http://localhost:4567/api/new curl -X POST -H "Chhoto-Api-Key: <YOUR_API_KEY>" -d '{"shortlink":"<shortlink>", "longlink":"<longlink>"}' http://localhost:4567/api/new
``` ```
To get a list of all the currently available links: To get a list of all the currently available links:
``` bash ``` bash
curl -H "X-API-Key: <YOUR_API_KEY>" http://localhost:4567/api/all curl -H "Chhoto-Api-Key: <YOUR_API_KEY>" http://localhost:4567/api/all
``` ```
To delete a link: To delete a link:
``` bash ``` bash
curl -X DELETE -H "X-API-Key: <YOUR_API_KEY>" http://localhost:4567/api/del/<shortlink> curl -X DELETE -H "Chhoto-Api-Key: <YOUR_API_KEY>" http://localhost:4567/api/del/<shortlink>
``` ```
Where `<shortlink>` is name of the shortened link you would like to delete. For example, if the shortened link is `http://localhost:4567/example`, `<shortlink>` would be `example`. Where `<shortlink>` is name of the shortened link you would like to delete. For example, if the shortened link is `http://localhost:4567/example`, `<shortlink>` would be `example`.

View file

@ -42,7 +42,7 @@ pub fn gen_key() -> String {
// Check if the API key header exists // Check if the API key header exists
pub fn api_header(req: &HttpRequest) -> Option<&str> { pub fn api_header(req: &HttpRequest) -> Option<&str> {
req.headers().get("X-API-Key")?.to_str().ok() req.headers().get("Chhoto-Api-Key")?.to_str().ok()
} }
// Determine whether the inputted API key is sufficiently secure // Determine whether the inputted API key is sufficiently secure

View file

@ -41,8 +41,7 @@ pub fn is_api_ok(http: HttpRequest) -> Response {
// The header may not exist when the user logs in through the web interface, so allow a request with no header. // The header may not exist when the user logs in through the web interface, so allow a request with no header.
// Further authentication checks will be conducted in services.rs // Further authentication checks will be conducted in services.rs
} else { } else {
// Due to the implementation of this result in services.rs, this JSON object will not be outputted. Response { success: false, error: false, reason: "Chhoto-Api-Key header not found".to_string(), pass: true }
Response { success: false, error: false, reason: "X-API-Key header was not found".to_string(), pass: true }
} }
} else { } else {
// If the API key isn't set, but an API Key header is provided // If the API key isn't set, but an API Key header is provided