Started api
This commit is contained in:
parent
2e5bb88b57
commit
73a3432c57
@ -2,16 +2,55 @@ const mongoose = require("mongoose");
|
|||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test
|
* Class for managing the backend api
|
||||||
|
* @hideconstructor
|
||||||
*/
|
*/
|
||||||
class Router {
|
class BackendApi {
|
||||||
constructor(){
|
#_plugin;
|
||||||
|
#_router;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This object is already created for you
|
||||||
|
* @param {plugin} Plugin instance
|
||||||
|
*/
|
||||||
|
constructor(plugin){
|
||||||
|
this.#_plugin = plugin;
|
||||||
|
this.#_router = new BackendRouter(plugin.package);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the router for your plugin
|
||||||
|
* @type {BackendRouter}
|
||||||
|
*/
|
||||||
|
get router(){
|
||||||
|
return this.#_router;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new database model for the plugin
|
||||||
|
* @param {String} name
|
||||||
|
* @param {Object} schema
|
||||||
|
* @returns {Model}
|
||||||
|
*/
|
||||||
|
createModel(name, schema){
|
||||||
|
return new Model(name, this.#_plugin, schema);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class registers routes to the backend that can be accessed from the frontend
|
||||||
|
* @hideconstructor
|
||||||
|
*/
|
||||||
|
class BackendRouter {
|
||||||
|
#_root;
|
||||||
|
|
||||||
|
constructor(path){
|
||||||
|
this.#_root = `plugins/${path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} route
|
|
||||||
* Hola
|
* Hola
|
||||||
|
* @param {String} route
|
||||||
*/
|
*/
|
||||||
get(route){
|
get(route){
|
||||||
|
|
||||||
@ -42,39 +81,23 @@ class Router {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BackendApi {
|
/**
|
||||||
|
* @hideconstructor
|
||||||
|
*/
|
||||||
|
class Model {
|
||||||
|
#_name;
|
||||||
#_plugin;
|
#_plugin;
|
||||||
#_router;
|
#_schema;
|
||||||
|
|
||||||
/**
|
constructor(name, plugin, schema){
|
||||||
* This object is already created for you
|
this.#_name = name;
|
||||||
* @param {plugin} Plugin instance
|
this.#_plugin = plugin;
|
||||||
*/
|
this.#_schema = schema;
|
||||||
constructor(plugin){
|
|
||||||
this._plugin = plugin;
|
|
||||||
this._router = new Router();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the router for your plugin
|
|
||||||
* @type {Router} router
|
|
||||||
*/
|
|
||||||
get router(){
|
|
||||||
return this.router;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new database model for the plguin
|
|
||||||
* @param {String} name
|
|
||||||
* @param {Object} schema
|
|
||||||
* @returns {mongoose.model}
|
|
||||||
*/
|
|
||||||
createModel(name, schema){
|
|
||||||
return mongoose.model(name, new Schema(schema))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
BackendApi,
|
BackendApi
|
||||||
Router
|
|
||||||
}
|
}
|
@ -20,12 +20,12 @@ function init(){
|
|||||||
console.log("Launching using the following plugins:");
|
console.log("Launching using the following plugins:");
|
||||||
pluginsInfo.forEach(pluginInfo => {
|
pluginsInfo.forEach(pluginInfo => {
|
||||||
console.log(`\t- ${pluginInfo.name}`);
|
console.log(`\t- ${pluginInfo.name}`);
|
||||||
plugins[pluginInfo.package] = require(`${basePath}/plugins/${pluginInfo.package}/${pluginInfo.backend.entrypoint}`);
|
plugins[pluginInfo.package] = {info: pluginInfo, payload: require(`${basePath}/plugins/${pluginInfo.package}/${pluginInfo.backend.entrypoint}`)};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Execute main
|
// Execute main
|
||||||
Object.keys(plugins).forEach(k => {
|
Object.keys(plugins).forEach(k => {
|
||||||
plugins[k].Main(new BackendApi(k))
|
plugins[k].payload.Main(new BackendApi(plugins[k].info))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,127 @@
|
|||||||
import * as Dragonroll from "@/services/Dragonroll"
|
import * as _Dragonroll from "@/services/Dragonroll"
|
||||||
import * as Chat from "@/services/Chat"
|
import * as _Chat from "@/services/Chat"
|
||||||
import * as ContextMenu from "@/services/ContextMenu"
|
import * as _ContextMenu from "@/services/ContextMenu"
|
||||||
import * as Map from "@/services/Map"
|
import * as _Map from "@/services/Map"
|
||||||
import * as Modules from "@/services/Modules"
|
import * as _Modules from "@/services/Modules"
|
||||||
import * as Sound from "@/services/Sound"
|
import * as _Sound from "@/services/Sound"
|
||||||
import * as Tooltip from "@/services/Tooltip"
|
import * as _Tooltip from "@/services/Tooltip"
|
||||||
import * as Windows from "@/services/Windows"
|
import * as _Windows from "@/services/Windows"
|
||||||
|
import Server from '@/services/Server';
|
||||||
|
|
||||||
const Api = {
|
/**
|
||||||
Dragonroll,
|
* Class for managing the client api
|
||||||
Chat,
|
* @hideconstructor
|
||||||
ContextMenu,
|
*/
|
||||||
Map,
|
class ClientApi {
|
||||||
Modules,
|
#_plugin
|
||||||
Sound,
|
#_router
|
||||||
Tooltip,
|
|
||||||
Windows
|
/**
|
||||||
|
* @param {*} plugin
|
||||||
|
*/
|
||||||
|
constructor(plugin){
|
||||||
|
this.#_plugin = plugin
|
||||||
|
this.#_router = new ClientRouter()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the client router
|
||||||
|
* @type {ClientRouter}
|
||||||
|
*/
|
||||||
|
get router(){
|
||||||
|
return this.#_router;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} Response
|
||||||
|
* @property {Object} data
|
||||||
|
* @property {number} status
|
||||||
|
* @property {string} statusText
|
||||||
|
* @property {Object} headers
|
||||||
|
* @property {Object} config
|
||||||
|
* @property {Object} request
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback routerCallback
|
||||||
|
* @param {Response} response
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for accessing backend routes
|
||||||
|
* @hideconstructor
|
||||||
|
*/
|
||||||
|
class ClientRouter {
|
||||||
|
#_path;
|
||||||
|
|
||||||
|
constructor(path){
|
||||||
|
this.#_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a get request to an specified route of a plugin, and then executes the routerCallback with the response
|
||||||
|
* @param {String} route
|
||||||
|
* @param {routerCallback} callback
|
||||||
|
*/
|
||||||
|
get(route, callback){
|
||||||
|
Server().get(`${path}/${route}`).then(response => callback(response)).catch(err => console.log(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} route
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
post(route){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} route
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
put(route){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} route
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
delete(route){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
baseGet(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
basePost(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
baseUpdate(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
baseDelete(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Api
|
ClientApi
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import { GetPluginPaths } from "./Resources"
|
import { GetPluginPaths } from "./Resources"
|
||||||
import { Api } from '@/services/Api'
|
import { ClientApi } from '@/services/Api'
|
||||||
|
|
||||||
let pluginInfo = []
|
let pluginInfo = []
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ async function FetchPlugins(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
import(/* @vite-ignore */ `../../plugins/${pluginName}/${pluginData.client.entrypoint}`).then(module => {
|
import(/* @vite-ignore */ `../../plugins/${pluginName}/${pluginData.client.entrypoint}`).then(module => {
|
||||||
module.Main(Api);
|
module.Main(new ClientApi(pluginData));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,14 @@
|
|||||||
"template": "node_modules/clean-jsdoc-theme",
|
"template": "node_modules/clean-jsdoc-theme",
|
||||||
"tutorials": "./tutorials",
|
"tutorials": "./tutorials",
|
||||||
"theme_opts": {
|
"theme_opts": {
|
||||||
|
"sort": false,
|
||||||
"default_theme": "dark",
|
"default_theme": "dark",
|
||||||
"homepageTitle": "Dragonroll API",
|
"homepageTitle": "Dragonroll API",
|
||||||
"title": "<a href='index.html'><img src='static/media/logo-splash.png' class='logo-splash-dark'/><img src='static/media/logo-splash-light.png' class='logo-splash-light'/></a>",
|
"title": "<a href='index.html'><img src='static/media/logo-splash.png' class='logo-splash-dark'/><img src='static/media/logo-splash-light.png' class='logo-splash-light'/></a>",
|
||||||
"static_dir": ["./static"],
|
"static_dir": ["./static"],
|
||||||
"include_js": ["./static/scripts/themeWatch.js"],
|
"include_js": ["./static/scripts/themeWatch.js"],
|
||||||
"favicon": "static/media/logo.png"
|
"favicon": "static/media/logo.png",
|
||||||
|
"outputSourceFiles": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"markdown": {
|
"markdown": {
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
# Hola
|
|
||||||
hola test
|
|
1
tutorials/plugin.md
Normal file
1
tutorials/plugin.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
This guide will help you through creating a plugin for Dragonroll
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"test": {
|
"plugin": {
|
||||||
"title": "Test tutorial"
|
"title": "Creating a plugin"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user