mirror of https://github.com/zer0bin-dev/zer0bin
yay!
This commit is contained in:
parent
4393106cd0
commit
99d4986f2b
|
@ -1,18 +1,22 @@
|
|||
{
|
||||
"server": {
|
||||
"backend_host": "127.0.0.1",
|
||||
"backend_port": 8000
|
||||
},
|
||||
"pastes": {
|
||||
"character_limit": 40000,
|
||||
"days_til_expiration": 7,
|
||||
"id_length": 10
|
||||
},
|
||||
"ratelimits": {
|
||||
"seconds_in_between_pastes": 2,
|
||||
"allowed_pastes_before_ratelimit": 5
|
||||
},
|
||||
"databases": {
|
||||
"postgres_uri": "postgres://postgres:postgres@localhost:5432/zer0bin"
|
||||
}
|
||||
"server": {
|
||||
"backend_host": "127.0.0.1",
|
||||
"backend_port": 8000
|
||||
},
|
||||
"pastes": {
|
||||
"character_limit": 40000,
|
||||
"days_til_expiration": 7,
|
||||
"id_length": 10
|
||||
},
|
||||
"ratelimits": {
|
||||
"seconds_in_between_pastes": 2,
|
||||
"allowed_pastes_before_ratelimit": 5
|
||||
},
|
||||
"databases": {
|
||||
"postgres_uri": "postgres://postgres:postgres@localhost:5432/zer0bin"
|
||||
},
|
||||
"logging": {
|
||||
"on_post_paste": true,
|
||||
"on_get_paste": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ pub struct Config {
|
|||
pub pastes: PastesConfig,
|
||||
pub ratelimits: RatelimitsConifg,
|
||||
pub databases: DatabasesConfig,
|
||||
pub logging: LoggingConfig
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
|
@ -34,6 +35,12 @@ pub struct DatabasesConfig {
|
|||
pub postgres_uri: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct LoggingConfig {
|
||||
pub on_post_paste: bool,
|
||||
pub on_get_paste: bool
|
||||
}
|
||||
|
||||
pub fn load(path: PathBuf) -> Config {
|
||||
let file = File::open(path).expect("Failed to load config");
|
||||
serde_json::from_reader(file).unwrap()
|
||||
|
|
|
@ -63,6 +63,10 @@ pub async fn get_paste(state: web::Data<AppState>, id: web::Path<String>) -> imp
|
|||
.execute(&state.pool)
|
||||
.await;
|
||||
|
||||
if state.config.logging.on_get_paste {
|
||||
println!("[GET] id={} views={}", id, p.views + 1);
|
||||
}
|
||||
|
||||
HttpResponse::Ok().json(ApiResponse {
|
||||
success: true,
|
||||
data: GetPasteResponse {
|
||||
|
@ -165,41 +169,29 @@ pub async fn new_paste(
|
|||
Some(Utc::now() + Duration::days(state.config.pastes.days_til_expiration))
|
||||
};
|
||||
|
||||
/*
|
||||
.replace(/&/g, '&')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')
|
||||
.replace(/"/g, '"');
|
||||
*/
|
||||
|
||||
// let cleaned = data
|
||||
// .content
|
||||
// .clone()
|
||||
// .replace("&", "&")
|
||||
// .replace("<", "<")
|
||||
// .replace(">", ">")
|
||||
// .replace(r#"""#, """);
|
||||
|
||||
let cleaned = data
|
||||
.content
|
||||
.clone();
|
||||
let content = data.content.clone();
|
||||
|
||||
let res =
|
||||
sqlx::query(r#"INSERT INTO pastes("id", "content", "expires_at") VALUES ($1, $2, $3)"#)
|
||||
.bind(id.clone())
|
||||
.bind(cleaned.clone())
|
||||
.bind(content.clone())
|
||||
.bind(expires_at)
|
||||
.execute(&state.pool)
|
||||
.await;
|
||||
|
||||
match res {
|
||||
Ok(_) => HttpResponse::Ok().json(ApiResponse {
|
||||
Ok(_) => {
|
||||
if state.config.logging.on_post_paste {
|
||||
println!("[POST] id={} length={}", id, content.len());
|
||||
}
|
||||
|
||||
HttpResponse::Ok().json(ApiResponse {
|
||||
success: true,
|
||||
data: NewPasteResponse {
|
||||
id,
|
||||
content: cleaned,
|
||||
content,
|
||||
},
|
||||
}),
|
||||
})},
|
||||
Err(e) => {
|
||||
eprintln!("Error occurred while creating paste: {:?}", e);
|
||||
|
||||
|
|
|
@ -166,14 +166,18 @@ function viewPaste(content: string, views: string) {
|
|||
enable(newButton)
|
||||
enable(copyButton)
|
||||
hide(editor)
|
||||
|
||||
show(codeViewPre)
|
||||
show(viewCounterLabel)
|
||||
show(viewCounter)
|
||||
|
||||
viewCounter.textContent = views
|
||||
|
||||
try {
|
||||
wrapper.classList.remove("text-area-proper")
|
||||
} catch (error) {}
|
||||
|
||||
Scrollbar.init(document.querySelector(".scrollbar-container"))
|
||||
viewCounter.textContent = views
|
||||
}
|
||||
|
||||
saveButton.addEventListener("click", async function () {
|
||||
|
|
Loading…
Reference in New Issue