Compare commits

...

11 commits

Author SHA1 Message Date
unurled
bc6cb56261 change little things 2023-02-16 13:35:42 +00:00
unurled
e00ab6183c rust server working :) !!! 2023-02-16 13:30:06 +01:00
unurled
d625ced9b1 Merge branch 'master' of https://git.unurled.gq/unurled/text-display 2022-05-18 14:11:37 +02:00
unurled
6ec575810a use xxhash 2022-05-18 14:10:30 +02:00
unurled
f6ad485262 bug fix 2022-05-18 09:00:45 +02:00
unurled
5c29ebd821 readme.md 2022-02-23 11:37:32 +01:00
unurled
e0813ba69c Add mongodb to dotenv 2022-02-23 11:34:30 +01:00
unurled
21e059fd33 use of dotenv to get url and port. 2022-02-23 11:31:46 +01:00
unurled
5dede3767b Merge branch 'master' of gitlab.com:unurled/text-display 2022-02-21 16:44:04 +01:00
unurled
7847d29200 Hash password 2022-02-21 16:43:57 +01:00
unurled
78a63803d0 Update README.MD 2022-02-19 10:21:46 +00:00
33 changed files with 416 additions and 1134 deletions

2
.env.example Normal file
View file

@ -0,0 +1,2 @@
URL="http://localhost"
PORT="3030"

12
.gitignore vendored
View file

@ -1,2 +1,10 @@
node_modules/
package-lock.json
.env
# Added by cargo
/target
Cargo.lock
db.json
.vscode
.idea

17
Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "text-display"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dotenv = "0.15.0"
rocket = { version = "0.5.0-rc.2", features = ["json", "secrets"] }
rocket_cors = "0.5.2"
rpassword = "7.2.0"
serde = "1.0.152"
serde_json = "1.0.93"
text_io = "0.1.12"
tokio = { version = "1.25.0", features = ["full"] }
xxhash-rust = { version = "0.8.6", features = ["xxh64"] }

View file

@ -5,7 +5,7 @@ havn't throught of any better name sooo...
making it working :
- download nodejs
- download or setup on cloud a mongodb database
- add to mongodb an entry: (will be making a proper way to do it in the future maybe not so shure)
- add to mongodb an entry: (will be making a proper way to do it in the future maybe not so sure)
```
{
"_id": {
@ -16,11 +16,6 @@ making it working :
"text": "text"
}
```
- change http://localhost:3000 to your url and stuff in :
- `src/index.js:49:12` and `src/index.js:49:31`
- `src/text.js:7:19` to your username (need to access mongodb)
- `src/public/getText.js:13:60`
- `src/public/main.js:13:65`
- `src/config/db.config.js:5:17` link to your mongodb database url
- `cp .env.example .env` and change the values like you need.
- `npm i`
- `npm start`

20
Rocket.toml Normal file
View file

@ -0,0 +1,20 @@
## defaults for _all_ profiles
[default]
address = "0.0.0.0"
limits = { form = "64 kB", json = "1 MiB" }
## set only when compiled in debug mode, i.e, `cargo build`
[debug]
port = 8000
## only the `json` key from `default` will be overridden; `form` will remain
limits = { json = "10MiB" }
## set only when the `nyc` profile is selected
[nyc]
port = 9001
## set only when compiled in release mode, i.e, `cargo build --release`
## don't use this secret_key! generate your own and keep it private!
[release]
port = 8000
secret_key = "edit me"

767
dist/output.css vendored
View file

