From 308ff23ac03dcdcd5b221a0a997b47dc25b21582 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Wed, 17 Apr 2024 09:02:56 -0400 Subject: [PATCH] Apply previous check fixes I've made --- src/api/{session.js => session.ts} | 21 +++-- src/api/types/document.ts | 11 ++- src/api/{viewer.js => viewer.ts} | 0 src/common/ProgressiveImage.svelte | 2 +- src/pages/app/Document.svelte | 2 +- src/pages/embed/note/Note.svelte | 2 +- src/pages/embed/page/Page.svelte | 2 +- src/pages/entities/Entities.svelte | 2 +- src/pages/viewer/AllText.svelte | 2 +- src/pages/viewer/InternalPage.svelte | 2 +- src/pages/viewer/ModifyImage.svelte | 2 +- src/pages/viewer/SearchResults.svelte | 2 +- src/pages/viewer/Sidebar.svelte | 2 +- src/pages/viewer/Viewer.svelte | 2 +- .../(embed)/stories/note-embed.stories.svelte | 1 + .../(embed)/stories/page-embed.stories.svelte | 4 +- .../documents/[id]-[slug]/+layout.svelte | 2 +- src/test/fixtures/documents.ts | 76 +++++++++++++++++++ vite.config.js | 1 + 19 files changed, 113 insertions(+), 25 deletions(-) rename src/api/{session.js => session.ts} (88%) rename src/api/{viewer.js => viewer.ts} (100%) diff --git a/src/api/session.js b/src/api/session.ts similarity index 88% rename from src/api/session.js rename to src/api/session.ts index 110cfeac6..3ed07a6e6 100644 --- a/src/api/session.js +++ b/src/api/session.ts @@ -1,4 +1,4 @@ -import axios from "axios"; +import axios, { type AxiosInstance } from "axios"; import axiosRetry from "axios-retry"; import { DC_BASE } from "../config/config.js"; @@ -30,11 +30,12 @@ export function getCsrfToken() { return token; } -const session = axios.create({ - xsrfCookieName: CSRF_COOKIE_NAME, - xsrfHeaderName: CSRF_HEADER_NAME, - withCredentials: cookiesEnabled, -}); +const session: AxiosInstance & { getStatic?: (url: string) => any } = + axios.create({ + xsrfCookieName: CSRF_COOKIE_NAME, + xsrfHeaderName: CSRF_HEADER_NAME, + withCredentials: cookiesEnabled, + }); session.interceptors.response.use( (response) => { @@ -55,6 +56,11 @@ session.interceptors.response.use( const CACHE_LIMIT = 50; +export interface SessionCache { + cached: any[]; + cachedByUrl: Record; +} + export class SessionCache { constructor() { this.cached = []; @@ -86,8 +92,7 @@ export class SessionCache { const sessionCache = new SessionCache(); -// @ts-ignore -session.getStatic = async function getStatic(url) { +session.getStatic = async function getStatic(url: string) { if (sessionCache.has(url)) { return sessionCache.lookup(url); } diff --git a/src/api/types/document.ts b/src/api/types/document.ts index 0f03fc923..ec6a85949 100644 --- a/src/api/types/document.ts +++ b/src/api/types/document.ts @@ -4,6 +4,13 @@ import type { Project } from "./project"; export type DocumentAccess = "public" | "organization" | "private"; +export type DocumentStatus = + | "success" + | "readable" + | "pending" + | "error" + | "nofile"; + export interface DocumentRevision { version: number; user: number; @@ -19,7 +26,7 @@ export interface Document { asset_url: string; canonical_url: string; created_at: string; - data: Record; + data: Record; description: string; edit_access: boolean; file_hash: string; @@ -39,7 +46,7 @@ export interface Document { revisions?: DocumentRevision[]; slug: string; source: string; - status: "success" | "failure" | "queued" | "in_progress"; + status: DocumentStatus; title: string; updated_at: string; user: User | number; diff --git a/src/api/viewer.js b/src/api/viewer.ts similarity index 100% rename from src/api/viewer.js rename to src/api/viewer.ts diff --git a/src/common/ProgressiveImage.svelte b/src/common/ProgressiveImage.svelte index c7dc18c34..3f54d6890 100644 --- a/src/common/ProgressiveImage.svelte +++ b/src/common/ProgressiveImage.svelte @@ -1,7 +1,7 @@