Started api
This commit is contained in:
parent
2e5bb88b57
commit
73a3432c57
@ -2,16 +2,55 @@ const mongoose = require("mongoose");
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
/**
|
||||
* Test
|
||||
* Class for managing the backend api
|
||||
* @hideconstructor
|
||||
*/
|
||||
class Router {
|
||||
constructor(){
|
||||
|
||||
class BackendApi {
|
||||
#_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
|
||||
* @param {String} route
|
||||
*/
|
||||
get(route){
|
||||
|
||||
@ -42,39 +81,23 @@ class Router {
|
||||
}
|
||||
}
|
||||
|
||||
class BackendApi {
|
||||
/**
|
||||
* @hideconstructor
|
||||
*/
|
||||
class Model {
|
||||
#_name;
|
||||
#_plugin;
|
||||
#_router;
|
||||
|
||||
/**
|
||||
* This object is already created for you
|
||||
* @param {plugin} Plugin instance
|
||||
*/
|
||||
constructor(plugin){
|
||||
this._plugin = plugin;
|
||||
this._router = new Router();
|
||||
}
|
||||
#_schema;
|
||||
|
||||
/**
|
||||
* 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))
|
||||
constructor(name, plugin, schema){
|
||||
this.#_name = name;
|
||||
this.#_plugin = plugin;
|
||||
this.#_schema = schema;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
BackendApi,
|
||||
Router
|
||||
BackendApi
|
||||
}
|
@ -20,12 +20,12 @@ function init(){
|
||||
console.log("Launching using the following plugins:");
|
||||
pluginsInfo.forEach(pluginInfo => {
|
||||
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
|
||||
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 Chat from "@/services/Chat"
|
||||
import * as ContextMenu from "@/services/ContextMenu"
|
||||
import * as Map from "@/services/Map"
|
||||
import * as Modules from "@/services/Modules"
|
||||
import * as Sound from "@/services/Sound"
|
||||
import * as Tooltip from "@/services/Tooltip"
|
||||
import * as Windows from "@/services/Windows"
|
||||
import * as _Dragonroll from "@/services/Dragonroll"
|
||||
import * as _Chat from "@/services/Chat"
|
||||
import * as _ContextMenu from "@/services/ContextMenu"
|
||||
import * as _Map from "@/services/Map"
|
||||
import * as _Modules from "@/services/Modules"
|
||||
import * as _Sound from "@/services/Sound"
|
||||
import * as _Tooltip from "@/services/Tooltip"
|
||||
import * as _Windows from "@/services/Windows"
|
||||
import Server from '@/services/Server';
|
||||
|
||||
const Api = {
|
||||
Dragonroll,
|
||||
Chat,
|
||||
ContextMenu,
|
||||
Map,
|
||||
Modules,
|
||||
Sound,
|
||||
Tooltip,
|
||||
Windows
|
||||
/**
|
||||
* Class for managing the client api
|
||||
* @hideconstructor
|
||||
*/
|
||||
class ClientApi {
|
||||
#_plugin
|
||||
#_router
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
Api
|
||||
ClientApi
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { GetPluginPaths } from "./Resources"
|
||||
import { Api } from '@/services/Api'
|
||||
import { ClientApi } from '@/services/Api'
|
||||
|
||||
let pluginInfo = []
|
||||
|
||||
@ -23,7 +23,7 @@ async function FetchPlugins(){
|
||||
});
|
||||
|
||||
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",
|
||||
"tutorials": "./tutorials",
|
||||
"theme_opts": {
|
||||
"sort": false,
|
||||
"default_theme": "dark",
|
||||
"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>",
|
||||
"static_dir": ["./static"],
|
||||
"include_js": ["./static/scripts/themeWatch.js"],
|
||||
"favicon": "static/media/logo.png"
|
||||
"favicon": "static/media/logo.png",
|
||||
"outputSourceFiles": false
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
"title": "Test tutorial"
|
||||
"plugin": {
|
||||
"title": "Creating a plugin"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user