@ -1,767 +0,0 @@
/*
! tailwindcss v3.0.16 | MIT License | https://tailwindcss.com
*/
/*
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
*/
*,
::before,
::after {
box-sizing: border-box;
/* 1 */
border-width: 0;
/* 2 */
border-style: solid;
/* 2 */
border-color: #e5e7eb;
/* 2 */
}
::before,
::after {
--tw-content: '';
}
/*
1. Use a consistent sensible line-height in all browsers.
2. Prevent adjustments of font size after orientation changes in iOS.
3. Use a more readable tab size.
4. Use the user's configured `sans` font-family by default.
*/
html {
line-height: 1.5;
/* 1 */
-webkit-text-size-adjust: 100%;
/* 2 */
-moz-tab-size: 4;
/* 3 */
-o-tab-size: 4;
tab-size: 4;
/* 3 */
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
/* 4 */
}
/*
1. Remove the margin in all browsers.
2. Inherit line-height from `html` so users can set them as a class directly on the `html` element.
*/
body {
margin: 0;
/* 1 */
line-height: inherit;
/* 2 */
}
/*
1. Add the correct height in Firefox.
2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
3. Ensure horizontal rules are visible by default.
*/
hr {
height: 0;
/* 1 */
color: inherit;
/* 2 */
border-top-width: 1px;
/* 3 */
}
/*
Add the correct text decoration in Chrome, Edge, and Safari.
*/
abbr:where([title]) {
-webkit-text-decoration: underline dotted;
text-decoration: underline dotted;
}
/*
Remove the default font size and weight for headings.
*/
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: inherit;
font-weight: inherit;
}
/*
Reset links to optimize for opt-in styling instead of opt-out.
*/
a {
color: inherit;
text-decoration: inherit;
}
/*
Add the correct font weight in Edge and Safari.
*/
b,
strong {
font-weight: bolder;
}
/*
1. Use the user's configured `mono` font family by default.
2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp,
pre {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
/* 1 */
font-size: 1em;
/* 2 */
}
/*
Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/*
Prevent `sub` and `sup` elements from affecting the line height in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/*
1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
3. Remove gaps between table borders by default.
*/
table {
text-indent: 0;
/* 1 */
border-color: inherit;
/* 2 */
border-collapse: collapse;
/* 3 */
}
/*
1. Change the font styles in all browsers.
2. Remove the margin in Firefox and Safari.
3. Remove default padding in all browsers.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit;
/* 1 */
font-size: 100%;
/* 1 */
line-height: inherit;
/* 1 */
color: inherit;
/* 1 */
margin: 0;
/* 2 */
padding: 0;
/* 3 */
}
/*
Remove the inheritance of text transform in Edge and Firefox.
*/
button,
select {
text-transform: none;
}
/*
1. Correct the inability to style clickable types in iOS and Safari.
2. Remove default button styles.
*/
button,
[type='button'],
[type='reset'],
[type='submit'] {
-webkit-appearance: button;
/* 1 */
background-color: transparent;
/* 2 */
background-image: none;
/* 2 */
}
/*
Use the modern Firefox focus style for all focusable elements.
*/
:-moz-focusring {
outline: auto;
}
/*
Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)
*/
:-moz-ui-invalid {
box-shadow: none;
}
/*
Add the correct vertical alignment in Chrome and Firefox.
*/
progress {
vertical-align: baseline;
}
/*
Correct the cursor style of increment and decrement buttons in Safari.
*/
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: auto;
}
/*
1. Correct the odd appearance in Chrome and Safari.
2. Correct the outline style in Safari.
*/
[type='search'] {
-webkit-appearance: textfield;
/* 1 */
outline-offset: -2px;
/* 2 */
}
/*
Remove the inner padding in Chrome and Safari on macOS.
*/
::-webkit-search-decoration {
-webkit-appearance: none;
}
/*
1. Correct the inability to style clickable types in iOS and Safari.
2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button;
/* 1 */
font: inherit;
/* 2 */
}
/*
Add the correct display in Chrome and Safari.
*/
summary {
display: list-item;
}
/*
Removes the default spacing and border for appropriate elements.
*/
blockquote,
dl,
dd,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
figure,
p,
pre {
margin: 0;
}
fieldset {
margin: 0;
padding: 0;
}
legend {
padding: 0;
}
ol,
ul,
menu {
list-style: none;
margin: 0;
padding: 0;
}
/*
Prevent resizing textareas horizontally by default.
*/
textarea {
resize: vertical;
}
/*
1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)
2. Set the default placeholder color to the user's configured gray 400 color.
*/
input::-moz-placeholder, textarea::-moz-placeholder {
opacity: 1;
/* 1 */
color: #9ca3af;
/* 2 */
}
input:-ms-input-placeholder, textarea:-ms-input-placeholder {
opacity: 1;
/* 1 */
color: #9ca3af;
/* 2 */
}
input::placeholder,
textarea::placeholder {
opacity: 1;
/* 1 */
color: #9ca3af;
/* 2 */
}
/*
Set the default cursor for buttons.
*/
button,
[role="button"] {
cursor: pointer;
}
/*
Make sure disabled buttons don't get the pointer cursor.
*/
:disabled {
cursor: default;
}
/*
1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
This can trigger a poorly considered lint error in some tools but is included by design.
*/
img,
svg,
video,
canvas,
audio,
iframe,
embed,
object {
display: block;
/* 1 */
vertical-align: middle;
/* 2 */
}
/*
Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)
*/
img,
video {
max-width: 100%;
height: auto;
}
/*
Ensure the default browser behavior of the `hidden` attribute.
*/
[hidden] {
display: none;
}
*, ::before, ::after {
--tw-translate-x: 0;
--tw-translate-y: 0;
--tw-rotate: 0;
--tw-skew-x: 0;
--tw-skew-y: 0;
--tw-scale-x: 1;
--tw-scale-y: 1;
--tw-pan-x: ;
--tw-pan-y: ;
--tw-pinch-zoom: ;
--tw-scroll-snap-strictness: proximity;
--tw-ordinal: ;
--tw-slashed-zero: ;
--tw-numeric-figure: ;
--tw-numeric-spacing: ;
--tw-numeric-fraction: ;
--tw-ring-inset: ;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgb(59 130 246 / 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
--tw-blur: ;
--tw-brightness: ;
--tw-contrast: ;
--tw-grayscale: ;
--tw-hue-rotate: ;
--tw-invert: ;
--tw-saturate: ;
--tw-sepia: ;
--tw-drop-shadow: ;
--tw-backdrop-blur: ;
--tw-backdrop-brightness: ;
--tw-backdrop-contrast: ;
--tw-backdrop-grayscale: ;
--tw-backdrop-hue-rotate: ;
--tw-backdrop-invert: ;
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
}
.static {
position: static;
}
.absolute {
position: absolute;
}
.bottom-0 {
bottom: 0px;
}
.left-10 {
left: 2.5rem;
}
.left-52 {
left: 13rem;
}
.top-52 {
top: 13rem;
}
.left-0 {
left: 0px;
}
.right-0 {
right: 0px;
}
.grid {
display: grid;
}
.h-24 {
height: 6rem;
}
.h-screen {
height: 100vh;
}
.grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.place-content-center {
place-content: center;
}
.place-items-center {
place-items: center;
}
.content-center {
align-content: center;
}
.items-center {
align-items: center;
}
.gap-4 {
gap: 1rem;
}
.gap-40 {
gap: 10rem;
}
.gap-10 {
gap: 2.5rem;
}
.self-center {
align-self: center;
}
.rounded-full {
border-radius: 9999px;
}
.rounded-sm {
border-radius: 0.125rem;
}
.rounded-lg {
border-radius: 0.5rem;
}
.border {
border-width: 1px;
}
.border-2 {
border-width: 2px;
}
.border-4 {
border-width: 4px;
}
.border-stone-700 {
--tw-border-opacity: 1;
border-color: rgb(68 64 60 / var(--tw-border-opacity));
}
.border-slate-900 {
--tw-border-opacity: 1;
border-color: rgb(15 23 42 / var(--tw-border-opacity));
}
.border-slate-50 {
--tw-border-opacity: 1;
border-color: rgb(248 250 252 / var(--tw-border-opacity));
}
.bg-slate-600 {
--tw-bg-opacity: 1;
background-color: rgb(71 85 105 / var(--tw-bg-opacity));
}
.px-4 {
padding-left: 1rem;
padding-right: 1rem;
}
.py-1 {
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.py-4 {
padding-top: 1rem;
padding-bottom: 1rem;
}
.px-10 {
padding-left: 2.5rem;
padding-right: 2.5rem;
}
.py-3 {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
}
.px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.font-mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.font-sans {
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}
.text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}
.text-lg {
font-size: 1.125rem;
line-height: 1.75rem;
}
.text-9xl {
font-size: 8rem;
line-height: 1;
}
.text-7xl {
font-size: 4.5rem;
line-height: 1;
}
.text-6xl {
font-size: 3.75rem;
line-height: 1;
}
.text-5xl {
font-size: 3rem;
line-height: 1;
}
.text-2xl {
font-size: 1.5rem;
line-height: 2rem;
}
.text-4xl {
font-size: 2.25rem;
line-height: 2.5rem;
}
.font-bold {
font-weight: 700;
}
.font-medium {
font-weight: 500;
}
.text-gray-300 {
--tw-text-opacity: 1;
color: rgb(209 213 219 / var(--tw-text-opacity));
}
.text-slate-100 {
--tw-text-opacity: 1;
color: rgb(241 245 249 / var(--tw-text-opacity));
}
.text-slate-50 {
--tw-text-opacity: 1;
color: rgb(248 250 252 / var(--tw-text-opacity));
}
.shadow-sm {
--tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.shadow {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.hover\:border-none:hover {
border-style: none;
}
.hover\:border-transparent:hover {
border-color: transparent;
}
.hover\:border-slate-900:hover {
--tw-border-opacity: 1;
border-color: rgb(15 23 42 / var(--tw-border-opacity));
}
.hover\:bg-black:hover {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
.hover\:bg-slate-900:hover {
--tw-bg-opacity: 1;
background-color: rgb(15 23 42 / var(--tw-bg-opacity));
}
.hover\:font-bold:hover {
font-weight: 700;
}
.hover\:text-gray-400:hover {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}
.focus\:border-slate-900:focus {
--tw-border-opacity: 1;
border-color: rgb(15 23 42 / var(--tw-border-opacity));
}
.focus\:bg-slate-900:focus {
--tw-bg-opacity: 1;
background-color: rgb(15 23 42 / var(--tw-bg-opacity));
}
.focus\:hover\:border-slate-900:hover:focus {
--tw-border-opacity: 1;
border-color: rgb(15 23 42 / var(--tw-border-opacity));
}
.focus\:hover\:bg-slate-900:hover:focus {
--tw-bg-opacity: 1;
background-color: rgb(15 23 42 / var(--tw-bg-opacity));
}

View file

@ -1,24 +0,0 @@
{
"name": "text",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js"
},
"author": "unurled",
"license": "ISC",
"dependencies": {
"dotenv": "^14.3.0",
"express": "^4.17.2",
"express-session": "^1.17.2",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.1.8",
"passport": "^0.5.2",
"passport-gitlab2": "^5.0.0",
"passport-local": "^1.0.0"
},
"devDependencies": {
"tailwindcss": "^3.0.16"
}
}

17
public/css/main.css Normal file
View file

@ -0,0 +1,17 @@
#content {
position: absolute;
top: 40vh;
}
#login-content {
position: absolute;
top: 20vh;
}
#login {
bottom: 5vh;
}
#text {
font-size: large;
}

