mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2025-12-23 09:44:18 +01:00
JS以外のファイルでも画像をreplace可能に。
テキストファイルがreplaceできない問題を解決
This commit is contained in:
@@ -166,13 +166,25 @@ func convertLinks(
|
|||||||
n.Attr[i].Val = fileIdentifier
|
n.Attr[i].Val = fileIdentifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// jsファイルを解析する
|
|
||||||
if strings.HasSuffix(a.Val, ".js") {
|
|
||||||
// アップロード済みファイルの元パスとURLを取得
|
// アップロード済みファイルの元パスとURLを取得
|
||||||
for path, url := range uploadedMediaFilePathToURL {
|
for path, url := range uploadedMediaFilePathToURL {
|
||||||
// JS内に該当ファイルがあったら置換
|
// 該当ファイルがあったら置換
|
||||||
content = strings.ReplaceAll(content, path, url)
|
content = strings.ReplaceAll(content, path, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 変換済みのテキストファイルの元パスとイベントを取得
|
||||||
|
for path, event := range textFilePathToEvent {
|
||||||
|
// 該当ファイルがあったら、replaceableの場合はdタグ、そうでない場合はneventに置換
|
||||||
|
new := ""
|
||||||
|
if replaceable {
|
||||||
|
new = event.Tags.GetFirst([]string{"d"}).Value()
|
||||||
|
} else {
|
||||||
|
new, err = nip19.EncodeEvent(event.ID, allRelays, pubKey)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("❌ Failed encode event id", filePath, ":", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
content = strings.ReplaceAll(content, path, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
event, err := getEvent(priKey, pubKey, content, kind, tags)
|
event, err := getEvent(priKey, pubKey, content, kind, tags)
|
||||||
|
|||||||
Reference in New Issue
Block a user