diff --git a/backend/src/main/java/com/github/binpastes/paste/api/PasteController.java b/backend/src/main/java/com/github/binpastes/paste/api/PasteController.java index be1fabb..7a6f5ed 100644 --- a/backend/src/main/java/com/github/binpastes/paste/api/PasteController.java +++ b/backend/src/main/java/com/github/binpastes/paste/api/PasteController.java @@ -18,20 +18,14 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.support.WebExchangeBindException; import org.springframework.web.server.ResponseStatusException; import reactor.core.publisher.Mono; +import java.time.Duration; +import java.time.LocalDateTime; + import static com.github.binpastes.paste.api.model.ListView.ListItemView; @RestController @@ -55,6 +49,16 @@ public Mono findPaste(@PathVariable("pasteId") String pasteId, Serve .doOnNext(paste -> { if (paste.isOneTime()) { response.getHeaders().add(HttpHeaders.CACHE_CONTROL, "no-store"); + } else { + if (paste.getDateOfExpiry() != null ) { + var in5min = LocalDateTime.now().plusMinutes(5); + if (in5min.isAfter(paste.getDateOfExpiry())) { + response.getHeaders().add(HttpHeaders.CACHE_CONTROL, "max-age=" + Duration.between(LocalDateTime.now(), paste.getDateOfExpiry()).toSeconds()); + return; + } + } + + response.getHeaders().add(HttpHeaders.CACHE_CONTROL, "max-age=300"); } }) .map(reference -> SingleView.from(reference, remoteAddress(request))) diff --git a/frontend/index.html b/frontend/index.html index 015844b..713ddcc 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -8,7 +8,7 @@ - + diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5ec1e08..9d3fc62 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -5,10 +5,10 @@ import Footer from './components/Footer/Footer'; import Header from './components/Header/Header'; import RecentPastes from './components/RecentPastes/RecentPastes'; import Create from './pages/Create'; -import Read from './pages/Read'; -import Search from './pages/Search'; -const NotFound = lazy(() => import("./pages/404")); +const Read = lazy(() => import('./pages/Read')); +const Search = lazy(() => import('./pages/Search')); +const NotFound = lazy(() => import('./pages/404')); const App: () => JSX.Element = () => { return ( diff --git a/frontend/src/api/model/PasteCreateCmd.ts b/frontend/src/api/model/PasteCreateCmd.ts index b3e7ee7..6cadbd2 100644 --- a/frontend/src/api/model/PasteCreateCmd.ts +++ b/frontend/src/api/model/PasteCreateCmd.ts @@ -1,5 +1,5 @@ -export interface PasteCreateCmd { +export type PasteCreateCmd = { title?: string content: string isEncrypted?: boolean diff --git a/frontend/src/api/model/PasteListView.ts b/frontend/src/api/model/PasteListView.ts index b52a8cc..4ef1f6c 100644 --- a/frontend/src/api/model/PasteListView.ts +++ b/frontend/src/api/model/PasteListView.ts @@ -1,5 +1,5 @@ -export interface PasteListView { +export type PasteListView = { id: string title?: string sizeInBytes: number @@ -8,6 +8,6 @@ export interface PasteListView { dateOfExpiry?: string } -export interface PasteList { +export type = PasteList { pastes: Array } diff --git a/frontend/src/api/model/PasteView.ts b/frontend/src/api/model/PasteView.ts index eca5d45..0705723 100644 --- a/frontend/src/api/model/PasteView.ts +++ b/frontend/src/api/model/PasteView.ts @@ -1,5 +1,5 @@ -export interface PasteView { +export type PasteView = { id: string title?: string content: string diff --git a/frontend/src/components/CreatePaste/CreatePaste.tsx b/frontend/src/components/CreatePaste/CreatePaste.tsx index 56e44ed..a238e76 100644 --- a/frontend/src/components/CreatePaste/CreatePaste.tsx +++ b/frontend/src/components/CreatePaste/CreatePaste.tsx @@ -5,17 +5,21 @@ import {encrypt} from "../../crypto/CryptoUtil"; import {Copy} from '../../assets/Vectors'; import styles from "./createPaste.module.css"; -export interface PasteClone { +export type PasteClone = { title?: string content: string } -interface CreatePasteProps { +type CreatePasteProps = { onCreatePaste: (paste: PasteCreateCmd) => Promise initialPaste?: PasteClone } -interface FormModel extends Omit { +type FormModel = { + title?: string + content: string + expiry?: 'ONE_HOUR' | 'ONE_DAY' | 'ONE_WEEK' | 'ONE_MONTH' | 'THREE_MONTHS' | 'ONE_YEAR' | 'NEVER' + exposure?: 'PUBLIC' | 'UNLISTED' | 'ONCE' password: string } diff --git a/frontend/src/components/Footer/Footer.tsx b/frontend/src/components/Footer/Footer.tsx index 7dba624..e6d9f6b 100644 --- a/frontend/src/components/Footer/Footer.tsx +++ b/frontend/src/components/Footer/Footer.tsx @@ -1,10 +1,9 @@ import {JSX} from 'solid-js'; const Footer: () => JSX.Element = () => { - return (
- © 2023 + © {new Date().getFullYear()}
) } diff --git a/frontend/src/components/Header/Header.tsx b/frontend/src/components/Header/Header.tsx index 8379691..9db47f9 100644 --- a/frontend/src/components/Header/Header.tsx +++ b/frontend/src/components/Header/Header.tsx @@ -2,7 +2,6 @@ import {A} from '@solidjs/router'; import {JSX} from 'solid-js'; const Header: () => JSX.Element = () => { - return (

BinPastes

diff --git a/frontend/src/components/ReadPaste/ReadPaste.tsx b/frontend/src/components/ReadPaste/ReadPaste.tsx index fc1cea7..21c7832 100644 --- a/frontend/src/components/ReadPaste/ReadPaste.tsx +++ b/frontend/src/components/ReadPaste/ReadPaste.tsx @@ -1,12 +1,12 @@ +import {Component, createEffect, createSignal, JSX, lazy, on, Show} from 'solid-js'; import linkifyElement from 'linkify-element'; -import {Component, createEffect, createSignal, JSX, on, Show} from 'solid-js'; import {PasteView} from '../../api/model/PasteView'; import {decrypt} from '../../crypto/CryptoUtil'; import {relativeDiffLabel, toDateString, toDateTimeString} from '../../datetime/DateTimeUtil'; import {Lock, Unlock, Key, Trash, Copy} from '../../assets/Vectors'; import styles from './readPaste.module.css'; -interface ReadPasteProps { +type ReadPasteProps = { paste: PasteView onClonePaste: () => void onDeletePaste: () => void diff --git a/frontend/src/pages/404.tsx b/frontend/src/pages/404.tsx index 64d74ce..3165ff6 100644 --- a/frontend/src/pages/404.tsx +++ b/frontend/src/pages/404.tsx @@ -2,7 +2,6 @@ import {A} from '@solidjs/router'; import {JSX} from 'solid-js'; const NotFound: () => JSX.Element = () => { - return (

404 Nothing around here :(

diff --git a/frontend/src/pages/Search.tsx b/frontend/src/pages/Search.tsx index 069d1e9..860a2b1 100644 --- a/frontend/src/pages/Search.tsx +++ b/frontend/src/pages/Search.tsx @@ -1,7 +1,6 @@ import {JSX} from 'solid-js'; const Search: () => JSX.Element = () => { - return ( <>

Search