forked from hibas123/SecureFileWrapper
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;
|
||||
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<File[]>;
|
||||
create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt?: boolean, preview?: Buffer): Promise<File>;
|
||||
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 });
|
||||
}
|
||||
async test() {
|
||||
let res = await this.makeRequest("/test", "GET", {}, undefined);
|
||||
statusParser(res);
|
||||
return await res.json();
|
||||
}
|
||||
async list(folder) {
|
||||
if (!folder)
|
||||
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") };
|
||||
}
|
||||
|
||||
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<File[]> {
|
||||
if (!folder) folder = "root";
|
||||
let res = await this.makeRequest("/files", "GET", { folder: folder }, undefined)
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "secure-file-wrapper",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"main": "index.js",
|
||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||
"license": "MIT",
|
||||
|
8
test.js
8
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 => {
|
||||
|
10
test.ts
10
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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user