mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2026-01-31 20:54:49 +01:00
httpClientを共通のインスタンスとして使えるようにした
This commit is contained in:
@@ -141,7 +141,6 @@ func convertLinks(priKey, pubKey, basePath string, replaceable bool, indexHtmlId
|
||||
// jsファイルを解析する
|
||||
if strings.HasSuffix(basePath, ".js") {
|
||||
jsContent := string(bytesContent)
|
||||
|
||||
}
|
||||
|
||||
// Tagsを追加
|
||||
@@ -179,7 +178,7 @@ func convertLinks(priKey, pubKey, basePath string, replaceable bool, indexHtmlId
|
||||
} else if slices.Contains(availableMediaHtmlTags, n.Data) {
|
||||
// 内部mediaファイルを対象にUpload Requestを作成
|
||||
for i, a := range n.Attr {
|
||||
if (a.Key == "href" || a.Key == "src" || a.Key == "data") && !isExternalURL(a.Val) && isValidBasicFileType(a.Val) {
|
||||
if (a.Key == "href" || a.Key == "src" || a.Key == "data") && !isExternalURL(a.Val) && isValidMediaFileType(a.Val) {
|
||||
filePath := filepath.Join(basePath, a.Val)
|
||||
|
||||
// アップロードのためのHTTPリクエストを取得
|
||||
@@ -189,12 +188,11 @@ func convertLinks(priKey, pubKey, basePath string, replaceable bool, indexHtmlId
|
||||
}
|
||||
|
||||
// アップロード処理を代入
|
||||
uploadFunc := func() (*MediaResult, error) {
|
||||
// リクエストを送信
|
||||
client := &http.Client{}
|
||||
uploadFunc := func(client *http.Client) (*MediaResult, error) {
|
||||
response, err := client.Do(request)
|
||||
// リクエストを送信
|
||||
if err != nil {
|
||||
fmt.Errorf("Error sending request: %w", err)
|
||||
return nil, fmt.Errorf("Error sending request: %w", err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
|
||||
@@ -79,13 +79,13 @@ type MediaResult struct {
|
||||
tags []string
|
||||
}
|
||||
|
||||
var mediaUploadRequestQueue []func() (*MediaResult, error)
|
||||
var mediaUploadRequestQueue []func(*http.Client) (*MediaResult, error)
|
||||
|
||||
func addNostrEventQueue(event *nostr.Event) {
|
||||
nostrEventsQueue = append(nostrEventsQueue, event)
|
||||
}
|
||||
|
||||
func addMediaUploadRequestFuncQueue(reqFunc func() (*MediaResult, error)) {
|
||||
func addMediaUploadRequestFuncQueue(reqFunc func(client *http.Client) (*MediaResult, error)) {
|
||||
mediaUploadRequestQueue = append(mediaUploadRequestQueue, reqFunc)
|
||||
}
|
||||
|
||||
@@ -106,11 +106,13 @@ func uploadMediaFilesFromQueue() {
|
||||
|
||||
var mutex sync.Mutex
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
// アップロードを並列処理
|
||||
for _, reqFunc := range mediaUploadRequestQueue {
|
||||
wg.Add(1)
|
||||
go func(reqFun func() (*MediaResult, error)) {
|
||||
_, err := reqFun()
|
||||
go func(reqFun func(*http.Client) (*MediaResult, error)) {
|
||||
_, err := reqFun(client)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user