mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: bug fix
This commit is contained in:
1 parent
273a0563b3
commit
60820a3e5f
7 files changed
+15
-12
No files matched your search
@@ -7,7 +7,7 @@ const diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions = {
|
||||
noSyntaxValidation: false,
|
||||
noSuggestionDiagnostics: true,
|
||||
};
|
||||
const compilerOptions = {
|
||||
const compilerOptions: monaco.languages.typescript.CompilerOptions = {
|
||||
target: monaco.languages.typescript.ScriptTarget.ES2020,
|
||||
module: monaco.languages.typescript.ModuleKind.ESNext,
|
||||
allowNonTsExtensions: true,
|
||||
|
||||
@@ -135,7 +135,7 @@ export async function previewFile(ev, type = '') {
|
||||
if (ext === 'pdf') return previewPDF(`${link}${link.includes('?') ? '&' : '?'}noDisposition=1`);
|
||||
Notification.info(i18n('Loading file...'));
|
||||
try {
|
||||
const { url } = await request.get(link);
|
||||
const { url } = await request.get(link, {}, { headers: { 'Do-Not-Cache': 'on' } });
|
||||
if (/^(doc|xls|ppt)x?$/.test(ext)) return previewOffice(link, url);
|
||||
content = await request.get(url, undefined, { dataType: 'text' });
|
||||
} catch (e) {
|
||||
|
||||
@@ -21,9 +21,11 @@ self.addEventListener('notificationclick', (event) => {
|
||||
const PRECACHE = `precache-${process.env.VERSION}`;
|
||||
const DO_NOT_CACHE = ['vditor', '.worker.js', 'fonts', 'i.monaco'];
|
||||
|
||||
function shouldCache(name: string) {
|
||||
function shouldCache(name: string, request?: Request) {
|
||||
if (!name.split('/').pop()) return false;
|
||||
if (!name.split('/').pop().includes('.')) return false;
|
||||
// For files download, a response is formatted as string
|
||||
if (request && request.headers.get('Do-Not-Cache')) return false;
|
||||
return true;
|
||||
}
|
||||
function shouldPreCache(name: string) {
|
||||
@@ -86,21 +88,22 @@ self.addEventListener('activate', (event) => {
|
||||
|
||||
self.addEventListener('fetch', (event: FetchEvent) => {
|
||||
if (!['get', 'head'].includes(event.request.method.toLowerCase())) return;
|
||||
if (!shouldCache(event.request.url) && config?.base && config?.targets?.length) {
|
||||
if (!shouldCache(event.request.url, event.request) && config?.base && config?.targets?.length) {
|
||||
if (new URL(event.request.url).origin !== location.origin) return;
|
||||
event.respondWith(get(event.request.url));
|
||||
return;
|
||||
}
|
||||
// Only handle whitelisted origins;
|
||||
if (!config?.hosts?.some((i) => event.request.url.startsWith(i))) return;
|
||||
if (process.env.NODE_ENV !== 'production' || !shouldCache(event.request.url)) return;
|
||||
if (!shouldCache(event.request.url, event.request)) return;
|
||||
const Accept = event.request.headers.get('Accept');
|
||||
event.respondWith((async () => {
|
||||
const cachedResponse = await caches.match(event.request.url);
|
||||
if (cachedResponse) return cachedResponse;
|
||||
console.log(`Caching ${event.request.url}`);
|
||||
const [cache, response] = await Promise.all([
|
||||
caches.open(PRECACHE),
|
||||
fetch(event.request.url), // Fetch from url to prevent opaque response
|
||||
fetch(event.request.url, { headers: { Accept } }), // Fetch from url to prevent opaque response
|
||||
]);
|
||||
if (response.ok) {
|
||||
cache.put(event.request.url, response.clone());
|
||||
|
||||
Reference in new issue
Block a user