🏡 index : old_projects/url_shortener.git

author yaqubroli <walchuk2018@icloud.com> 2022-12-23 21:08:10.0 -08:00:00
committer yaqubroli <walchuk2018@icloud.com> 2022-12-23 21:08:10.0 -08:00:00
commit
07b474f9b7cbadb38d2ed0d1526ca1d89b5f2cf7 [patch]
tree
34c336c0728040cef2ec6c5e325e91575f9b4541
parent
6d2791a9a572e0f48b330d723bf9863ce3929550
download
07b474f9b7cbadb38d2ed0d1526ca1d89b5f2cf7.tar.gz

Added rm, added css, removed phantom setting



Diff

 README.MD             | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/settings.rs       |  1 -
 html/static/style.css | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/README.MD b/README.MD
new file mode 100644
index 0000000..91ca920 100644
--- /dev/null
+++ a/README.MD
@@ -1,0 +1,65 @@
# Unnamed combination URL shortener/pastebin

This is a combination URL shortener/pastebin written in Rust and [actix-web](https://github.com/actix/actix-web). It supports connecting to any mySQL server. It currently runs the landing page on https://7800.io/.

## Warning

I would not recommend using this in production. It was originally just a project to acquaint me with rust and actix-web. Large portions were written hastily with the help of Copilot, and thus, are probably not best-in-class when it comes to software design.

### Things I'd have to do to make this usable

* Proper error handling (for example, showing the user a "unable to access database" error through HTTP)
* Proper static 404 support
* Proper logging (instead of println!s placed while debugging that I forgot to remove)
* Remodeling the Count struct as an option

## Required files

### config.toml

A fully populated config.toml is required to run the server. The parameters that are default to actix-web are explained in the config.

The parameters specific to the url shortener are:

* [application.html] --- Things related to HTML and templating
    * **template** --- Whether to template at all or not
    * **template_index** --- Whether to template the index.html (/)
    * **template_static** --- Whether to template static html (this is sometimes needed as the submission form is often on a static page, as it is in this repo's example html)
    * **path** --- the path that html will be read from. Might want to make this /var/www/url_shortener, for instance.
    * **static_path** --- the subdirectory of **path** where static is stored. Unlike the above, this is actually displayed as part of the url.
    * **domain** --- The domain you're hosting from, used for templating
* [application.database] --- Things related to connecting to the mSQL database
    * **host**
    * **port** --- Usually 3306.
    * **username**
    * **password**
    * **database**

### HTML files

In your HTML directory, these files are required

* **index.html**
* **url.html** --- The page shown after a URL is submitted
* **paste.html** --- The page shown after a paste is submitted

## Forms

Submitting a URL/paste is done through a POST request.

Here are the fields necessary:

* **content** --- this is the URL to be shortened or the paste to be submitted
* **content_type** --- this is either `Pastebin` or `Url`, make this a hidden value on form

## Templating

This app has its own inbuilt templating engine. It's extremely simple; include these within your HTML and they will get replaced.

* `{content}` --- The original URL or the paste-text
* `{shortened}` --- The shortened suffix (yourdomain.com/*)
* `{domain}` --- Your domain, as set in the config.toml
* `{count:0}` --- The total number of URLs shortened
* `{count:1}` --- The total number of pastes submitted
* `{count:2}` --- The total number of all entries

diff --git a/src/settings.rs b/src/settings.rs
index 16b1473..1fdf9ef 100644
--- a/src/settings.rs
+++ a/src/settings.rs
@@ -21,7 +21,6 @@
    pub template: bool,
    pub template_index: bool,
    pub template_static: bool,
    pub count: bool,
    pub domain: String,
    pub path: String,
    pub static_path: String
diff --git a/html/static/style.css b/html/static/style.css
index 97a5ebf..1bc1035 100644
--- a/html/static/style.css
+++ a/html/static/style.css
@@ -133,4 +133,57 @@
    margin: 0 0.5em;
    /* make the buttons the same size */
    min-width: 5em;
}

@keyframes buttonRaise {
    0% {
        /* make the buttons look like they're being pressed when clicked */
        transform: translateY(0px);
        box-shadow: 0 0 0 0 rgb(60, 0, 0);
    }
    100% {
        transform: translateY(-2px);
        box-shadow: 0 4px 0 0 rgb(60, 0, 0);
    }
    
}

/* make the buttons look like they're being pressed when clicked */
#indexbuttonrow a:hover {
    animation-name: buttonRaise;
    animation-duration: 0.2s;
    animation-fill-mode: forwards;
}

#indexbuttonrow a:active {
    animation-name: buttonRaise;
    animation-duration: 0.2s;
    animation-fill-mode: forwards;
    animation-direction: reverse;
}

@keyframes buttonRaise_2 {
    0% {
        /* make the buttons look like they're being pressed when clicked */
        transform: translateY(0px);
        box-shadow: 0 0 0 0 rgb(183, 183, 183);
    }
    100% {
        transform: translateY(-2px);
        box-shadow: 0 4px 0 0 rgb(183, 183, 183);
    }
    
}

.button:hover {
    animation-name: buttonRaise_2;
    animation-duration: 0.2s;
    animation-fill-mode: forwards;
}

.button:active {
    animation-name: buttonRaise_2;
    animation-duration: 0.2s;
    animation-fill-mode: forwards;
    animation-direction: reverse;
}