mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2025-12-17 14:54:31 +01:00
第二引数でNIP-95かどうかを返す
This commit is contained in:
@@ -7,20 +7,31 @@ import (
|
|||||||
"github.com/studiokaiji/nostr-webhost/hostr/cmd/consts"
|
"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
|
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 {
|
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 {
|
} 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 {
|
} else if kind == consts.KindWebhostJS || kind == consts.KindWebhostReplaceableJS {
|
||||||
return "text/javascript; charset=utf-8", nil
|
return "text/javascript; charset=utf-8", false, nil
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("Invalid Kind")
|
return "", false, fmt.Errorf("Invalid Kind")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user