31
public/edit.html Normal file
View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Text Display</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<script src="js/edit.js"></script>
<div id="login-content" class="container-fluid text-center">
<div class="container">
<h1>Login</h1>
<div class="container">
<div class="form-floating">
<textarea class="form-control" placeholder="Text" id="text" style="height: 50vh;"></textarea>
<label for="text">Set your text</label>
</div>
<br>
<input class="btn btn-primary" type="submit" value="Save" onclick="saveText()">
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<script src="js/main.js"></script>
</body>
</html>

23
public/index.html Normal file
View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Text Display</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<div id="content" class="container-fluid text-center">
<div class="container">
<p id="text"></p>
</div>
<div id="login" class="container fixed-bottom">
<a class="btn btn-outline-info login-btn" href="login.html">Login</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<script src="js/main.js"></script>
</body>
</html>

17
public/js/edit.js Normal file
View file

@ -0,0 +1,17 @@
function saveText() {
let x = document.getElementById("text").value;
const options = {method: 'POST', body: JSON.stringify({text: x}), headers: { 'Content-Type': 'application/json' }};
fetch(location.protocol + '/api/edit', options)
.then((response) => response.text())
.then(data => {
redirectOrNot(data);
})
.catch(err => console.error(err));
}
async function redirectOrNot(res) {
let url = location.protocol
location.href = url+res
}

