mail request stub
This commit is contained in:
parent
6ba185b376
commit
ef6a9af447
14
webmail.lua
14
webmail.lua
@ -5,7 +5,7 @@ local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
local Channel = dofile(MP .. "/util/channel.lua")
|
||||
local channel
|
||||
|
||||
|
||||
-- auth request from webmail
|
||||
local auth_handler = function(auth)
|
||||
local handler = minetest.get_auth_handler()
|
||||
|
||||
@ -24,12 +24,22 @@ local auth_handler = function(auth)
|
||||
})
|
||||
end
|
||||
|
||||
-- send request from webmail
|
||||
local send_handler = function(sendmail)
|
||||
-- send mail from webclient
|
||||
minetest.log("action", "[webmail] sending mail from webclient: " .. sendmail.src .. " -> " .. sendmail.dst)
|
||||
mail.send(sendmail.src, sendmail.dst, sendmail.subject, sendmail.body)
|
||||
end
|
||||
|
||||
-- get player messages request from webmail
|
||||
local get_player_messages_handler = function(playername)
|
||||
channel.send({
|
||||
type = "player-messages",
|
||||
playername = playername,
|
||||
data = mail.messages[playername]
|
||||
})
|
||||
end
|
||||
|
||||
-- called on mail saving to disk (every change)
|
||||
mail.webmail_save_hook = function()
|
||||
channel.send({
|
||||
@ -49,6 +59,8 @@ mail.webmail_init = function(http, url, key)
|
||||
auth_handler(data.data)
|
||||
elseif data.type == "send" then
|
||||
send_handler(data.data)
|
||||
elseif data.type == "player-messages" then
|
||||
get_player_messages_handler(data.data)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
@ -1,20 +1,16 @@
|
||||
|
||||
const app = require("../app");
|
||||
const store = require("../store");
|
||||
|
||||
const bodyParser = require('body-parser')
|
||||
const jsonParser = bodyParser.json()
|
||||
const bodyParser = require('body-parser');
|
||||
const jsonParser = bodyParser.json();
|
||||
|
||||
const playermessages = require("../promise/playermessages");
|
||||
|
||||
app.get('/api/inbox/:name', function(req, res){
|
||||
|
||||
var name = req.params.name;
|
||||
|
||||
console.log(req.params, store);
|
||||
|
||||
if (name && store.messages[name])
|
||||
res.json(store.messages[name]);
|
||||
else
|
||||
res.end();
|
||||
|
||||
playermessages(name)
|
||||
.then(list => res.json(list))
|
||||
.catch(e => res.status(500).end);
|
||||
});
|
||||
|
@ -25,5 +25,5 @@ module.exports = (username, password) => new Promise(function(resolve, reject){
|
||||
var handle = setTimeout(function(){
|
||||
events.removeListener("channel-recv", handleEvent);
|
||||
reject("mod-comm timeout");
|
||||
}, 2500);
|
||||
}, 1000);
|
||||
});
|
26
webmail/src/promise/playermessages.js
Normal file
26
webmail/src/promise/playermessages.js
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
const events = require("../events");
|
||||
|
||||
module.exports = (playername) => new Promise(function(resolve, reject){
|
||||
|
||||
events.emit("channel-send", {
|
||||
type: "player-messages",
|
||||
data: playername
|
||||
});
|
||||
|
||||
function handleEvent(result){
|
||||
if (result.type == "player-messages" && result.playername == playername){
|
||||
events.removeListener("channel-recv", handleEvent);
|
||||
clearTimeout(handle);
|
||||
resolve(result.data);
|
||||
}
|
||||
}
|
||||
|
||||
events.on("channel-recv", handleEvent);
|
||||
|
||||
var handle = setTimeout(function(){
|
||||
events.removeListener("channel-recv", handleEvent);
|
||||
reject("mod-comm timeout");
|
||||
}, 1000);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user