fix api error and add license
This commit is contained in:
parent
aae5ce66ca
commit
a76f42137e
3 changed files with 10 additions and 94 deletions
9
LICENSE
Normal file
9
LICENSE
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 hippoz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,93 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Document</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<button onclick="createToken('testinguser', '0', ['822089558886842418']);">create token</button>
|
|
||||||
<button onclick="sendMessage('822089558886842418', '822089558886842421', 'hello');">send message</button>
|
|
||||||
<button onclick="getChannels('822089558886842418');">get channels</button>
|
|
||||||
<button onclick="getGuildInfo('822089558886842418');">get info</button>
|
|
||||||
<button onclick="getOwnUserInfo();">get own user info</button>
|
|
||||||
<button onclick="eventPoll('822089558886842418');">poll event</button>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let createdToken;
|
|
||||||
|
|
||||||
async function createToken(username, discordID, guildAccess) {
|
|
||||||
const res = await fetch("http://localhost:4050/api/v1/tokens/create", {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({
|
|
||||||
username,
|
|
||||||
discordID,
|
|
||||||
guildAccess
|
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
"content-type": "application/json"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const json = await res.json();
|
|
||||||
console.log("createToken()", json);
|
|
||||||
createdToken = json.token;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendMessage(guildId, channelId, content) {
|
|
||||||
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/channels/${channelId}/messages/create`, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({
|
|
||||||
content
|
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
"content-type": "application/json",
|
|
||||||
"authorization": createdToken
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log("sendMessage() stauts", await res.status);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getChannels(guildId) {
|
|
||||||
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/channels`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"authorization": createdToken
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log("getChannels()", await res.json());
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getGuildInfo(guildId) {
|
|
||||||
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"authorization": createdToken
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log("getGuildInfo()", await res.json());
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getOwnUserInfo() {
|
|
||||||
const res = await fetch(`http://localhost:4050/api/v1/users/@self`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"authorization": createdToken
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log("getOwnUserInfo()", await res.json());
|
|
||||||
}
|
|
||||||
|
|
||||||
async function eventPoll(guildId) {
|
|
||||||
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/events/poll`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"authorization": createdToken
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log("eventPoll()", await res.json());
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -104,7 +104,7 @@ router.get("/guilds/:guildId", checkAuth(async (req, res) => {
|
||||||
router.get("/users/@self/guilds", checkAuth(async (req, res) => {
|
router.get("/users/@self/guilds", checkAuth(async (req, res) => {
|
||||||
const { guildAccess } = req.user;
|
const { guildAccess } = req.user;
|
||||||
|
|
||||||
res.status(200).send({ error: false, guilds: guildAccess.map(e => guildMap.get(e).guildObject) });
|
res.status(200).send({ error: false, guilds: guildAccess.map(e => guildMap.get(e)?.guildObject) });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.get("/guilds/:guildId/events/poll", checkAuth(async (req, res) => {
|
router.get("/guilds/:guildId/events/poll", checkAuth(async (req, res) => {
|
||||||
|
|
Loading…
Reference in a new issue