Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seafile fix #110

Merged
merged 4 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions source/interface/dav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
const path = require("path");
const xml2js = require("xml2js");

const DAV_KEY_PREFIXES = ["", "d:", "D:", "lp1:"];

function generateKeysForName(name) {
return DAV_KEY_PREFIXES.map(function __mapKeyName(prefix) {
return prefix + name;
function findKey(baseKey, obj) {
return Object.keys(obj).find(function __findBaseKey(itemKey) {
const match = /^[a-z0-9]+:(.+)$/i.exec(itemKey);
return match ? match[1] === baseKey : itemKey === baseKey;
});
}

Expand All @@ -18,11 +17,9 @@ function getSingleValue(item) {
function getValueForKey(key, obj) {
let keys, i, keyCount;
if (typeof obj === "object") {
keys = generateKeysForName(key);
for (i = 0, keyCount = keys.length; i < keyCount; i += 1) {
if (typeof obj[keys[i]] !== "undefined") {
return obj[keys[i]];
}
const actualKey = findKey(key, obj);
if (actualKey && typeof obj[actualKey] !== "undefined") {
return obj[actualKey];
}
}
return undefined;
Expand Down
66 changes: 66 additions & 0 deletions test/responses/seafile-propfind.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version='1.0' encoding='UTF-8'?>
<ns0:multistatus xmlns:ns0="DAV:">
<ns0:response>
<ns0:href>/seafdav/</ns0:href>
<ns0:propstat>
<ns0:prop>
<ns0:resourcetype>
<ns0:collection />
</ns0:resourcetype>
<ns0:displayname />
<ns0:lockdiscovery />
<ns0:supportedlock>
<ns0:lockentry>
<ns0:lockscope>
<ns0:exclusive />
</ns0:lockscope>
<ns0:locktype>
<ns0:write />
</ns0:locktype>
</ns0:lockentry>
<ns0:lockentry>
<ns0:lockscope>
<ns0:shared />
</ns0:lockscope>
<ns0:locktype>
<ns0:write />
</ns0:locktype>
</ns0:lockentry>
</ns0:supportedlock>
</ns0:prop>
<ns0:status>HTTP/1.1 200 OK</ns0:status>
</ns0:propstat>
</ns0:response>
<ns0:response>
<ns0:href>/seafdav/Ma%20biblioth%C3%A8que/</ns0:href>
<ns0:propstat>
<ns0:prop>
<ns0:resourcetype>
<ns0:collection />
</ns0:resourcetype>
<ns0:displayname>Ma bibliothèque</ns0:displayname>
<ns0:getetag>2920f985ebc6692632c7c3ab46b3919556239d37</ns0:getetag>
<ns0:lockdiscovery />
<ns0:supportedlock>
<ns0:lockentry>
<ns0:lockscope>
<ns0:exclusive />
</ns0:lockscope>
<ns0:locktype>
<ns0:write />
</ns0:locktype>
</ns0:lockentry>
<ns0:lockentry>
<ns0:lockscope>
<ns0:shared />
</ns0:lockscope>
<ns0:locktype>
<ns0:write />
</ns0:locktype>
</ns0:lockentry>
</ns0:supportedlock>
</ns0:prop>
<ns0:status>HTTP/1.1 200 OK</ns0:status>
</ns0:propstat>
</ns0:response>
</ns0:multistatus>
37 changes: 37 additions & 0 deletions test/specs/getDirectoryContents.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const fs = require("fs");
const path = require("path");

function useSeafileResponse() {
returnFakeResponse(fs.readFileSync(path.resolve(__dirname, "../responses/seafile-propfind.xml"), "utf8"));
}

describe("getDirectoryContents", function() {
beforeEach(function() {
this.client = createWebDAVClient(
Expand Down Expand Up @@ -100,4 +107,34 @@ describe("getDirectoryContents", function() {
expect(contents[0].basename).to.equal("file2.txt");
});
});

describe("when connected to Seafile server", function() {
beforeEach(function() {
this.client = createWebDAVClient(
"https://cloud.ascal-strasbg.fr/seafdav",
createWebDAVServer.test.username,
createWebDAVServer.test.password
);
useSeafileResponse();
});

afterEach(function() {
restoreFetch();
});

it("returns the correct response", function() {
return this.client.getDirectoryContents("/").then(function(contents) {
expect(contents).to.be.an("array");
expect(contents).to.deep.equal([
{
filename: "/Ma bibliothèque",
basename: "Ma bibliothèque",
lastmod: undefined,
size: 0,
type: "directory"
}
]);
});
});
});
});