diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..200dfb3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.enabled": false +} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 9e0fc94..b272df8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,7 +17,11 @@ export default class SecureFile { private PrivateKey; constructor(server: string, username: string, private_key: string); private getCode(); - private makeRequest(endpoint, method, query, body); + private makeRequest(endpoint, method, query, body?); + test(): Promise<{ + user: string; + test: true; + }>; list(folder?: string): Promise; create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt?: boolean, preview?: Buffer): Promise; get(id: string, version?: string): Promise; diff --git a/index.js b/index.js index 88709d4..8c1630a 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,11 @@ class SecureFile { } return await node_fetch_1.default(this.Server + endpoint + query_str, { method: method, body: body }); } + async test() { + let res = await this.makeRequest("/test", "GET", {}, undefined); + statusParser(res); + return await res.json(); + } async list(folder) { if (!folder) folder = "root"; diff --git a/index.ts b/index.ts index 379d53d..50b2dfe 100644 --- a/index.ts +++ b/index.ts @@ -33,7 +33,7 @@ export default class SecureFile { return { code: code, signature: r.sign(code).toString("base64") }; } - private async makeRequest(endpoint: string, method: "POST" | "GET" | "PUT" | "DELETE", query: any, body: Buffer) { + private async makeRequest(endpoint: string, method: "POST" | "GET" | "PUT" | "DELETE", query: any, body?: Buffer) { let code = await this.getCode(); query.code = code.code; query.signature = code.signature; @@ -47,6 +47,12 @@ export default class SecureFile { return await fetch(this.Server + endpoint + query_str, { method: method, body: body }); } + async test(): Promise<{ user: string, test: true }> { + let res = await this.makeRequest("/test", "GET", {}, undefined); + statusParser(res); + return await res.json(); + } + async list(folder?: string): Promise { if (!folder) folder = "root"; let res = await this.makeRequest("/files", "GET", { folder: folder }, undefined) diff --git a/package.json b/package.json index 3b3d165..30a7b55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "secure-file-wrapper", - "version": "1.0.1", + "version": "1.0.2", "main": "index.js", "author": "Fabian Stamm ", "license": "MIT", diff --git a/test.js b/test.js index e54944e..2d925a0 100644 --- a/test.js +++ b/test.js @@ -32,6 +32,13 @@ module.exports = { testver = res.version; test.done(); }, + test: async function (test) { + test.expect(2); + let res = await sf.test(); + test.ok(res.test); + test.equal(res.user, "test"); + test.done(); + }, get: async function (test) { test.expect(2); let res = await sf.get(testid); @@ -43,7 +50,6 @@ module.exports = { test.expect(4); let res = await sf.list(); test.ok(res); - console.log(res); test.ok(Array.isArray(res), "Is from type Array"); test.ok(res.length > 0, "Do elements exist?"); res.forEach(e => { diff --git a/test.ts b/test.ts index 7e318c1..76362d1 100644 --- a/test.ts +++ b/test.ts @@ -51,6 +51,15 @@ module.exports = { testver = res.version; test.done(); }, + + test: async function (test: TestType) { + test.expect(2); + let res = await sf.test(); + test.ok(res.test); + test.equal(res.user, "test"); + test.done() + }, + get: async function (test: TestType) { test.expect(2); let res = await sf.get(testid); @@ -62,7 +71,6 @@ module.exports = { test.expect(4); let res = await sf.list(); test.ok(res); - console.log(res); test.ok(Array.isArray(res), "Is from type Array"); test.ok(res.length > 0, "Do elements exist?") res.forEach(e => {