18
public/js/login.js Normal file
View file

@ -0,0 +1,18 @@
function formLink() {
let x = document.getElementById("Token").value;
const options = {method: 'POST', headers: {Token: x}};
fetch(location.protocol + '/login', options)
.then((response) => response.text())
.then(data => {
redirectOrNot(data);
})
.catch(err => console.log(err));
}
async function redirectOrNot(res) {
let url = location.protocol
location.href = url+res
}

18
public/js/main.js Normal file
View file

@ -0,0 +1,18 @@
!async function(){
let data = await fetch(location.protocol + "/api")
.then((response) => response.text())
.then(data => {
return data;
})
.catch(error => {
console.error(error);
});
console.log(data);
print(data);
}();
function print(data) {
document.getElementById("text").innerText = data
document.getElementById("text").value = data
}

30
public/login.html Normal file
View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Text Display</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<script src="js/login.js"></script>
<div id="login-content" class="container-fluid text-center">
<div class="container">
<h1>Login</h1>
<div class="container">
<div class="input-group">
<label class="input-group-text">Api - key</label>
<input name="Token" id="Token" type="text" class="form-control" placeholder="xxxx-xxxx-xxxxx-xxxxx">
</div>
<br>
<input class="btn btn-primary" type="submit" value="Submit" onclick="formLink()">
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

