1
0
mirror of https://github.com/vwxyzjn/portwarden synced 2025-12-24 03:13:13 +00:00

API-6 # Refactor the directory

This commit is contained in:
Costa Huang
2018-11-27 14:48:32 -05:00
parent 7c699f0b8c
commit 7717e3eb19
9 changed files with 65 additions and 48 deletions

View File

@@ -1,48 +0,0 @@
<html>
<head>
<title>Melody example: chatting</title>
</head>
<style>
#chat {
text-align: left;
background: #f1f1f1;
width: 500px;
min-height: 300px;
padding: 20px;
}
</style>
<body>
<center>
<h3>Chat</h3>
<pre id="chat"></pre>
<input placeholder="say something" id="text" type="text">
</center>
<script>
var url = "ws://" + window.location.host + "/ws";
var ws = new WebSocket(url);
var name = "Guest" + Math.floor(Math.random() * 1000);
var chat = document.getElementById("chat");
var text = document.getElementById("text");
var now = function () {
var iso = new Date().toISOString();
return iso.split("T")[1].split(".")[0];
};
ws.onmessage = function (msg) {
var line = now() + " " + msg.data + "\n";
chat.innerText += line;
};
ws.onopen = function (event) {
console.log(event);
};
text.onkeydown = function (e) {
if (e.keyCode === 13 && text.value !== "") {
ws.send("<" + name + "> " + text.value);
text.value = "";
}
};
</script>
</body>
</html>

20
web/scheduler/main.go Normal file
View File

@@ -0,0 +1,20 @@
package main
import (
"io/ioutil"
"log"
"github.com/vwxyzjn/portwarden/web/worker/server"
)
func main() {
credential, err := ioutil.ReadFile("portwardenCredentials.json")
if err != nil {
log.Fatalf("Unable to read client secret file: %v", err)
}
ps := server.PortwardenServer{
Port: 5000,
GoogleDriveAppCredentials: credential,
}
ps.Run()
}

View File

@@ -0,0 +1,12 @@
{
"web": {
"client_id": "1098948957266-vqofngan2v0282k3ia7udtue5pk9aq8n.apps.googleusercontent.com",
"project_id": "neat-tempo-223722",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://www.googleapis.com/oauth2/v3/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "N25YpAKLwoK20_XHn8zAdDO4",
"redirect_uris": ["http://localhost:5000/gdrive/login"],
"javascript_origins": ["http://localhost:5000"]
}
}

33
web/worker/main.go Normal file
View File

@@ -0,0 +1,33 @@
package main
import (
"github.com/RichardKnop/machinery/v1"
"github.com/RichardKnop/machinery/v1/config"
"github.com/vwxyzjn/portwarden"
)
func main() {
var cnf = &config.Config{
Broker: "amqp://guest:guest@localhost:5672/",
DefaultQueue: "machinery_tasks",
ResultBackend: "amqp://guest:guest@localhost:5672/",
AMQP: &config.AMQPConfig{
Exchange: "machinery_exchange",
ExchangeType: "direct",
BindingKey: "machinery_task",
},
}
server, err := machinery.NewServer(cnf)
if err != nil {
panic(err)
}
server.RegisterTasks(map[string]interface{}{
"CreateBackupBytes": portwarden.CreateBackupBytes,
})
worker := server.NewWorker("worker_name", 0)
err = worker.Launch()
if err != nil {
panic(err)
}
}