Compare commits
3 Commits
master
...
kcoram/upl
Author | SHA1 | Date |
---|---|---|
Kevin C. Coram | 6aeb4836a2 | |
Kevin C. Coram | 802109cf31 | |
Kevin C. Coram | e0fc3147f7 |
|
@ -1,2 +1,3 @@
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
hugo-micropub
|
||||||
|
|
|
@ -87,7 +87,7 @@ func initConfig() (err error) {
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
if SelectedMediaStorage == nil {
|
if SelectedMediaStorage == nil {
|
||||||
return errors.New("no media storage configured")
|
log.Println("no media storage configured")
|
||||||
}
|
}
|
||||||
// Find selected CDN (optional)
|
// Find selected CDN (optional)
|
||||||
SelectedCdn = func() Cdn {
|
SelectedCdn = func() Cdn {
|
||||||
|
|
16
entry.go
16
entry.go
|
@ -75,13 +75,23 @@ func parseRequestBody(r *http.Request) (string, error) {
|
||||||
return string(bodyBytes), nil
|
return string(bodyBytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validEntry(values map[string][]string) bool {
|
||||||
|
if _, ok := values["content"]; ok {
|
||||||
|
return true
|
||||||
|
} else if _, ok := values["like-of"]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
||||||
if h, ok := values["h"]; ok && (len(h) != 1 || h[0] != "entry") {
|
if h, ok := values["h"]; ok && (len(h) != 1 || h[0] != "entry") {
|
||||||
return nil, errors.New("only entry type is supported so far")
|
return nil, errors.New("only entry type is supported so far")
|
||||||
}
|
}
|
||||||
if _, ok := values["content"]; ok {
|
if validEntry(values) {
|
||||||
entry := &Entry{
|
entry := &Entry{}
|
||||||
content: values["content"][0],
|
if content, ok := values["content"]; ok {
|
||||||
|
entry.content = content[0]
|
||||||
}
|
}
|
||||||
if name, ok := values["name"]; ok {
|
if name, ok := values["name"]; ok {
|
||||||
entry.title = name[0]
|
entry.title = name[0]
|
||||||
|
|
4
main.go
4
main.go
|
@ -17,7 +17,9 @@ func main() {
|
||||||
log.Println("Blog URL: " + BlogUrl)
|
log.Println("Blog URL: " + BlogUrl)
|
||||||
log.Println("Ignored URLs for Webmention: " + strings.Join(IgnoredWebmentionUrls, ", "))
|
log.Println("Ignored URLs for Webmention: " + strings.Join(IgnoredWebmentionUrls, ", "))
|
||||||
http.HandleFunc("/micropub", HandleMicroPub)
|
http.HandleFunc("/micropub", HandleMicroPub)
|
||||||
http.HandleFunc("/media", HandleMedia)
|
if SelectedMediaStorage != nil {
|
||||||
|
http.HandleFunc("/media", HandleMedia)
|
||||||
|
}
|
||||||
http.HandleFunc("/webmention", HandleWebmention)
|
http.HandleFunc("/webmention", HandleWebmention)
|
||||||
log.Fatal(http.ListenAndServe(":5555", nil))
|
log.Fatal(http.ListenAndServe(":5555", nil))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleMedia(w http.ResponseWriter, r *http.Request) {
|
func HandleMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if SelectedMediaStorage == nil {
|
||||||
|
// This shouldn't happen since the HTTP handler isn't set up if there is no SelectedMediaStorage
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
_, _ = w.Write([]byte("No media endpoint configured"))
|
||||||
|
}
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
_, _ = w.Write([]byte("The HTTP method is not allowed, make a POST request"))
|
_, _ = w.Write([]byte("The HTTP method is not allowed, make a POST request"))
|
||||||
|
|
10
micropub.go
10
micropub.go
|
@ -12,6 +12,14 @@ type MicropubConfig struct {
|
||||||
MediaEndpoint string `json:"media-endpoint,omitempty"`
|
MediaEndpoint string `json:"media-endpoint,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMediaEndpoint() string {
|
||||||
|
if SelectedMediaStorage != nil {
|
||||||
|
return MediaEndpointUrl
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func HandleMicroPub(w http.ResponseWriter, r *http.Request) {
|
func HandleMicroPub(w http.ResponseWriter, r *http.Request) {
|
||||||
// a handler for GET requests, used for troubleshooting
|
// a handler for GET requests, used for troubleshooting
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
|
@ -20,7 +28,7 @@ func HandleMicroPub(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
jsonBytes, err := json.Marshal(&MicropubConfig{
|
jsonBytes, err := json.Marshal(&MicropubConfig{
|
||||||
SyndicateTo: SyndicationTargets,
|
SyndicateTo: SyndicationTargets,
|
||||||
MediaEndpoint: MediaEndpointUrl,
|
MediaEndpoint: getMediaEndpoint(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
Loading…
Reference in New Issue