View file

@ -1,13 +0,0 @@
// import mongoose package
const mongoose = require('mongoose')
// declare a Database string URI
const DB_URI = 'mongodb://127.0.0.1:27017/urlshortener'
// establishing a database connection
mongoose.connect(DB_URI)
const connection = mongoose.connection
// export the connection object
module.exports = connection

11
src/data.rs Normal file
View file

@ -0,0 +1,11 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Text {
pub(crate) password: u64,
pub(crate) text: String,
}
pub(crate) fn deserialize(data: String) -> Result<Text, serde_json::Error> {
serde_json::from_str(Box::leak(data.into_boxed_str()))
}

45
src/file.rs Normal file
View file

@ -0,0 +1,45 @@
use std::{fs::File, path::Path, io::Write, fs::write};
use std::string::ToString;
use text_io::read;
use rpassword::prompt_password;
use crate::data::Text;
use crate::hash;
pub static PATH: &str = "db.json";
pub fn new_file() -> File {
let pass: String = prompt_password("Input the token: ").unwrap();
print!("Input the text you want to display: ");
let text_str: String = read!("{}\n");
let path_obj = Path::new(&PATH);
let text_obj = Text {
password: hash::hash(pass),
text: text_str,
};
let j = serde_json::to_string(&text_obj).unwrap();
let mut file = match File::create(&path_obj) {
Err(why) => panic!("couldn't create {}: {}", path_obj.display(), why),
Ok(file) => file,
};
match file.write_all(j.to_string().as_bytes()) {
Err(why) => panic!("couldn't write to {}: {}", path_obj.display(), why),
Ok(file) => file,
};
return file;
}
pub fn write_file(data: Text) {
let j = serde_json::to_string(&data).unwrap();
write(&PATH, j).expect("Unable to write data;");
}
pub fn get_file() -> File {
let path_obj = Path::new("db.json");
let file: File = match File::open(&path_obj) {
Err(_why) => new_file(),
Ok(file) => file,
};
return file;
}

5
src/hash.rs Normal file
View file

@ -0,0 +1,5 @@
use xxhash_rust::xxh64::xxh64;
pub fn hash(string: String) -> u64 {
xxh64(string.as_bytes(), 12)
}

127
src/http_server.rs Normal file
View file

