aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/services/PreviewService.ts
blob: 769a1fcfb9f37c9431e2bc65f362a5cc67a78805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

// The preview service worker cache name (see webpack config)
const SWCacheName = 'previews'

/**
 * Check if the preview is already cached by the service worker
 * @param previewUrl
 */
export const isCachedPreview = function(previewUrl: string): Promise<boolean> {
	if (!window?.caches?.open) {
		return Promise.resolve(false)
	}

	return window?.caches?.open(SWCacheName)
		.then(function(cache) {
			return cache.match(previewUrl)
				.then(function(response) {
					return !!response
				})
		})
}