Add v1.0
This commit is contained in:
parent
6a5f642fb4
commit
48dffc112a
21 changed files with 1327 additions and 0 deletions
27
src/endpoints/management/create_channel.ts
Normal file
27
src/endpoints/management/create_channel.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `POST`, path: `/manage`,
|
||||
options: {
|
||||
validate: {
|
||||
payload: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel } = request.params;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
db[channel].lurkers = {};
|
||||
|
||||
return h.response().code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
38
src/endpoints/management/create_message.ts
Normal file
38
src/endpoints/management/create_message.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import { v4 } from "uuid";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: [`POST`, `PUT`], path: `/manage/{channel}/message`,
|
||||
options: {
|
||||
validate: {
|
||||
payload: Joi.object({
|
||||
lurk: Joi.array().items(Joi.string().min(1)).min(1),
|
||||
unlurk: Joi.array().items(Joi.string().min(1)).min(1),
|
||||
}),
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel } = request.params;
|
||||
const data = request.payload as lurk_message;
|
||||
const id = v4();
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
db[channel].messages[id] = data;
|
||||
|
||||
return h.response({
|
||||
lurk: data.lurk,
|
||||
unlurk: data.unlurk,
|
||||
id,
|
||||
}).code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
33
src/endpoints/management/delete_message.ts
Normal file
33
src/endpoints/management/delete_message.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `DELETE`, path: `/manage/{channel}/message/{id}`,
|
||||
options: {
|
||||
validate: {
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
id: Joi.string().uuid(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel, id } = request.params;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
if (!db[channel].messages[id]) {
|
||||
throw boom.notFound(`Invalid ID`);
|
||||
};
|
||||
|
||||
let message = db[channel].messages[id];
|
||||
delete db[channel].messages[id];
|
||||
|
||||
return h.response(message).code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
27
src/endpoints/management/list_messages.ts
Normal file
27
src/endpoints/management/list_messages.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `GET`, path: `/manage/{channel}`,
|
||||
async handler(request, h) {
|
||||
const { channel } = request.params;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
let messages = [];
|
||||
for (const messageId in db[channel].messages) {
|
||||
let message = db[channel].messages[messageId];
|
||||
messages.push({
|
||||
id: messageId,
|
||||
lurk: message.lurk,
|
||||
unlurk: message.unlurk,
|
||||
});
|
||||
};
|
||||
|
||||
return h.response(messages).code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
27
src/endpoints/management/reset_lurkers.ts
Normal file
27
src/endpoints/management/reset_lurkers.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `DELETE`, path: `/manage/{channel}/lurkers`,
|
||||
options: {
|
||||
validate: {
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel } = request.params;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
db[channel].lurkers = {};
|
||||
|
||||
return h.response().code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
34
src/endpoints/management/update_message.ts
Normal file
34
src/endpoints/management/update_message.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import { v4 } from "uuid";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `PATCH`, path: `/manage/{channel}/message/{id}`,
|
||||
options: {
|
||||
validate: {
|
||||
payload: Joi.object({
|
||||
lurk: Joi.array().items(Joi.string().min(1)).min(1),
|
||||
unlurk: Joi.array().items(Joi.string().min(1)).min(1),
|
||||
}),
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
id: Joi.string().uuid(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel, id } = request.params;
|
||||
const data = request.payload as lurk_message;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
db[channel].messages[id] = data;
|
||||
|
||||
return h.response(`Updated message set with ID: ${id}`).code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
Loading…
Add table
Add a link
Reference in a new issue