@ -0,0 +1,127 @@
use std::fs;
use std::path::Path;
use rocket;
use rocket::fs::{FileServer, NamedFile, relative};
use rocket::http::{CookieJar, Cookie, Status};
use rocket::request::{FromRequest, Outcome};
use rocket::{Request, routes, uri};
use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors};
use rocket::serde::json::Json;
use crate::{data, file};
use crate::data::deserialize;
use crate::file::PATH;
struct Token(String);
#[derive(Debug)]
enum ApiTokenError {
Missing,
}
#[derive(serde::Deserialize)]
#[serde(crate = "rocket::serde")]
struct Text<'r> {
text: &'r str,
}
#[rocket::async_trait]
impl<'r> FromRequest<'r> for Token {
type Error = ApiTokenError;
async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome<Self, Self::Error> {
let token = request.headers().get_one("token");
match token {
Some(token) => {
// check validity
Outcome::Success(Token(token.to_string()))
}
None => Outcome::Failure((Status::Unauthorized, ApiTokenError::Missing)),
}
}
}
fn make_cors() -> Cors {
rocket_cors::CorsOptions {
allowed_origins: AllowedOrigins::all(),
allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]),
allow_credentials: true,
..Default::default()
}
.to_cors()
.expect("error while building CORS")
}
#[rocket::get("/")]
fn get_text() -> String {
let content = data::deserialize(fs::read_to_string(&file::PATH).expect(""));
if content.is_err() {
return "".to_string();
}
return content.unwrap().text;
}
#[rocket::get("/edit")]
async fn edit_get() -> Option<NamedFile> {
let path = Path::new(relative!("public")).join("edit.html");
NamedFile::open(path).await.ok()
}
#[rocket::post("/login")]
fn login(token: Token, cookies: &CookieJar<'_>) -> String {
let temp = fs::read_to_string(PATH);
if temp.is_err() {
return "/".to_string();
}
let content = deserialize(temp.unwrap());
let token_int = token.0.parse::<u64>();
if token_int.is_err() {
return "/".to_string();
}
if content.is_ok() {
if content.unwrap().password == token.0.parse::<u64>().unwrap() {
cookies.add_private(Cookie::new("Token", token.0));
return uri!(edit_get).to_string();
}
}
return "/".to_string();
}
#[rocket::post("/edit", format = "json", data = "<text>")]
fn edit(text: Json<Text<'_>>, cookies: &CookieJar<'_>) -> String {
let temp = fs::read_to_string(PATH);
if temp.is_err() {
return "/".to_string();
}
let content = deserialize(temp.unwrap());
let token = cookies.get_private("Token");
if token.is_none() {
return "/".to_string();
}
let token_int = token.unwrap().value().parse::<u64>();
if token_int.is_err() {
return "/".to_string();
}
if content.is_ok() {
let mut data = content.unwrap();
if data.password == token_int.unwrap() {
data.text = text.text.to_string();
file::write_file(data);
return "/".to_string();
}
}
return "/".to_string();
}
#[rocket::main]
pub async fn main() -> Result<(), rocket::Error> {
let _rocket = rocket::build()
.mount("/", FileServer::from("public/"))
.mount("/", routes![login, edit_get])
.mount("/api", routes![get_text, edit])
.manage(make_cors())
.launch()
.await?;
Ok(())
}

View file

@ -1,49 +0,0 @@
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var path = require('path');
const connection = require('./config/db.config');
connection.once('open', () => console.log('DB Connected'));
connection.on('error', () => console.log('Error'));
var app = express();
app.use(session({
secret: 'haklo secret very secret',
resave: true,
saveUninitialized: true
}));
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use('/api/post', require('./post'));
app.use('/text', require('./text'))
app.use('/', require('./login'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + `/public/index.html`));
})
app.get('/main.js', function(req, res) {
res.sendFile(path.join(__dirname + '/public/main.js'))
})
app.get('/FetchService.js', function(req, res) {
res.sendFile(path.join(__dirname + '/public/FetchService.js'))
})
app.get('/getText.js', function(req, res) {
res.sendFile(path.join(__dirname + '/public/getText.js'))
})
app.get('/login.html', function (req, res) {
res.sendFile(path.join(__dirname + `/public/login.html`));
})
app.get('/dist/output.css', function (req, res) {
res.sendFile(path.join(__dirname + `/../dist/output.css`));
})
app.get('/edit', function(request, res) {
if (request.session.loggedin) {
res.sendFile(path.join(__dirname + `/public/edit.html`));
} else {
res.send("You need to login at /login.html");
}
});
app.listen(3000, console.log("http://localhost:3000"))

