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:
@@ -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
20
web/scheduler/main.go
Normal 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()
|
||||
}
|
||||
12
web/scheduler/portwardenCredentials.json
Normal file
12
web/scheduler/portwardenCredentials.json
Normal 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
33
web/worker/main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user