소스 검색

Merge pull request #61 from dom111/feature/disable-head-requests

Feature/disable head requests
Dom Hastings 5 년 전
부모
커밋
acca7044d3
11개의 변경된 파일78개의 추가작업 그리고 21개의 파일을 삭제
  1. 0 5
      .github/workflows/build-on-push.yml
  2. 1 0
      .gitignore
  3. 0 0
      assets/css/style-min.css
  4. 1 1
      assets/css/style.css
  5. 12 1
      src/lib/DAV.js
  6. 3 1
      src/lib/UI/NativeDOM/List/Item.js
  7. 13 2
      src/lib/UI/UI.js
  8. 0 0
      src/webdav-min.js
  9. 4 2
      src/webdav.js
  10. 13 0
      tests/.eslintrc.json
  11. 31 9
      tests/unit/DAV.test.js

+ 0 - 5
.github/workflows/build-on-push.yml

@@ -13,8 +13,3 @@ jobs:
       - run: yarn install
       - run: yarn build
       - run: yarn test
-
-      - name: Commit changes
-        uses: dom111/actions-js-build/commit@master
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
+.idea
 node_modules
 *.log
 ~*

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
assets/css/style-min.css


+ 1 - 1
assets/css/style.css

@@ -140,7 +140,7 @@ pre[class*="language-"] {
   color: #999;
 }
 