View file

@ -1,34 +0,0 @@
const User = require('./model/user');
const express = require('express')
const router = express.Router()
router.post('/auth', function(request, response) {
var username = request.body.username;
var password = request.body.password;
if (username && password) {
let user = User.findOne({
name: username, pass: password
}, function(err, results) {
if (results !=null) {
console.log(results.name);
if (results.name.length > 0) {
request.session.loggedin = true;
request.session.username = username;
request.session.password = password
response.redirect('/edit');
} else {
response.send('Incorrect Username and/or Password!');
}
response.end();
} else {
response.send('Use a registered username Please.')
}
});
} else {
response.send('Please enter Username and Password!');
response.end();
}
});
module.exports = router

22
src/main.rs Normal file
View file

@ -0,0 +1,22 @@
use dotenv::dotenv;
use std::env;
mod file;
pub mod hash;
mod http_server;
mod data;
use file::get_file;
fn main() {
dotenv().ok();
if env::var("URL").is_err() || env::var("PORT").is_err() {
println!("Please set .env file, you can see an example in the file .env.example");
return;
}
let _file = get_file();
let res = http_server::main();
if res.is_err() {
println!("Error in server: {}", res.unwrap_err())
}
}

View file

@ -1,12 +0,0 @@
const mongoose = require('mongoose')
// instantiate a mongoose schema
const UserSchema = new mongoose.Schema({
name: String,
pass: String,
text: String
})
// create a model from schema and export it
// user here is the collection name modify it if you want
module.exports = mongoose.model('user', UserSchema)

View file

@ -1,26 +0,0 @@
const express = require('express')
const router = express.Router()
const User = require('./model/user');
router.post('/', function(request, response) {
console.log("Connection")
var username = request.session.username;
var password = request.session.password;
console.log(username + password)
let user = User.findOneAndUpdate(
{user: username},
{text: request.body.text}, function(err, results) {
console.log("updated, ")
console.log(request.body)
console.log(results.text)
if (results.text.length > 0) {
response.redirect("/");
//response.sendFile(path.join(__dirname + `/public/index.html`))
} else {
response.send('Incorrect Username and/or Password!');
}
});
});
module.exports = router

View file

@ -1,62 +0,0 @@
export default class FetchService {
constructor() {
}
async performGetHttpRequest(fetchLink, headers, query=null) {
if(!fetchLink || !headers) {
throw new Error("One or more GET request parameters was not passed.");
}
try {
const rawResponse = await fetch(fetchLink, {
method: "GET",
headers: headers,
query: (query != null) ? query : ""
});
const content = await rawResponse.json();
return content;
}
catch(err) {
console.error(`Error at fetch GET: ${err}`);
throw err;
}
}
async performPostHttpRequest(fetchLink, headers, body) {
if(!fetchLink || !headers || !body) {
throw new Error("One or more POST request parameters was not passed.");
}
try {
const rawResponse = await fetch(fetchLink, {
method: "POST",
headers: headers,
body: JSON.stringify(body)
});
const content = await rawResponse.json();
return content;
}
catch(err) {
console.error(`Error at fetch POST: ${err}`);
throw err;
}
}
async performPutHttpRequest(fetchLink, headers, body) {
if(!fetchLink || !headers || !body) {
throw new Error("One or more POST request parameters was not passed.");
}
try {
const rawResponse = await fetch(fetchLink, {
method: "PUT",
headers: headers,
body: JSON.stringify(body)
});
const content = await rawResponse.json();
return content;
}
catch(err) {
console.error(`Error at fetch PUT: ${err}`);
throw err;
}
}
}

