mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 23:58:35 -06:00
Compare commits
4 commits
231fd3c8ca
...
3ad05f1e63
Author | SHA1 | Date | |
---|---|---|---|
3ad05f1e63 | |||
931b4a95e4 | |||
cdc3508a0c | |||
e742c0ab5e |
14 changed files with 53 additions and 10 deletions
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
FROM lukemathwalker/cargo-chef:latest-rust-slim AS chef
|
||||
WORKDIR /chhoto-url
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
FROM scratch as builder-amd64
|
||||
COPY ./actix/target/x86_64-unknown-linux-musl/release/chhoto-url /chhoto-url
|
||||
|
||||
|
|
3
Makefile
3
Makefile
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# .env file has the variables $DOCKER_USERNAME and $PASSWORD defined
|
||||
include .env
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<!-- SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com> -->
|
||||
<!-- SPDX-License-Identifier: MIT -->
|
||||
|
||||
[![docker-pulls](https://img.shields.io/docker/pulls/sintan1729/chhoto-url)](https://hub.docker.com/r/sintan1729/chhoto-url)
|
||||
[![maintainer](https://img.shields.io/badge/maintainer-SinTan1729-blue)](https://github.com/SinTan1729)
|
||||
![commit-since-latest-release](https://img.shields.io/github/commits-since/SinTan1729/chhoto-url/latest?sort=semver&label=commits%20since%20latest%20release)
|
||||
|
@ -39,6 +42,7 @@ for small. URL means, well... URL. So the name simply means Small URL.
|
|||
stays under 5MB under normal use.)
|
||||
- Counts number of hits for each short link in a privacy respecting way
|
||||
i.e. only the hit is recorded, and nothing else.
|
||||
- Has a mobile friendly UI.
|
||||
- Allows setting the URL of your website, in case you want to conveniently
|
||||
generate short links locally.
|
||||
- Links are stored in an SQLite database.
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
[package]
|
||||
name = "chhoto-url"
|
||||
version = "5.2.4"
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use actix_session::Session;
|
||||
use std::{env, time::SystemTime};
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use rusqlite::Connection;
|
||||
use serde::Serialize;
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use actix_files::{Files, NamedFile};
|
||||
use actix_session::{storage::CookieSessionStore, Session, SessionMiddleware};
|
||||
use actix_web::{
|
||||
|
@ -9,7 +12,7 @@ use actix_web::{
|
|||
App, Either, HttpResponse, HttpServer, Responder,
|
||||
};
|
||||
use rusqlite::Connection;
|
||||
use std::env;
|
||||
use std::{env, io::Result};
|
||||
mod auth;
|
||||
mod database;
|
||||
mod utils;
|
||||
|
@ -30,12 +33,12 @@ async fn add_link(req: String, data: web::Data<AppState>, session: Session) -> H
|
|||
if auth::validate(session) {
|
||||
let out = utils::add_link(req, &data.db);
|
||||
if out.0 {
|
||||
HttpResponse::Ok().body(out.1)
|
||||
HttpResponse::Created().body(out.1)
|
||||
} else {
|
||||
HttpResponse::BadRequest().body(out.1)
|
||||
HttpResponse::Conflict().body(out.1)
|
||||
}
|
||||
} else {
|
||||
HttpResponse::Forbidden().body("Not logged in!")
|
||||
HttpResponse::Unauthorized().body("Not logged in!")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +48,7 @@ async fn getall(data: web::Data<AppState>, session: Session) -> HttpResponse {
|
|||
if auth::validate(session) {
|
||||
HttpResponse::Ok().body(utils::getall(&data.db))
|
||||
} else {
|
||||
HttpResponse::Forbidden().body("Not logged in!")
|
||||
HttpResponse::Unauthorized().body("Not logged in!")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +59,7 @@ async fn siteurl(session: Session) -> HttpResponse {
|
|||
let site_url = env::var("site_url").unwrap_or(String::from("unset"));
|
||||
HttpResponse::Ok().body(site_url)
|
||||
} else {
|
||||
HttpResponse::Forbidden().body("Not logged in!")
|
||||
HttpResponse::Unauthorized().body("Not logged in!")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,7 @@ async fn login(req: String, session: Session) -> HttpResponse {
|
|||
if let Ok(password) = env::var("password") {
|
||||
if password != req {
|
||||
eprintln!("Failed login attempt!");
|
||||
return HttpResponse::Forbidden().body("Wrong password!");
|
||||
return HttpResponse::Unauthorized().body("Wrong password!");
|
||||
}
|
||||
}
|
||||
// Return Ok if no password was set on the server side
|
||||
|
@ -127,12 +130,12 @@ async fn delete_link(
|
|||
HttpResponse::NotFound().body("Not found!")
|
||||
}
|
||||
} else {
|
||||
HttpResponse::Forbidden().body("Not logged in!")
|
||||
HttpResponse::Unauthorized().body("Not logged in!")
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
async fn main() -> Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("warn"));
|
||||
|
||||
// Generate session key in runtime so that restart invalidates older logins
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use nanoid::nanoid;
|
||||
use rand::seq::SliceRandom;
|
||||
use regex::Regex;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
services:
|
||||
chhoto-url:
|
||||
image: sintan1729/chhoto-url:latest
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<!-- SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com> -->
|
||||
<!-- SPDX-License-Identifier: MIT -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<!-- SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com> -->
|
||||
<!-- SPDX-License-Identifier: MIT -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
|
@ -23,4 +26,4 @@
|
|||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
const prepSubdir = (link) => {
|
||||
let thisPage = new URL(window.location.href);
|
||||
let subdir = thisPage.pathname;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* SPDX-FileCopyrightText: 2023 Sayantan Santra <sayantan.santra689@gmail.com> */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
@font-face {
|
||||
font-family: Montserrat;
|
||||
src: url('Montserrat-VF.woff2');
|
||||
|
|
Loading…
Reference in a new issue