Skip to content
Snippets Groups Projects
Commit 6589eac3 authored by Travis Ralston's avatar Travis Ralston
Browse files

Very early start to a synapse importer

parent 1a2cbf62
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
/pkg
media-repo.yaml
homeserver.yaml
vendor/pkg
vendor/src
......
package main
import (
"flag"
"fmt"
"github.com/turt2live/matrix-media-repo/config"
"github.com/turt2live/matrix-media-repo/storage"
"github.com/turt2live/matrix-media-repo/synapse"
)
func main() {
c, err := config.ReadConfig()
if err != nil {
panic(err)
}
db, err := storage.OpenDatabase(c.Database.Postgres)
if err != nil {
panic(err)
}
homeserverYamlPath := flag.String("homeserver", "homeserver.yaml", "Path to your homeserver.yaml")
moveFiles := flag.Bool("move", false, "If set, files will be moved instead of copied")
importRemote := flag.Bool("remote", false, "If set, remote media will also be imported")
flag.Parse()
hsConfig, err := synapse.ReadConfig(*homeserverYamlPath)
if err != nil {
panic(err)
}
fmt.Println(*moveFiles)
fmt.Println(*importRemote)
fmt.Println(*db)
fmt.Println(hsConfig.GetConnectionString())
}
\ No newline at end of file
package synapse
import (
"errors"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
type HomeserverYaml struct {
Database struct {
Name string `yaml:"name"`
Arguments struct {
Username string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
Hostname string `yaml:"host"`
} `yaml:"args"`
} `yaml:"database"`
}
func ReadConfig(yamlPath string) (HomeserverYaml, error) {
c := &HomeserverYaml{}
f, err := os.Open(yamlPath)
if err != nil {
return *c, err
}
defer f.Close()
buffer, err := ioutil.ReadAll(f)
err = yaml.Unmarshal(buffer, &c)
if err != nil {
return *c, err
}
return *c, nil
}
func (c *HomeserverYaml) GetConnectionString() (string) {
if c.Database.Name != "psycopg2" {
panic(errors.New("homeserver database must be postgres"))
}
a := c.Database.Arguments
return "postgres://" + a.Username + ":" + a.Password + "@" + a.Hostname + "/" + a.Database + "?sslmode=disable"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment