diff --git a/hostr/cmd/tools/getContentType.go b/hostr/cmd/tools/getContentType.go index 4ed7157..1b97a3a 100644 --- a/hostr/cmd/tools/getContentType.go +++ b/hostr/cmd/tools/getContentType.go @@ -7,20 +7,31 @@ import ( "github.com/studiokaiji/nostr-webhost/hostr/cmd/consts" ) -func GetContentType(event nostr.Event) (string, error) { +// Content-Typeをイベントから取得する。NIP-95の場合は第二引数がtrueになる。 +func GetContentType(event *nostr.Event) (string, bool, error) { kind := event.Kind - if kind == "" { - + if kind == consts.KindTextFile || kind == consts.KindReplaceableTextFile { + contentTypeTag := event.Tags.GetFirst([]string{"type"}) + contentType := contentTypeTag.Value() + + fmt.Println(*event) + fmt.Println(*contentTypeTag) + + if len(contentType) < 1 { + return "", true, fmt.Errorf("Content-Type not specified") + } + + return contentType, true, nil } if kind == consts.KindWebhostHTML || kind == consts.KindWebhostReplaceableHTML { - return "text/html; charset=utf-8", nil + return "text/html; charset=utf-8", false, nil } else if kind == consts.KindWebhostCSS || kind == consts.KindWebhostReplaceableCSS { - return "text/css; charset=utf-8", nil + return "text/css; charset=utf-8", false, nil } else if kind == consts.KindWebhostJS || kind == consts.KindWebhostReplaceableJS { - return "text/javascript; charset=utf-8", nil + return "text/javascript; charset=utf-8", false, nil } else { - return "", fmt.Errorf("Invalid Kind") + return "", false, fmt.Errorf("Invalid Kind") } }