Adding keys request
This commit is contained in:
parent
6036556a37
commit
15df0351a4
@ -21,7 +21,7 @@ async function verifyJWT(token: string, publicKey: string) {
|
|||||||
|
|
||||||
import { URLSearchParams } from "url";
|
import { URLSearchParams } from "url";
|
||||||
|
|
||||||
type QueryTypes = "get" | "set" | "push" | "subscribe" | "unsubscribe";
|
type QueryTypes = "keys" | "get" | "set" | "push" | "subscribe" | "unsubscribe";
|
||||||
|
|
||||||
export class ConnectionManager {
|
export class ConnectionManager {
|
||||||
static server: WebSocket.Server;
|
static server: WebSocket.Server;
|
||||||
@ -96,6 +96,11 @@ export class ConnectionManager {
|
|||||||
const query = stored.get(id) || db.getQuery(path);
|
const query = stored.get(id) || db.getQuery(path);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case "keys":
|
||||||
|
if (!perms.read)
|
||||||
|
throw noperm;
|
||||||
|
answer(id, await query.keys());
|
||||||
|
return;
|
||||||
case "get":
|
case "get":
|
||||||
if (!perms.read)
|
if (!perms.read)
|
||||||
throw noperm;
|
throw noperm;
|
||||||
|
@ -74,6 +74,19 @@ export default class Query {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async keys() {
|
||||||
|
const lock = await this.database.locks.lock(this.path);
|
||||||
|
try {
|
||||||
|
let obj = await this.getField(this.path);
|
||||||
|
if (!obj)
|
||||||
|
return [];
|
||||||
|
let fields = await this.getFields(this.path);
|
||||||
|
return fields.map(field => field.split("/").filter(e => e !== "")).filter(path => path.length === this.path.length + 1).map(path => path.pop());
|
||||||
|
} finally {
|
||||||
|
lock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async get() {
|
async get() {
|
||||||
const lock = await this.database.locks.lock(this.path);
|
const lock = await this.database.locks.lock(this.path);
|
||||||
try {
|
try {
|
||||||
@ -243,6 +256,7 @@ export default class Query {
|
|||||||
if (type === ChangeTypes.PUSH) {
|
if (type === ChangeTypes.PUSH) {
|
||||||
send({
|
send({
|
||||||
id: change.path[change.path.length - 1],
|
id: change.path[change.path.length - 1],
|
||||||
|
path: change.path,
|
||||||
data: await new Query(this.database, change.path).get()
|
data: await new Query(this.database, change.path).get()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user