Skip to content

Commit

Permalink
Apply previous check fixes I've made
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 17, 2024
1 parent f0474ef commit 308ff23
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 25 deletions.
21 changes: 13 additions & 8 deletions src/api/session.js → src/api/session.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) => {
Expand All @@ -55,6 +56,11 @@ session.interceptors.response.use(

const CACHE_LIMIT = 50;

export interface SessionCache {
cached: any[];
cachedByUrl: Record<string, any>;
}

export class SessionCache {
constructor() {
this.cached = [];
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 9 additions & 2 deletions src/api/types/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +26,7 @@ export interface Document {
asset_url: string;
canonical_url: string;
created_at: string;
data: Record<string, unknown>;
data: Record<string, string[]>;
description: string;
edit_access: boolean;
file_hash: string;
Expand All @@ -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;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/common/ProgressiveImage.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { onMount, onDestroy, createEventDispatcher } from "svelte";
import { IMAGE_WIDTHS } from "../config/config.js";
import { pageImageUrl } from "@/api/viewer.js";
import { pageImageUrl } from "@/api/viewer";
import { timeout } from "@/util/timeout.js";
const dispatch = createEventDispatcher();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/app/Document.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import closeSimpleSvg from "@/assets/close_inline.svg?raw";
import pencilSvg from "@/assets/pencil.svg?raw";
import { pageImageUrl } from "@/api/viewer.js";
import { pageImageUrl } from "@/api/viewer";
import RevisionIcon from "../../common/RevisionIcon.svelte";
export let document;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/embed/note/Note.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { onMount, tick } from "svelte";
import { getAnnotation } from "@/api/annotation.js";
import { getDocument } from "@/api/document.js";
import { pageImageUrl } from "@/api/viewer.js";
import { pageImageUrl } from "@/api/viewer";
import { embedUrl } from "@/api/embed.js";
import {
currentUrl,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/embed/page/Page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { informSize } from "@/embed/iframeSizer.js";
import { getDocument } from "@/api/document.js";
import { getAnnotations } from "@/api/annotation.js";
import { textUrl, pageImageUrl } from "@/api/viewer.js";
import { textUrl, pageImageUrl } from "@/api/viewer";
import { embedUrl } from "@/api/embed.js";
import { APP_URL, DC_BASE } from "../../../config/config.js";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/entities/Entities.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { router } from "@/router/router.js";
import { getDocument } from "@/api/document.js";
import { extractEntities } from "@/api/entity.js";
import { jsonUrl } from "@/api/viewer.js";
import { jsonUrl } from "@/api/viewer";
import session from "@/api/session.js";
import { entities, getE } from "@/entities/entities.js";
import { updateInCollection } from "@/manager/documents.js";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/AllText.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import TextPage from "./TextPage.svelte";
import session from "@/api/session.js";
import { jsonUrl } from "@/api/viewer.js";
import { jsonUrl } from "@/api/viewer";
import { doc } from "@/viewer/document.js";
import { layout } from "@/viewer/layout.js";
import { viewer } from "@/viewer/viewer.js";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/InternalPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ProgressiveImage from "@/common/ProgressiveImage.svelte";
import session from "@/api/session.js";
import { selectableTextUrl } from "@/api/viewer.js";
import { selectableTextUrl } from "@/api/viewer";
import { doc, showAnnotation } from "@/viewer/document.js";
import { layout } from "@/viewer/layout.js";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/ModifyImage.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import Image from "@/common/Image.svelte";
import { viewer } from "@/viewer/viewer.js";
import { pageImageUrl } from "@/api/viewer.js";
import { pageImageUrl } from "@/api/viewer";
import { modification } from "@/viewer/modification/modification.js";
import { getDocument } from "@/api/document.js";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/SearchResults.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { layout } from "@/viewer/layout.js";
import { viewer } from "@/viewer/viewer.js";
import { doc, changeMode, restorePosition } from "@/viewer/document.js";
import { selectableTextUrl } from "@/api/viewer.js";
import { selectableTextUrl } from "@/api/viewer";
import session from "@/api/session.js";
async function handlePage(page) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import AccessIcon from "../../common/AccessIcon.svelte";
import HtmlField from "../../common/HtmlField.svelte";
import session from "../../api/session.js";
import { jsonUrl } from "../../api/viewer.js";
import { jsonUrl } from "../../api/viewer";
import {
enterRedactMode,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/Viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
} from "@/viewer/layout.js";
import { doc, showAnnotation } from "@/viewer/document.js";
import { viewer } from "@/viewer/viewer.js";
import { pageImageUrl } from "@/api/viewer.js";
import { pageImageUrl } from "@/api/viewer";
let shareOption = null;
Expand Down
1 change: 1 addition & 0 deletions src/routes/(embed)/stories/note-embed.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import document from "$lib/api/fixtures/documents/document-expanded.json";
import note from "$lib/api/fixtures/notes/note-expanded.json";
import notes from "$lib/api/fixtures/notes/notes-expanded.json";
import type { SvelteComponent } from "svelte";
export const meta = {
title: "Embed / Note",
Expand Down
4 changes: 1 addition & 3 deletions src/routes/(embed)/stories/page-embed.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import { Story } from "@storybook/addon-svelte-csf";
import PageEmbed from "../documents/[id]/pages/[page]/+page.svelte";
import document from "$lib/api/fixtures/documents/document-expanded.json";
import { results } from "$lib/api/fixtures/notes/notes-expanded.json";
const page = 1;
Expand All @@ -21,7 +19,7 @@
};
const data = {
document: document as Document,
document: document as unknown as Document,
page,
notes: notes as Note[],
embed: false,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/documents/[id]-[slug]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Sections from "./sidebar/Sections.svelte";
import { embedUrl } from "@/api/embed";
import { pageImageUrl } from "@/api/viewer.js";
import { pageImageUrl } from "@/api/viewer";
import { canonicalUrl } from "@/lib/api/documents";
export let data;
Expand Down
76 changes: 76 additions & 0 deletions src/test/fixtures/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,3 +1267,79 @@ export const documentsList: Page<Document> = {
},
],
};

export const documentExpanded: Document = {
id: 2622,
access: "public",
admin_noindex: false,
asset_url: "https://s3.documentcloud.org/",
canonical_url:
"https://www.documentcloud.org/documents/2622-agreement-between-conservatives-and-liberal-democrats-to-form-a-coalition-government",
created_at: "2010-05-12T15:44:15.278766Z",
data: {},
description:
"<p>This agreement between Conservatives and Liberal Democrats makes David Cameron the new prime minister and installs Nick Clegg, whose party came in third in last week's election, as his deputy. The document details the long list of compromises between the two parties, who don't share much in terms of ideology but need each other to form a government.</p>\n\n<p>Here, the NewsHour's Simon Marks reads between the lines to explain who won which battles and what each side is giving up.</p>",
edit_access: false,
file_hash: "",
noindex: false,
language: "eng",
organization: {
id: 60,
avatar_url: "",
individual: false,
name: "NewsHour",
slug: "newshour",
uuid: "23f98aa7-92d4-4edb-bf18-ccf362b29bdf",
},
original_extension: "pdf",
page_count: 7,
page_spec: "595.0x842.0:0-6",
projects: [
{
id: 200,
created_at: "2020-09-25T13:59:43.519966Z",
description: "",
edit_access: false,
add_remove_access: false,
private: false,
slug: "british-election",
title: "British Election",
updated_at: "2020-09-25T13:59:43.526790Z",
user: 126,
},
{
id: 6909,
created_at: "2020-10-28T17:41:54.481623Z",
description: "Documents to use for testing",
edit_access: false,
add_remove_access: false,
private: false,
slug: "test-project",
title: "Test project",
updated_at: "2024-02-14T15:31:38.770237Z",
user: 1020,
},
],
publish_at: null,
published_url: "",
related_article:
"http://www.pbs.org/newshour/rundown/2010/05/the-conservative-libdem-agreement-reading-between-the-lines.html",
revision_control: false,
slug: "agreement-between-conservatives-and-liberal-democrats-to-form-a-coalition-government",
source: "",
status: "success",
title:
"Agreement between Conservatives and Liberal Democrats to form a Coalition Government",
updated_at: "2024-02-14T15:32:52.849946Z",
user: {
id: 126,
avatar_url: "",
name: "Chris Amico",
organization: 14187,
organizations: [14187],
admin_organizations: [14187],
username: "ChrisAmico_lSozDZNW",
uuid: "caea06a2-ee1c-43e6-865a-a09078522bf1",
verified_journalist: true,
},
};
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default defineConfig({
],
environment: "jsdom",
coverage: {
provider: "v8",
include: ["src/lib/**", "src/routes/**"],
exclude: ["src/**/*.stories.@(js|jsx|ts|tsx|svelte)"],
reporter: ["text", "html", "lcov", "clover", "json", "json-summary"],
Expand Down

0 comments on commit 308ff23

Please sign in to comment.