From 64c50e637893e81ad78dcbc8dc40e3bc5e17f7d9 Mon Sep 17 00:00:00 2001 From: studiokaiji Date: Fri, 10 Nov 2023 10:56:22 +0900 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E5=BC=95=E6=95=B0=E3=81=A7NI?= =?UTF-8?q?P-95=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E3=82=92=E8=BF=94?= =?UTF-8?q?=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hostr/cmd/tools/getContentType.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) 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") } }