mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-22 08:16:28 +00:00
time based fix
This commit is contained in:
parent
8cee6579e2
commit
33829768eb
@ -16,4 +16,4 @@ services:
|
||||
depends_on:
|
||||
- memcached
|
||||
ports:
|
||||
- 5000:5000
|
||||
- 80:5000
|
||||
|
20
proxy.mjs
20
proxy.mjs
@ -1,11 +1,19 @@
|
||||
import http from 'http'
|
||||
import httpProxy from 'http-proxy'
|
||||
|
||||
const proxy = httpProxy.createProxyServer({})
|
||||
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)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
const target = req.url.startsWith('/api/') ? 'http://localhost:5000' : 'http://localhost:3000'
|
||||
proxy.web(req, res, { target })
|
||||
})
|
||||
server.on('error', () => start())
|
||||
} catch (e) {
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
server.listen(1234)
|
||||
start()
|
||||
|
@ -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)]
|
||||
|
@ -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) => {
|
||||
store::del(&p.id.clone());
|
||||
if e < now() {
|
||||
if e < n {
|
||||
store::del(&p.id.clone());
|
||||
return HttpResponse::BadRequest().finish();
|
||||
}
|
||||
}
|
||||
|
@ -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(¬e.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> {
|
||||
|
Loading…
Reference in New Issue
Block a user