From 00fc1faed96d13cc52babb8e033b32bbc98192f9 Mon Sep 17 00:00:00 2001 From: poeti8 Date: Tue, 4 Aug 2020 20:32:23 +0430 Subject: [PATCH] feat: add link expiration --- client/components/LinksTable.tsx | 55 +++++++++++++++++-- client/components/Shortener.tsx | 32 +++++++++-- client/consts/consts.ts | 2 + client/store/links.ts | 4 +- docs/api/api.ts | 12 ++++ global.d.ts | 9 +-- package-lock.json | 36 ++++++------ server/cron.ts | 6 ++ server/handlers/links.ts | 16 +++++- server/handlers/types.d.ts | 1 + server/handlers/validators.ts | 37 ++++++++++++- server/migrations/20200730203154_expire_in.ts | 14 +++++ server/models/link.ts | 1 + server/queries/link.ts | 18 ++++++ 14 files changed, 205 insertions(+), 38 deletions(-) create mode 100644 server/migrations/20200730203154_expire_in.ts diff --git a/client/components/LinksTable.tsx b/client/components/LinksTable.tsx index 1164cb5..f1b2a26 100644 --- a/client/components/LinksTable.tsx +++ b/client/components/LinksTable.tsx @@ -8,6 +8,8 @@ import { ifProp } from "styled-tools"; import getConfig from "next/config"; import QRCode from "qrcode.react"; import Link from "next/link"; +import differenceInMilliseconds from "date-fns/differenceInMilliseconds"; +import ms from "ms"; import { removeProtocol, withComma, errorMessage } from "../utils"; import { useStoreActions, useStoreState } from "../store"; @@ -112,7 +114,8 @@ interface BanForm { interface EditForm { target: string; address: string; - description: string; + description?: string; + expire_in?: string; } const Row: FC = ({ index, link, setDeleteModal }) => { @@ -124,7 +127,12 @@ const Row: FC = ({ index, link, setDeleteModal }) => { { target: link.target, address: link.address, - description: link.description + description: link.description, + expire_in: link.expire_in + ? ms(differenceInMilliseconds(new Date(link.expire_in), new Date()), { + long: true + }) + : "" }, { withIds: true } ); @@ -189,9 +197,20 @@ const Row: FC = ({ index, link, setDeleteModal }) => { )} - {`${formatDistanceToNow( - new Date(link.created_at) - )} ago`} + + {formatDistanceToNow(new Date(link.created_at))} ago + {link.expire_in && ( + + Expires in{" "} + {ms( + differenceInMilliseconds(new Date(link.expire_in), new Date()), + { + long: true + } + )} + + )} + {copied ? ( = ({ index, link, setDeleteModal }) => { - + = ({ index, link, setDeleteModal }) => { /> + + + Expire in: + + + + +