mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-04-20 03:40:00 -05:00
Compare commits
No commits in common. "2594051a54c507ed6770a35b024f4be052f5fb39" and "d48b664c0a04a25f6505a57ad550c0091b641136" have entirely different histories.
2594051a54
...
d48b664c0a
5 changed files with 8 additions and 44 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,4 +8,4 @@ urls.sqlite
|
|||
.vscode/
|
||||
**/.directory
|
||||
.env
|
||||
cookie*
|
||||
|
||||
|
|
32
README.md
32
README.md
|
@ -122,38 +122,6 @@ default, the auto-generated links are adjective-name pairs. You can use UIDs by
|
|||
the `slug_style` variable to `UID`. You can also set the length of those slug by setting
|
||||
the `slug_length` variable. It defaults to 8, and a minimum of 4 is supported.
|
||||
|
||||
## CLI usage instructions
|
||||
The application can be used from the terminal using something like `curl`. In all the examples
|
||||
below, replace `http://localhost:4567` with where your instance of `chhoto-url` is accessible.
|
||||
|
||||
If you have set up
|
||||
a password, first do the following to get an authentication cookie and store it in a file.
|
||||
```bash
|
||||
curl -X post -d "<your-password>" -c cookie.txt http://localhost:4567/api/login
|
||||
```
|
||||
You should receive "Correct password!" in case the provided password was correct. For any other
|
||||
request, please add `-b cookie.txt` to use this authentication cookie.
|
||||
|
||||
To add a link, do
|
||||
```bash
|
||||
curl -X POST -d '{"shhortlink":"<shortlink>", "longlink":<longlink>}' http://localhost:4567/api/new
|
||||
```
|
||||
Send an empty `<shortlink>` if you want it to be auto-generated. The server will reply with the generated shortlink.
|
||||
|
||||
To get a list of all the currently available links as `json`, do
|
||||
```bash
|
||||
curl http://localhost:4567/api/all
|
||||
```
|
||||
|
||||
To delete a link, do
|
||||
```bash
|
||||
curl -X DELETE http://localhost:4567/api/del/<shortlink>
|
||||
```
|
||||
The server will send a confirmation.
|
||||
|
||||
You can get the version of `chhoto-url` the server is running using `curl http://localhost:4567/api/version` and
|
||||
get the siteurl using `curl http://localhost:4567/api/siteurl`.
|
||||
|
||||
## Disable authentication
|
||||
If you do not define a password environment variable when starting the docker image, authentication
|
||||
will be disabled.
|
||||
|
|
2
actix/Cargo.lock
generated
2
actix/Cargo.lock
generated
|
@ -475,7 +475,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "chhoto-url"
|
||||
version = "5.2.2"
|
||||
version = "5.2.1"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-session",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "chhoto-url"
|
||||
version = "5.2.2"
|
||||
version = "5.2.1"
|
||||
edition = "2021"
|
||||
authors = ["Sayantan Santra <sayantan[dot]santra689[at]gmail[dot]com"]
|
||||
license = "mit"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use std::env;
|
||||
|
||||
use crate::database;
|
||||
use nanoid::nanoid;
|
||||
use rand::seq::SliceRandom;
|
||||
use regex::Regex;
|
||||
use rusqlite::Connection;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
|
||||
use crate::database;
|
||||
|
||||
#[derive(Deserialize, Default, PartialEq)]
|
||||
#[derive(Deserialize)]
|
||||
struct URLPair {
|
||||
shortlink: String,
|
||||
longlink: String,
|
||||
|
@ -32,11 +32,7 @@ pub fn getall(db: &Connection) -> String {
|
|||
}
|
||||
|
||||
pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||
let mut chunks: URLPair = serde_json::from_str(&req).unwrap_or_default();
|
||||
|
||||
if chunks == URLPair::default() {
|
||||
return (false, String::from("Invalid request!"));
|
||||
}
|
||||
let mut chunks: URLPair = serde_json::from_str(&req).unwrap();
|
||||
|
||||
let style = env::var("slug_style").unwrap_or(String::from("Pair"));
|
||||
let len_str = env::var("slug_length").unwrap_or(String::from("8"));
|
||||
|
|
Loading…
Reference in a new issue