Commit 3134ccf6 authored by Lakr Aream's avatar Lakr Aream 👼🏽

调整逻辑

parent 24a026f7
......@@ -200,7 +200,7 @@ TABLE `Candiay`.`users` (
<details>
<summary>Delete User</summary>
- Requires: Root/Admin Ticket, Request Sign
- Requires: Root/Admin Ticket, Self Ticker, Request Sign
- Location: ./users/c?
- Tips: User can delete itself for no reason
- Parameters:
......@@ -226,7 +226,7 @@ TABLE `Candiay`.`users` (
<details>
<summary>Change User Info</summary>
- Requires: Root/Admin/UserSelf Ticket, Request Sign
- Requires: Root/Admin Ticket, Self Ticker, Request Sign
- Location: ./users/c?
- Tips: none
- Parameters:
......@@ -251,7 +251,7 @@ TABLE `Candiay`.`users` (
<details>
<summary>List All Users</summary>
- Requires: Root/Admin/Developer Ticket, Request Sign
- Requires: Root/Admin/Developer Ticket with Request Sign will list all, otherwise only developers
- Location: ./users/c?
- Tips: none
- Parameters:
......
......@@ -19,6 +19,15 @@ coreApp.get("/", (req, res) => {
res.send("Candiay Core Bootstrap Succeed")
})
coreApp.get("/c", (req, res) => {
if (!StatusManager.shared.configSuccessed) {
res.status(502).send("Application in configuration")
return
}
const ret = RequestManager.shared.performSelectorFromMain(req, res)
res.status(ret["code"]).send(ret["context"])
})
coreApp.get("/users/c", (req, res) => {
if (!StatusManager.shared.configSuccessed) {
res.status(502).send("Application in configuration")
......
......@@ -72,7 +72,7 @@ export class RequestManager {
}
public performSelectorUserManagementRequest(req: any, res: any): { [key: string] : any } {
public performSelectorFromMain(req: any, res: any): { [key: string] : any } {
const headers: object = req.headers
const params: object = req.query
......@@ -91,14 +91,87 @@ export class RequestManager {
console.log("vaildate failed");
}
console.log("---------------------------------------------");
// Doing ~~Steave~~ Jobs
const actionTypeRaw = String(params["action"])
switch (actionTypeRaw.toLowerCase()) {
case "teapot": {
// The server refuses the attempt to brew coffee with a teapot.
return
}
case "signtest": {
if (!vaildated) {
const resolveObject: { [key: string] : any } = {
"code": 401,
"context": "Invalid Signature"
}
contextContaienr = resolveObject
return
} else {
const resolveObject: { [key: string] : any } = {
"code": 200,
"context": "Signature Validated"
}
contextContaienr = resolveObject
return
}
}
default:{
if (!vaildated) {
const ro: { [key: string] : any } = {
"code": 401,
"context": "Invalid Signature"
}
contextContaienr = ro
return
}
const roresolveObject: { [key: string] : any } = {
"code": 404,
"context": "Application Action " + actionTypeRaw + " Not Found"
}
contextContaienr = roresolveObject
return
}
}
})
let currentStamp = (new Date()).getTime()
// will sleep up to around 4680ms
while (contextContaienr === undefined && Math.abs((currentStamp - beginStamp) / 1000) < 4) {
require('deasync').sleep(2333)
currentStamp = (new Date()).getTime()
}
if (contextContaienr === undefined) {
return {
"code": 504,
"context": "Gateway Timeout"
}
} else {
return contextContaienr
}
}
public performSelectorUserManagementRequest(req: any, res: any): { [key: string] : any } {
const headers: object = req.headers
const params: object = req.query
const from: string = req.host
const beginStamp = (new Date()).getTime()
let contextContaienr: { [key: string] : any } | undefined
this.vaildateRequest(headers, params, from, (vaildated) => {
console.log("-------------------REQUEST-------------------");
console.log((new Date()))
console.log(req.url);
if (vaildated) {
console.log("vaildate success");
} else {
console.log("vaildate failed");
}
console.log("---------------------------------------------");
const actionTypeRaw = String(params["action"])
switch (actionTypeRaw.toLowerCase()) {
case "create": {
if (!vaildated) {
const resolveObject: { [key: string] : any } = {
......@@ -298,23 +371,6 @@ export class RequestManager {
})
return
}
case "signtest": {
if (!vaildated) {
const resolveObject: { [key: string] : any } = {
"code": 401,
"context": "Invalid Signature"
}
contextContaienr = resolveObject
return
} else {
const resolveObject: { [key: string] : any } = {
"code": 200,
"context": "Signature Validated"
}
contextContaienr = resolveObject
return
}
}
default:{
if (!vaildated) {
const ro: { [key: string] : any } = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment