From 158609c8efd856b00e554ee06990b418c4e06c7b Mon Sep 17 00:00:00 2001 From: studiokaiji Date: Wed, 25 Oct 2023 11:32:29 +0900 Subject: [PATCH] =?UTF-8?q?httpClient=E3=82=92=E5=85=B1=E9=80=9A=E3=81=AE?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=81=A8?= =?UTF-8?q?=E3=81=97=E3=81=A6=E4=BD=BF=E3=81=88=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hostr/cmd/deploy/deploy.go | 10 ++++------ hostr/cmd/deploy/media.go | 10 ++++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hostr/cmd/deploy/deploy.go b/hostr/cmd/deploy/deploy.go index b71fa67..b7279bd 100644 --- a/hostr/cmd/deploy/deploy.go +++ b/hostr/cmd/deploy/deploy.go @@ -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() diff --git a/hostr/cmd/deploy/media.go b/hostr/cmd/deploy/media.go index 5aca222..ae71149 100644 --- a/hostr/cmd/deploy/media.go +++ b/hostr/cmd/deploy/media.go @@ -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