mirror of
https://github.com/eliasrenman/url-shortener.git
synced 2026-03-16 20:16:06 +01:00
feat: links expiry
This commit is contained in:
@@ -2,12 +2,17 @@ use self::db::models::Urls;
|
|||||||
use super::schema::urls::dsl::*;
|
use super::schema::urls::dsl::*;
|
||||||
use super::schema::urls::*;
|
use super::schema::urls::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::{NaiveDateTime, Utc};
|
||||||
use diesel::{delete, dsl::insert_into, prelude::*, result::Error};
|
use diesel::{delete, dsl::insert_into, prelude::*, result::Error};
|
||||||
|
|
||||||
pub fn get_entry(path: &str) -> Result<Urls, Error> {
|
pub fn get_entry(path: &str) -> Result<Urls, Error> {
|
||||||
let connection = &mut establish_connection();
|
let connection = &mut establish_connection();
|
||||||
urls.find(path).select(Urls::as_select()).first(connection)
|
let now = Utc::now().naive_utc();
|
||||||
|
|
||||||
|
urls.find(path)
|
||||||
|
.filter(ttl.is_null().or(ttl.gt(now)))
|
||||||
|
.select(Urls::as_select())
|
||||||
|
.first(connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upsert_entry(
|
pub fn upsert_entry(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"@tailwindcss/vite": "^4.0.14",
|
"@tailwindcss/vite": "^4.0.14",
|
||||||
"@tanstack/svelte-query": "^5.69.0",
|
"@tanstack/svelte-query": "^5.69.0",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
"jwt-decode": "^4.0.0",
|
"jwt-decode": "^4.0.0",
|
||||||
"tailwindcss": "^4.0.14",
|
"tailwindcss": "^4.0.14",
|
||||||
},
|
},
|
||||||
@@ -187,6 +188,8 @@
|
|||||||
|
|
||||||
"combined-stream": ["combined-stream@1.0.8", "", { "dependencies": { "delayed-stream": "~1.0.0" } }, "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="],
|
"combined-stream": ["combined-stream@1.0.8", "", { "dependencies": { "delayed-stream": "~1.0.0" } }, "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="],
|
||||||
|
|
||||||
|
"date-fns": ["date-fns@4.1.0", "", {}, "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg=="],
|
||||||
|
|
||||||
"debug": ["debug@4.4.0", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA=="],
|
"debug": ["debug@4.4.0", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA=="],
|
||||||
|
|
||||||
"deepmerge": ["deepmerge@4.3.1", "", {}, "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A=="],
|
"deepmerge": ["deepmerge@4.3.1", "", {}, "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A=="],
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
"@tailwindcss/vite": "^4.0.14",
|
"@tailwindcss/vite": "^4.0.14",
|
||||||
"@tanstack/svelte-query": "^5.69.0",
|
"@tanstack/svelte-query": "^5.69.0",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
"jwt-decode": "^4.0.0",
|
"jwt-decode": "^4.0.0",
|
||||||
"tailwindcss": "^4.0.14"
|
"tailwindcss": "^4.0.14"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="p-3">Shortform</th>
|
<th class="p-3">Shortform</th>
|
||||||
<th class="p-3">Destination</th>
|
<th class="p-3">Destination</th>
|
||||||
<th class="p-3">Expire date</th>
|
<th class="p-3">Expires at</th>
|
||||||
<th class="p-3">Actions</th>
|
<th class="p-3">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { mutateDeleteUrl, type Url } from "@/api/url";
|
import { mutateDeleteUrl, type Url } from "@/api/url";
|
||||||
import { Edit, Trash } from "@lucide/svelte";
|
import { Edit, Trash } from "@lucide/svelte";
|
||||||
|
import { formatRelative } from "date-fns";
|
||||||
|
|
||||||
let { row }: { row: Url } = $props();
|
let { row }: { row: Url } = $props();
|
||||||
|
|
||||||
@@ -33,7 +34,10 @@
|
|||||||
></td
|
></td
|
||||||
>
|
>
|
||||||
<td class="p-3 truncate"
|
<td class="p-3 truncate"
|
||||||
>{row.ttl ? new Date(row.ttl).toLocaleTimeString() : "Never"}</td
|
>{row.ttl
|
||||||
|
? // Manually specifying Z at the end here since the date format saved in the database removes timezone info but we know it is saved as UTC+0
|
||||||
|
formatRelative(new Date(row.ttl + "Z"), new Date(), {})
|
||||||
|
: "Never"}</td
|
||||||
>
|
>
|
||||||
<td class="p-3 flex gap-3">
|
<td class="p-3 flex gap-3">
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in New Issue
Block a user