Adding test as enpoint
This commit is contained in:
parent
cce8c794ad
commit
3e97877edd
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"cSpell.enabled": false
|
||||||
|
}
|
6
index.d.ts
vendored
6
index.d.ts
vendored
@ -17,7 +17,11 @@ export default class SecureFile {
|
|||||||
private PrivateKey;
|
private PrivateKey;
|
||||||
constructor(server: string, username: string, private_key: string);
|
constructor(server: string, username: string, private_key: string);
|
||||||
private getCode();
|
private getCode();
|
||||||
private makeRequest(endpoint, method, query, body);
|
private makeRequest(endpoint, method, query, body?);
|
||||||
|
test(): Promise<{
|
||||||
|
user: string;
|
||||||
|
test: true;
|
||||||
|
}>;
|
||||||
list(folder?: string): Promise<File[]>;
|
list(folder?: string): Promise<File[]>;
|
||||||
create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt?: boolean, preview?: Buffer): Promise<File>;
|
create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt?: boolean, preview?: Buffer): Promise<File>;
|
||||||
get(id: string, version?: string): Promise<Buffer>;
|
get(id: string, version?: string): Promise<Buffer>;
|
||||||
|
5
index.js
5
index.js
@ -29,6 +29,11 @@ class SecureFile {
|
|||||||
}
|
}
|
||||||
return await node_fetch_1.default(this.Server + endpoint + query_str, { method: method, body: body });
|
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) {
|
async list(folder) {
|
||||||
if (!folder)
|
if (!folder)
|
||||||
folder = "root";
|
folder = "root";
|
||||||
|
8
index.ts
8
index.ts
@ -33,7 +33,7 @@ export default class SecureFile {
|
|||||||
return { code: code, signature: r.sign(code).toString("base64") };
|
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();
|
let code = await this.getCode();
|
||||||
query.code = code.code;
|
query.code = code.code;
|
||||||
query.signature = code.signature;
|
query.signature = code.signature;
|
||||||
@ -47,6 +47,12 @@ export default class SecureFile {
|
|||||||
return await fetch(this.Server + endpoint + query_str, { method: method, body: body });
|
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<File[]> {
|
async list(folder?: string): Promise<File[]> {
|
||||||
if (!folder) folder = "root";
|
if (!folder) folder = "root";
|
||||||
let res = await this.makeRequest("/files", "GET", { folder: folder }, undefined)
|
let res = await this.makeRequest("/files", "GET", { folder: folder }, undefined)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "secure-file-wrapper",
|
"name": "secure-file-wrapper",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
8
test.js
8
test.js
@ -32,6 +32,13 @@ module.exports = {
|
|||||||
testver = res.version;
|
testver = res.version;
|
||||||
test.done();
|
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) {
|
get: async function (test) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
let res = await sf.get(testid);
|
let res = await sf.get(testid);
|
||||||
@ -43,7 +50,6 @@ module.exports = {
|
|||||||
test.expect(4);
|
test.expect(4);
|
||||||
let res = await sf.list();
|
let res = await sf.list();
|
||||||
test.ok(res);
|
test.ok(res);
|
||||||
console.log(res);
|
|
||||||
test.ok(Array.isArray(res), "Is from type Array");
|
test.ok(Array.isArray(res), "Is from type Array");
|
||||||
test.ok(res.length > 0, "Do elements exist?");
|
test.ok(res.length > 0, "Do elements exist?");
|
||||||
res.forEach(e => {
|
res.forEach(e => {
|
||||||
|
10
test.ts
10
test.ts
@ -51,6 +51,15 @@ module.exports = {
|
|||||||
testver = res.version;
|
testver = res.version;
|
||||||
test.done();
|
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) {
|
get: async function (test: TestType) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
let res = await sf.get(testid);
|
let res = await sf.get(testid);
|
||||||
@ -62,7 +71,6 @@ module.exports = {
|
|||||||
test.expect(4);
|
test.expect(4);
|
||||||
let res = await sf.list();
|
let res = await sf.list();
|
||||||
test.ok(res);
|
test.ok(res);
|
||||||
console.log(res);
|
|
||||||
test.ok(Array.isArray(res), "Is from type Array");
|
test.ok(Array.isArray(res), "Is from type Array");
|
||||||
test.ok(res.length > 0, "Do elements exist?")
|
test.ok(res.length > 0, "Do elements exist?")
|
||||||
res.forEach(e => {
|
res.forEach(e => {
|
||||||
|
Reference in New Issue
Block a user