mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2025-12-18 15:24:19 +01:00
NIP-95リクエストに対応
This commit is contained in:
@@ -64,8 +64,13 @@ func Start(port string, mode string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filter := nostr.Filter{
|
filter := nostr.Filter{
|
||||||
Kinds: []int{consts.KindWebhostHTML, consts.KindWebhostCSS, consts.KindWebhostJS, consts.KindWebhostPicture},
|
Kinds: []int{
|
||||||
IDs: ids,
|
consts.KindWebhostHTML,
|
||||||
|
consts.KindWebhostCSS,
|
||||||
|
consts.KindWebhostJS,
|
||||||
|
consts.KindTextFile,
|
||||||
|
},
|
||||||
|
IDs: ids,
|
||||||
}
|
}
|
||||||
if mode == "secure" {
|
if mode == "secure" {
|
||||||
filter.Authors = []string{subdomainPubKey}
|
filter.Authors = []string{subdomainPubKey}
|
||||||
@@ -74,11 +79,16 @@ func Start(port string, mode string) {
|
|||||||
// Poolからデータを取得する
|
// Poolからデータを取得する
|
||||||
ev := pool.QuerySingle(ctx, allRelays, filter)
|
ev := pool.QuerySingle(ctx, allRelays, filter)
|
||||||
if ev != nil {
|
if ev != nil {
|
||||||
contentType, err := tools.GetContentType(ev.Kind)
|
contentType, isTextFile, err := tools.GetContentType(ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := tools.GetResponseContent(ev.Content, isTextFile)
|
||||||
|
if err != nil {
|
||||||
|
ctx.String(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
||||||
} else {
|
} else {
|
||||||
ctx.Data(http.StatusOK, contentType, []byte(ev.Content))
|
ctx.Data(http.StatusOK, contentType, content)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
@@ -112,16 +122,24 @@ func Start(port string, mode string) {
|
|||||||
consts.KindWebhostReplaceableHTML,
|
consts.KindWebhostReplaceableHTML,
|
||||||
consts.KindWebhostReplaceableCSS,
|
consts.KindWebhostReplaceableCSS,
|
||||||
consts.KindWebhostReplaceableJS,
|
consts.KindWebhostReplaceableJS,
|
||||||
|
consts.KindReplaceableTextFile,
|
||||||
},
|
},
|
||||||
Authors: authors,
|
Authors: authors,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
})
|
})
|
||||||
if ev != nil {
|
if ev != nil {
|
||||||
contentType, err := tools.GetContentType(ev.Kind)
|
contentType, isTextFile, err := tools.GetContentType(ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
}
|
}
|
||||||
ctx.Data(http.StatusOK, contentType, []byte(ev.Content))
|
|
||||||
|
// contentの変換
|
||||||
|
content, err := tools.GetResponseContent(ev.Content, isTextFile)
|
||||||
|
if err != nil {
|
||||||
|
ctx.String(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
||||||
|
} else {
|
||||||
|
ctx.Data(http.StatusOK, contentType, content)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
}
|
}
|
||||||
@@ -158,16 +176,24 @@ func Start(port string, mode string) {
|
|||||||
consts.KindWebhostReplaceableHTML,
|
consts.KindWebhostReplaceableHTML,
|
||||||
consts.KindWebhostReplaceableCSS,
|
consts.KindWebhostReplaceableCSS,
|
||||||
consts.KindWebhostReplaceableJS,
|
consts.KindWebhostReplaceableJS,
|
||||||
|
consts.KindReplaceableTextFile,
|
||||||
},
|
},
|
||||||
Authors: authors,
|
Authors: authors,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
})
|
})
|
||||||
|
|
||||||
if ev != nil {
|
if ev != nil {
|
||||||
contentType, err := tools.GetContentType(ev.Kind)
|
contentType, isTextFile, err := tools.GetContentType(ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
}
|
}
|
||||||
ctx.Data(http.StatusOK, contentType, []byte(ev.Content))
|
|
||||||
|
content, err := tools.GetResponseContent(ev.Content, isTextFile)
|
||||||
|
if err != nil {
|
||||||
|
ctx.String(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
||||||
|
} else {
|
||||||
|
ctx.Data(http.StatusOK, contentType, content)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user