View file

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../../dist/output.css">
</head>
<body class="bg-slate-600 text-2xl">
<div class="content-center place-items-center h-screen place-content-center text-slate-50">
<h1 class="content-center">Edit text</h1>
<textarea id="textarea1" class="bg-slate-600 border-full border border-slate-50 hover:border-slate-900 focus:border-slate-900 rounded-lg input shadow" name="name" rows="15" cols="100" placeholder="Your text here "></textarea>
<br/>
<button type="button" id="btn" class="px-2 py-2 btn shadow-sm btn-outline-primary side border rounded-full border-slate-900 focus:bg-slate-900 hover:bg-slate-900" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Save</button>
<script type="module" src="FetchService.js"></script>
<script type="module" src="main.js"></script>
<p id="response"></p>
</div>
</body>
</html>

View file

@ -1,15 +0,0 @@
import FetchService from './FetchService.js';
const fetchService = new FetchService();
function buildHeaders(authorization = null) {
const headers = {
"Content-Type": "application/json",
"Authorization": (authorization) ? authorization : "Bearer TOKEN_MISSING"
};
return headers;
}
const response = await fetchService.performGetHttpRequest('http://localhost:3000/text', buildHeaders());
document.getElementById("text").innerHTML = response.text;

View file

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../../dist/output.css">
</head>
<body class="bg-slate-600">
<p class="px-4 py-4 text-4xl items-center text-gray-300 font-bold" id="text"></p>
<a class="absolute right-0 bottom-0 px-4 py-1 text-sm border border-stone-700 hover:border-transparent text-gray-300 hover:font-bold hover:text-gray-400 hover:bg-black rounded-full" href="login.html">Login</a>
<script type="module" src="FetchService.js"></script>
<script type="module" src="getText.js"></script>
</body>
</html>

View file

@ -1,27 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="../../dist/output.css">
</head>
<body class="bg-slate-600">
<div class="font-sans text-5xl bg-slate-600 place-items-center h-screen content-center grid grid-cols-1 gap-10 place-content-center">
<div>
<h1 class="text-slate-100">Login Form</h1>
</div>
<form action="auth" method="POST">
<div>
<input class="" type="text" name="username" placeholder="Username" required>
</div>
<div>
<input type="password" name="password" placeholder="Password" required>
</div>
<div>
<input class="px-4 py-4 rounded-full text-slate-100 border-slate-50 border-4 hover:border-none hover:bg-slate-900" type="submit">
</form>
</div>
</div>
</body>
</html>

View file

@ -1,31 +0,0 @@
import FetchService from './FetchService.js';
/*-- Objects --*/
const fetchService = new FetchService();
async function save(e, btn) {
const textarea = document.getElementById('textarea1').value;
const headers = buildHeaders();
const jsonFileData = buildJsonFormData(textarea);
const response = await fetchService.performPostHttpRequest('http://localhost:3000/api/post', headers, jsonFileData);
}
function buildHeaders(authorization = null) {
const headers = {
"Content-Type": "application/json",
"Authorization": (authorization) ? authorization : "Bearer TOKEN_MISSING"
};
return headers;
}
function buildJsonFormData(text) {
return JSON.parse('{"text": "'+ text+'"}');
}
const button = document.querySelector(".btn");
button.addEventListener('click', function(e) {
save(e, this);
});

View file

@ -1,3 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View file

@ -1,22 +0,0 @@
const express = require('express')
const router = express.Router()
const User = require('./model/user');
router.get('/', function(request, response) {
let username = 'unurled';
console.log(username)
let user = User.findOne(
{user: username}, function(err, results) {
console.log("updated, ")
console.log(results.text)
if (results.text.length > 0) {
response.send('{"text": "' + results.text + '"}')
//response.sendFile(path.join(__dirname + `/public/index.html`))
} else {
response.send('Incorrect Username and/or Password!');
}
});
});
module.exports = router

View file

@ -1,10 +0,0 @@
module.exports = {
content: [
"./src/public/*.{html,js}",
"./src/*.{js}"
],
theme: {
extend: {},
},
plugins: [],
}