2021-03-03 10:02:35 +01:00
|
|
|
/*
|
|
|
|
MastoGem, A Mastodon proxy for Gemini
|
|
|
|
Copyright (C) 2021 Romain de Laage
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-03-02 20:31:38 +01:00
|
|
|
package main
|
|
|
|
|
2021-04-17 12:10:27 +02:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
2021-03-02 20:31:38 +01:00
|
|
|
|
|
|
|
type Blog struct {
|
2021-05-02 19:30:47 +02:00
|
|
|
Id string `json:"id"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
Date string `json:"created_at"`
|
|
|
|
Author Account `json:"account"`
|
|
|
|
Tags []Tag `json:"tags"`
|
|
|
|
Mentions []Mention `json:"mentions"`
|
2022-05-11 15:28:11 +02:00
|
|
|
Reblog *Blog `json:"reblog"`
|
2022-04-30 14:32:28 +02:00
|
|
|
Medias []Media `json:"media_attachments"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Media struct {
|
|
|
|
Url string `json:"url"`
|
2021-03-02 20:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Listen string `json:"listen"`
|
|
|
|
CertPath string `json:"cert_path"`
|
|
|
|
KeyPath string `json:"key_path"`
|
|
|
|
BaseURL string `json:"base_url"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
HomeMessage string `json:"home_message"`
|
2021-04-18 10:43:12 +02:00
|
|
|
RateLimit int `json:"rate_limit"`
|
2021-03-02 20:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Account struct {
|
2021-03-03 16:30:26 +01:00
|
|
|
Id string `json:"id"`
|
|
|
|
DisplayName string `json:"display_name"`
|
2021-03-04 09:27:50 +01:00
|
|
|
Name string `json:"acct"`
|
2021-03-03 16:30:26 +01:00
|
|
|
Url string `json:"url"`
|
2021-03-02 20:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Thread struct {
|
|
|
|
Ancestors []Blog `json:"ancestors"`
|
|
|
|
Descendants []Blog `json:"descendants"`
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:13:38 +01:00
|
|
|
type Mention struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"acct"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Tag struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
2021-04-17 12:10:27 +02:00
|
|
|
type Rate struct {
|
|
|
|
Date time.Time
|
|
|
|
Count int
|
|
|
|
}
|
|
|
|
|
|
|
|
var rateMap map[string]Rate
|
|
|
|
|
2021-03-02 20:31:38 +01:00
|
|
|
func main() {
|
|
|
|
config := getConfig()
|
2021-04-17 12:10:27 +02:00
|
|
|
rateMap = make(map[string]Rate)
|
2021-03-02 20:31:38 +01:00
|
|
|
|
|
|
|
listener := listen(config.Listen, config.CertPath, config.KeyPath)
|
|
|
|
log.Println("Server successfully started")
|
|
|
|
log.Println("Server is listening at " + config.Listen)
|
|
|
|
|
2021-04-18 10:43:12 +02:00
|
|
|
serve(listener, config.BaseURL, config.Title, config.HomeMessage, config.RateLimit)
|
2021-03-02 20:31:38 +01:00
|
|
|
}
|