From 60607184d4f4f145795cf2782d17bf31fdc7b62c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 3 Feb 2021 13:53:41 +0200 Subject: [PATCH] feature(client) view: unknown file type: method: GET -> HEAD: speed up --- client/modules/view/types.js | 4 +++- client/modules/view/types.spec.js | 7 ++++++- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/modules/view/types.js b/client/modules/view/types.js index dd7888bb..c4cf5ce6 100644 --- a/client/modules/view/types.js +++ b/client/modules/view/types.js @@ -63,7 +63,9 @@ function isVideo(name) { module.exports._detectType = detectType; async function detectType(path) { - const {headers} = await fetch(path); + const {headers} = await fetch(path, { + method: 'HEAD', + }); for (const [name, value] of headers) { if (name === 'content-type') diff --git a/client/modules/view/types.spec.js b/client/modules/view/types.spec.js index d0e486f5..8df0c9da 100644 --- a/client/modules/view/types.spec.js +++ b/client/modules/view/types.spec.js @@ -27,8 +27,13 @@ test('cloudcmd: client: view: types: detectType', async (t) => { await _detectType('/hello'); global.fetch = originalFetch; + const expected = [ + '/hello', { + method: 'HEAD', + } + ]; - t.calledWith(fetch, ['/hello']); + t.calledWith(fetch, expected); t.end(); }); diff --git a/package.json b/package.json index 26814456..0e147979 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "putout": "^14.0.0", "redzip": "^1.6.4", "rendy": "^3.0.0", - "restafary": "^9.5.0", + "restafary": "^9.6.0", "restbox": "^3.0.0", "shortdate": "^2.0.0", "simport": "^1.0.1",