mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-04-20 03:40:00 -05:00
Compare commits
3 commits
d48b664c0a
...
2594051a54
Author | SHA1 | Date | |
---|---|---|---|
2594051a54 | |||
38b817fdf8 | |||
a9168e3459 |
5 changed files with 44 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,4 +8,4 @@ urls.sqlite
|
||||||
.vscode/
|
.vscode/
|
||||||
**/.directory
|
**/.directory
|
||||||
.env
|
.env
|
||||||
|
cookie*
|
||||||
|
|
32
README.md
32
README.md
|
@ -122,6 +122,38 @@ 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_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.
|
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
|
## Disable authentication
|
||||||
If you do not define a password environment variable when starting the docker image, authentication
|
If you do not define a password environment variable when starting the docker image, authentication
|
||||||
will be disabled.
|
will be disabled.
|
||||||
|
|
2
actix/Cargo.lock
generated
2
actix/Cargo.lock
generated
|
@ -475,7 +475,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chhoto-url"
|
name = "chhoto-url"
|
||||||
version = "5.2.1"
|
version = "5.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-files",
|
"actix-files",
|
||||||
"actix-session",
|
"actix-session",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chhoto-url"
|
name = "chhoto-url"
|
||||||
version = "5.2.1"
|
version = "5.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Sayantan Santra <sayantan[dot]santra689[at]gmail[dot]com"]
|
authors = ["Sayantan Santra <sayantan[dot]santra689[at]gmail[dot]com"]
|
||||||
license = "mit"
|
license = "mit"
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use std::env;
|
|
||||||
|
|
||||||
use crate::database;
|
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
use crate::database;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default, PartialEq)]
|
||||||
struct URLPair {
|
struct URLPair {
|
||||||
shortlink: String,
|
shortlink: String,
|
||||||
longlink: String,
|
longlink: String,
|
||||||
|
@ -32,7 +32,11 @@ pub fn getall(db: &Connection) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||||
let mut chunks: URLPair = serde_json::from_str(&req).unwrap();
|
let mut chunks: URLPair = serde_json::from_str(&req).unwrap_or_default();
|
||||||
|
|
||||||
|
if chunks == URLPair::default() {
|
||||||
|
return (false, String::from("Invalid request!"));
|
||||||
|
}
|
||||||
|
|
||||||
let style = env::var("slug_style").unwrap_or(String::from("Pair"));
|
let style = env::var("slug_style").unwrap_or(String::from("Pair"));
|
||||||
let len_str = env::var("slug_length").unwrap_or(String::from("8"));
|
let len_str = env::var("slug_length").unwrap_or(String::from("8"));
|
||||||
|
|
Loading…
Reference in a new issue