time based fix

This commit is contained in:
cupcakearmy 2021-12-22 14:46:06 +01:00
parent 8cee6579e2
commit 33829768eb
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
5 changed files with 28 additions and 13 deletions

View File

@ -16,4 +16,4 @@ services:
depends_on:
- memcached
ports:
- 5000:5000
- 80:5000

View File

@ -1,11 +1,19 @@
import http from 'http'
import httpProxy from 'http-proxy'
const proxy = httpProxy.createProxyServer({})
var server = http.createServer(function (req, res) {
function start() {
try {
const proxy = httpProxy.createProxyServer({})
const server = http.createServer(function (req, res) {
const target = req.url.startsWith('/api/') ? 'http://localhost:5000' : 'http://localhost:3000'
proxy.web(req, res, { target })
})
})
server.listen(1234)
server.listen(1234)
server.on('error', () => start())
} catch (e) {
start()
}
}
start()

View File

@ -7,7 +7,7 @@ pub struct Note {
pub meta: String,
pub contents: String,
pub views: Option<u8>,
pub expiration: Option<u64>,
pub expiration: Option<u32>,
}
#[derive(Serialize, Deserialize, Clone)]

View File

@ -6,11 +6,11 @@ use crate::note::{generate_id, Note, NoteInfo, NotePublic};
use crate::size::LIMIT;
use crate::store;
fn now() -> u64 {
pub fn now() -> u32 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs()
.as_secs() as u32
}
#[derive(Serialize, Deserialize)]
@ -86,10 +86,12 @@ async fn delete(path: web::Path<NotePath>) -> impl Responder {
}
_ => {}
}
let n = now();
match changed.expiration {
Some(e) => {
if e < n {
store::del(&p.id.clone());
if e < now() {
return HttpResponse::BadRequest().finish();
}
}

View File

@ -1,5 +1,6 @@
use memcache;
use crate::note::now;
use crate::note::Note;
lazy_static! {
@ -12,7 +13,11 @@ lazy_static! {
pub fn set(id: &String, note: &Note) {
let serialized = serde_json::to_string(&note.clone()).unwrap();
CLIENT.set(id, serialized, 0).unwrap();
let expiration: u32 = match note.expiration {
Some(e) => e - now(),
None => 0,
};
CLIENT.set(id, serialized, expiration).unwrap();
}
pub fn get(id: &String) -> Option<Note> {