-.namespace {
+.token.namespace {
   opacity: .7;
 }
 

+ 12 - 1
src/lib/DAV.js

@@ -4,6 +4,7 @@ import Response from './DAV/Response.js';
 import joinPath from './joinPath.js';
 
 export default class DAV extends EventObject {
+  #bypassCheck;
   #cache;
   #http;
 
@@ -44,9 +45,12 @@ export default class DAV extends EventObject {
     ;
   };
 
-  constructor(cache = new Map(), http = new HTTP()) {
+  constructor({
+    bypassCheck
+  }, cache = new Map(), http = new HTTP()) {
     super();
 
+    this.#bypassCheck = bypassCheck;
     this.#cache = cache;
     this.#http  = http;
 
@@ -62,6 +66,13 @@ export default class DAV extends EventObject {
   }
 
   async check(uri) {
+    if (this.#bypassCheck) {
+      return {
+        ok: true,
+        status: 200
+      };
+    }
+
     return this.#http.HEAD(uri);
   }
 

+ 3 - 1
src/lib/UI/NativeDOM/List/Item.js

@@ -172,7 +172,9 @@ export default class Item extends Element {
     this.loading();
 
     if (entry.directory) {
-      return this.trigger('go', entry.fullPath, false, () => this.loading(false));
+      return this.trigger('go', entry.fullPath, {
+        failure: () => this.loading(false)
+      });
     }
 
     const launchLightbox = (lightboxContent, onShow) => {

+ 13 - 2
src/lib/UI/UI.js

@@ -5,16 +5,27 @@ import Unimplemented from '../Unimplemented.js';
 export default class UI extends EventObject {
   #container;
   #dav;
+  #options;
 
-  constructor(container, dav = new DAV()) {
+  constructor(container, options, dav = new DAV({
+    bypassCheck: options.bypassCheck
+  })) {
     super();
 
     if (! (container instanceof HTMLElement)) {
       throw new TypeError(`Invalid container element: '${container}'.`);
     }
 
-    this.#dav       = dav;
     this.#container = container;
+    this.#dav       = dav;
+    this.#options   = options;
+  }
+
+  get options() {
+    // return a clone so these cannot be changed
+    return {
+      ...this.#options
+    };
   }
 
   get dav() {

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
src/webdav-min.js


+ 4 - 2
src/webdav.js

@@ -5,10 +5,12 @@ import 'webdav-js/assets/scss/style.scss';
 import 'whatwg-fetch'; // IE11 compatibility
 import NativeDOM from './lib/UI/NativeDOM.js';
 
-const ui = new NativeDOM(document.body);
+const ui = new NativeDOM(document.body, {
+  bypassCheck: !! document.querySelector('[data-disable-check]')
+});
 
 if (document.readyState === 'loading') {
-  window.addEventListener('DOMContentLoaded', () => ui.render());
+  document.addEventListener('DOMContentLoaded', () => ui.render());
 }
 else {
   ui.render();

+ 13 - 0
tests/.eslintrc.json

@@ -0,0 +1,13 @@
+{
+  "overrides": [
+    {
+      "files": ["*.js"],
+      "globals": {
+        "describe": false,
+        "expect": false,
+        "it": false,
+        "jasmine": false
+      }
+    }
+  ]
+}

+ 31 - 9
tests/unit/DAV.test.js

@@ -24,7 +24,7 @@ describe('DAV', () => {
 
   it('should fire a HEAD request on check', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP)
+      dav = new DAV({}, SpyCache, SpyHTTP)
     ;
 
     dav.check('/checkHeadRequest');
@@ -33,7 +33,7 @@ describe('DAV', () => {
 
   it('should fire a COPY request on copy', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP)
+      dav = new DAV({}, SpyCache, SpyHTTP)
     ;
 
     dav.copy('/copySource', '/copyDestination');
@@ -46,7 +46,7 @@ describe('DAV', () => {
 
   it('should fire a DELETE request on del', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP)
+      dav = new DAV({}, SpyCache, SpyHTTP)
     ;
 
     dav.del('/checkDeleteRequest');
@@ -55,7 +55,7 @@ describe('DAV', () => {
 
   it('should fire a GET request on get', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP)
+      dav = new DAV({}, SpyCache, SpyHTTP)
     ;
 
     dav.get('/checkGetRequest');
@@ -68,12 +68,12 @@ describe('DAV', () => {
           ok: true
         },
         PROPFIND: {
-            text: () => `<?xml version="1.0" encoding="utf-8"?><D:multistatus xmlns:D="DAV:"><D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"><D:href>/Directory%20name/</D:href><D:propstat><D:prop><lp1:resourcetype><D:collection/></lp1:resourcetype><lp1:creationdate>2019-11-06T16:29:46Z</lp1:creationdate><lp1:getlastmodified>Wed, 06 Nov 2019 16:29:46 GMT</lp1:getlastmodified><lp1:getetag>"6-596b00e926ba3"</lp1:getetag><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:lockdiscovery/><D:getcontenttype>httpd/unix-directory</D:getcontenttype></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>`
+          text: () => '<?xml version="1.0" encoding="utf-8"?><D:multistatus xmlns:D="DAV:"><D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"><D:href>/Directory%20name/</D:href><D:propstat><D:prop><lp1:resourcetype><D:collection/></lp1:resourcetype><lp1:creationdate>2019-11-06T16:29:46Z</lp1:creationdate><lp1:getlastmodified>Wed, 06 Nov 2019 16:29:46 GMT</lp1:getlastmodified><lp1:getetag>"6-596b00e926ba3"</lp1:getetag><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:lockdiscovery/><D:getcontenttype>httpd/unix-directory</D:getcontenttype></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>'
         }
       }, {
         get: false
       }),
-      dav = new DAV(SpyCache, SpyHTTP),
+      dav = new DAV({}, SpyCache, SpyHTTP),
       collection = await dav.list('/checkPropfindRequest')
     ;
 
@@ -86,7 +86,7 @@ describe('DAV', () => {
 
   it('should fire an MKCOL request on mkcol', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP)
+      dav = new DAV({}, SpyCache, SpyHTTP)
     ;
 
     dav.mkcol('/checkMkcolRequest');
@@ -95,8 +95,9 @@ describe('DAV', () => {
 
   it('should fire a MOVE request on move', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP)
+      dav = new DAV({}, SpyCache, SpyHTTP)
     ;
+
     dav.move('/moveSource', '/moveDestination');
 
     expect(SpyHTTP.MOVE).toHaveBeenCalledWith('/moveSource', {
@@ -108,7 +109,7 @@ describe('DAV', () => {
 
   it('should fire a PUT request on upload', () => {
     const [SpyHTTP, SpyCache] = getSpies(),
-      dav = new DAV(SpyCache, SpyHTTP),
+      dav = new DAV({}, SpyCache, SpyHTTP),
       file = new File([''], 'uploadTest', {
         type: 'text/plain'
       })
@@ -122,4 +123,25 @@ describe('DAV', () => {
       body: file
     });
   });
+
+  it('should not fire a HEAD request on list when `bypassCheck` is set', async () => {
+    const [SpyHTTP, SpyCache] = getSpies({
+        HEAD: {
+          ok: true
+        },
+        PROPFIND: {
+          text: () => '<?xml version="1.0" encoding="utf-8"?><D:multistatus xmlns:D="DAV:"><D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"><D:href>/Directory%20name/</D:href><D:propstat><D:prop><lp1:resourcetype><D:collection/></lp1:resourcetype><lp1:creationdate>2019-11-06T16:29:46Z</lp1:creationdate><lp1:getlastmodified>Wed, 06 Nov 2019 16:29:46 GMT</lp1:getlastmodified><lp1:getetag>"6-596b00e926ba3"</lp1:getetag><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:lockdiscovery/><D:getcontenttype>httpd/unix-directory</D:getcontenttype></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>'
+        }
+      }, {
+        get: false
+      }),
+      dav = new DAV({
+        bypassCheck: true
+      }, SpyCache, SpyHTTP)
+    ;
+
+    await dav.list('/checkPropfindRequest');
+
+    expect(SpyHTTP.HEAD).not.toHaveBeenCalledWith('/checkPropfindRequest/');
+  });
 });

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.