initial upload
This commit is contained in:
parent
987c99d00b
commit
bb6c0147db
44 changed files with 1884 additions and 131 deletions
58
functions/db.authorities.mjs
Normal file
58
functions/db.authorities.mjs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
import {
|
||||
JsonDB,
|
||||
Config
|
||||
} from 'node-json-db';
|
||||
|
||||
import {
|
||||
default as ValidateSchema
|
||||
} from 'validate'
|
||||
|
||||
import {
|
||||
randomBytes
|
||||
} from "crypto";
|
||||
|
||||
|
||||
var authorityDB = new JsonDB(new Config("datastore/database/authorityDB.json", true, true, '/'));
|
||||
|
||||
const authoritySchema = new ValidateSchema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
match: /^[a-zA-Z0-9\ \-\_]+$/,
|
||||
length: { min: 3, max: 32 },
|
||||
message: 'invalid name'
|
||||
}
|
||||
})
|
||||
|
||||
export async function saveAuthority(authorityID, authorityConfig) {
|
||||
let configErrorList = authoritySchema.validate(authorityConfig);
|
||||
|
||||
configErrorList = configErrorList.map((configError) => {
|
||||
return configError.message;
|
||||
})
|
||||
|
||||
if (configErrorList.length > 0) {
|
||||
return {
|
||||
status: "error",
|
||||
errors: configErrorList
|
||||
}
|
||||
}
|
||||
|
||||
await authorityDB.push(`/${authorityID}`, authorityConfig);
|
||||
|
||||
return {
|
||||
status: "ok"
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAuthority(authorityID) {
|
||||
let AuthorityData = await authorityDB.getData(`/${authorityID}`);
|
||||
return AuthorityData;
|
||||
}
|
||||
|
||||
export async function deleteAuthority(authorityID) {
|
||||
await authorityDB.delete(`/${authorityID}`);
|
||||
}
|
||||
|
||||
saveAuthority(randomBytes(4).toString("hex"), {names: "{test}"})
|
||||
Loading…
Add table
Add a link
Reference in a new issue