From 28fe6508e4138a60e7e7b7387f7ee55db5eeb32b Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 24 Nov 2024 23:00:41 +0100 Subject: [PATCH 1/2] Add Cache control header for cloudfare configs --- .../internal/remove-cache.spec.ts | 13 ++++++++++--- .../internal/remove-cache.ts | 5 +++-- .../modal-archive-synchronize-manually.spec.tsx | 5 ++++- .../organisms/modal-publish/modal-publish.tsx | 3 ++- .../export/export-interval-update.spec.ts | 17 +++++++++++++---- .../src/shared/export/export-interval-update.ts | 3 ++- .../clientapp/src/shared/fetch/cache-control.ts | 2 ++ 7 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 starsky/starsky/clientapp/src/shared/fetch/cache-control.ts diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.spec.ts b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.spec.ts index d84352d241..618b6c5b0d 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.spec.ts +++ b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.spec.ts @@ -3,6 +3,7 @@ import { PageType } from "../../../../interfaces/IDetailView"; import * as FetchGet from "../../../../shared/fetch/fetch-get"; import { FileListCache } from "../../../../shared/filelist-cache"; import { RemoveCache } from "./remove-cache"; +import { CacheControl } from "../../../../shared/fetch/cache-control.ts"; describe("RemoveCache function", () => { beforeEach(() => { @@ -33,7 +34,9 @@ describe("RemoveCache function", () => { .mockImplementationOnce(() => Promise.resolve({ statusCode: 200, data: null })); const parentFolder = "/parent"; RemoveCache(jest.fn(), parentFolder, "search", jest.fn(), jest.fn()); - expect(mockFetchGet).toHaveBeenCalledWith("/starsky/api/remove-cache?json=true&f=/parent"); + expect(mockFetchGet).toHaveBeenCalledWith("/starsky/api/remove-cache?json=true&f=/parent", { + CacheControl + }); expect(mockFetchGet.mock.calls[0][0]).toContain("/remove-cache"); expect(mockFetchGet.mock.calls[0][0]).toContain( "/starsky/api/remove-cache?json=true&f=/parent" @@ -50,7 +53,9 @@ describe("RemoveCache function", () => { const parent: string | undefined = undefined as unknown as string; RemoveCache(jest.fn(), parent, "search", jest.fn(), jest.fn()); - expect(mockFetchGet).toHaveBeenCalledWith("/starsky/api/remove-cache?json=true&f=/"); + expect(mockFetchGet).toHaveBeenCalledWith("/starsky/api/remove-cache?json=true&f=/", { + CacheControl + }); expect(mockFetchGet.mock.calls[0][0]).toContain("/remove-cache"); expect(mockFetchGet.mock.calls[0][0]).toContain("/starsky/api/remove-cache?json=true&f=/"); mockFetchGet.mockRestore(); @@ -67,7 +72,9 @@ describe("RemoveCache function", () => { jest.runAllTimers(); - expect(mockFetchGet).toHaveBeenCalledWith("/starsky/api/remove-cache?json=true&f=/parent"); + expect(mockFetchGet).toHaveBeenCalledWith("/starsky/api/remove-cache?json=true&f=/parent", { + CacheControl + }); mockFetchGet.mockRestore(); }); diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.ts b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.ts index c05288e65a..58af089cf6 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.ts +++ b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/internal/remove-cache.ts @@ -6,6 +6,7 @@ import FetchGet from "../../../../shared/fetch/fetch-get.ts"; import { FileListCache } from "../../../../shared/filelist-cache.ts"; import { URLPath } from "../../../../shared/url/url-path.ts"; import { UrlQuery } from "../../../../shared/url/url-query.ts"; +import { CacheControl } from "../../../../shared/fetch/cache-control.ts"; /** * Remove Folder cache @@ -20,7 +21,7 @@ export function RemoveCache( setIsLoading(true); new FileListCache().CacheCleanEverything(); const parentFolder = propsParentFolder ?? "/"; - FetchGet(new UrlQuery().UrlRemoveCache(new URLPath().encodeURI(parentFolder))) + FetchGet(new UrlQuery().UrlRemoveCache(new URLPath().encodeURI(parentFolder)), { CacheControl }) .then(() => { return new Promise((resolve) => { setTimeout(() => { @@ -31,7 +32,7 @@ export function RemoveCache( }); }) .then((url: string) => { - return FetchGet(url, { "Cache-Control": "no-store, max-age=0" }); + return FetchGet(url, { CacheControl }); }) .then((connectionResult) => { const removeCacheResult = new CastToInterface().MediaArchive(connectionResult.data); diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.spec.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.spec.tsx index 3f3bc11ec9..69ef3ba03f 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.spec.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-archive-synchronize-manually/modal-archive-synchronize-manually.spec.tsx @@ -5,6 +5,7 @@ import * as FetchPost from "../../../shared/fetch/fetch-post"; import { UrlQuery } from "../../../shared/url/url-query"; import * as Modal from "../../atoms/modal/modal"; import ModalArchiveSynchronizeManually from "./modal-archive-synchronize-manually"; +import { CacheControl } from "../../../shared/fetch/cache-control.ts"; describe("ModalArchiveSynchronizeManually", () => { beforeEach(() => { @@ -105,7 +106,9 @@ describe("ModalArchiveSynchronizeManually", () => { }); expect(fetchGetSpy).toHaveBeenCalled(); - expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlRemoveCache("/")); + expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlRemoveCache("/"), { + CacheControl + }); fetchGetSpy.mockReset(); }); diff --git a/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx b/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx index 4fb7bb85af..3f80507073 100644 --- a/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/modal-publish/modal-publish.tsx @@ -13,6 +13,7 @@ import { UrlQuery } from "../../../shared/url/url-query"; import FormControl from "../../atoms/form-control/form-control"; import Modal from "../../atoms/modal/modal"; import Select from "../../atoms/select/select"; +import { CacheControl } from "../../../shared/fetch/cache-control.ts"; interface IModalPublishProps { isOpen: boolean; @@ -97,7 +98,7 @@ const ModalPublish: React.FunctionComponent = (props) => { return; } - FetchGet(new UrlQuery().UrlPublishExist(toUpdateItemName)).then((result) => { + FetchGet(new UrlQuery().UrlPublishExist(toUpdateItemName), { CacheControl }).then((result) => { if (result.statusCode !== 200) return; setExistItemName(result.data); }); diff --git a/starsky/starsky/clientapp/src/shared/export/export-interval-update.spec.ts b/starsky/starsky/clientapp/src/shared/export/export-interval-update.spec.ts index c15b198251..5dacd02a6f 100644 --- a/starsky/starsky/clientapp/src/shared/export/export-interval-update.spec.ts +++ b/starsky/starsky/clientapp/src/shared/export/export-interval-update.spec.ts @@ -3,6 +3,7 @@ import * as FetchGet from "../fetch/fetch-get"; import { UrlQuery } from "../url/url-query"; import { ExportIntervalUpdate } from "./export-interval-update"; import { ProcessingState } from "./processing-state"; +import { CacheControl } from "../fetch/cache-control.ts"; describe("ExportIntervalUpdate", () => { it("ready", async () => { @@ -20,7 +21,9 @@ describe("ExportIntervalUpdate", () => { await ExportIntervalUpdate("test", setProcessingSpy); expect(fetchGetSpy).toHaveBeenCalled(); - expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true)); + expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true), { + CacheControl + }); expect(setProcessingSpy).toHaveBeenCalled(); expect(setProcessingSpy).toHaveBeenCalledWith(ProcessingState.ready); }); @@ -40,7 +43,9 @@ describe("ExportIntervalUpdate", () => { await ExportIntervalUpdate("test", setProcessingSpy); expect(fetchGetSpy).toHaveBeenCalled(); - expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true)); + expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true), { + CacheControl + }); expect(setProcessingSpy).toHaveBeenCalled(); expect(setProcessingSpy).toHaveBeenCalledWith(ProcessingState.fail); }); @@ -60,7 +65,9 @@ describe("ExportIntervalUpdate", () => { await ExportIntervalUpdate("test", setProcessingSpy); expect(fetchGetSpy).toHaveBeenCalled(); - expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true)); + expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true), { + CacheControl + }); expect(setProcessingSpy).toHaveBeenCalledTimes(0); }); @@ -79,7 +86,9 @@ describe("ExportIntervalUpdate", () => { await ExportIntervalUpdate("test", setProcessingSpy); expect(fetchGetSpy).toHaveBeenCalled(); - expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true)); + expect(fetchGetSpy).toHaveBeenCalledWith(new UrlQuery().UrlExportZipApi("test", true), { + CacheControl + }); expect(setProcessingSpy).toHaveBeenCalledTimes(0); }); }); diff --git a/starsky/starsky/clientapp/src/shared/export/export-interval-update.ts b/starsky/starsky/clientapp/src/shared/export/export-interval-update.ts index cb85b321ce..5980f49037 100644 --- a/starsky/starsky/clientapp/src/shared/export/export-interval-update.ts +++ b/starsky/starsky/clientapp/src/shared/export/export-interval-update.ts @@ -2,6 +2,7 @@ import { Dispatch } from "react"; import FetchGet from "../fetch/fetch-get"; import { UrlQuery } from "../url/url-query"; import { ProcessingState } from "./processing-state"; +import { CacheControl } from "../fetch/cache-control.ts"; export async function ExportIntervalUpdate( zipKey: string, @@ -9,7 +10,7 @@ export async function ExportIntervalUpdate( ) { // need to check if ProcessingState = server if (!zipKey) return; - const result = await FetchGet(new UrlQuery().UrlExportZipApi(zipKey, true)); + const result = await FetchGet(new UrlQuery().UrlExportZipApi(zipKey, true), { CacheControl }); switch (result.statusCode) { case 200: diff --git a/starsky/starsky/clientapp/src/shared/fetch/cache-control.ts b/starsky/starsky/clientapp/src/shared/fetch/cache-control.ts new file mode 100644 index 0000000000..a2739c8eb5 --- /dev/null +++ b/starsky/starsky/clientapp/src/shared/fetch/cache-control.ts @@ -0,0 +1,2 @@ +const cacheControlValue = "no-store, max-age=0"; +export const CacheControl = { "Cache-Control": cacheControlValue }; From eb460ddab1889aefb2625bbef9c19b77041ed0ed Mon Sep 17 00:00:00 2001 From: Dion van Velde Date: Mon, 25 Nov 2024 15:11:35 +0100 Subject: [PATCH 2/2] #1839 Update history.md --- history.md | 1 + 1 file changed, 1 insertion(+) diff --git a/history.md b/history.md index 8265967270..6a42946d2a 100644 --- a/history.md +++ b/history.md @@ -44,6 +44,7 @@ Semantic Versioning 2.0.0 is from version 0.1.6+ ## version 0.6.4 - _(Unreleased)_ - 2024-11-?? {#v0.6.3} - [x] (Fixed) _Back-end_ Notification duplicate error handling (Issue #1832) (PR #1834) +- [x] (Fixed) _Front-end_ Add cache headers for download publish for cloudfare (PR #1839) ## version 0.6.3 - 2024-11-14 {#v0.6.3}