Skip to content

Commit

Permalink
uploadedMediaFiles => uploadedMediaFilePathToURL
Browse files Browse the repository at this point in the history
  • Loading branch information
studiokaiji committed Nov 8, 2023
1 parent d9e34df commit c931c29
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hostr/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func convertLinks(
// jsファイルを解析する
if strings.HasSuffix(a.Val, ".js") {
// アップロード済みファイルの元パスとURLを取得
for path, url := range uploadedMediaFiles {
for path, url := range uploadedMediaFilePathToURL {
// JS内に該当ファイルがあったら置換
content = strings.ReplaceAll(content, path, url)
}
Expand Down
12 changes: 6 additions & 6 deletions hostr/cmd/deploy/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ type MediaResult struct {
}

// [元パス]:[URL]の形で記録する
var uploadedMediaFiles = map[string]string{}
var uploadedMediaFilePathToURL = map[string]string{}

func uploadMediaFiles(filePaths []string, requests []*http.Request) {
client := &http.Client{}

var uploadedMediaFilesCount = 0
var uploadedMediaFilePathToURLCount = 0
var allMediaFilesCount = len(requests)

var wg sync.WaitGroup

go func() {
wg.Add(1)
tools.DisplayProgressBar(&uploadedMediaFilesCount, &allMediaFilesCount)
tools.DisplayProgressBar(&uploadedMediaFilePathToURLCount, &allMediaFilesCount)
wg.Done()
}()

Expand Down Expand Up @@ -118,9 +118,9 @@ func uploadMediaFiles(filePaths []string, requests []*http.Request) {
return
}

mutex.Lock() // ロックして排他制御
uploadedMediaFilesCount++ // カウントアップ
uploadedMediaFiles[filePath] = result.Url
mutex.Lock() // ロックして排他制御
uploadedMediaFilePathToURLCount++ // カウントアップ
uploadedMediaFilePathToURL[filePath] = result.Url
mutex.Unlock() // ロック解除
}(filePath, req)
}
Expand Down
16 changes: 8 additions & 8 deletions hostr/cmd/deploy/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func publishEventsFromQueue(replaceable bool) (string, string) {

// Publishの進捗状況を表示
allEventsCount := len(nostrEventsQueue)
uploadedMediaFilesCount := 0
uploadedMediaFilePathToURLCount := 0

var wg sync.WaitGroup

go func() {
wg.Add(1)
tools.DisplayProgressBar(&uploadedMediaFilesCount, &allEventsCount)
tools.DisplayProgressBar(&uploadedMediaFilePathToURLCount, &allEventsCount)
wg.Done()
}()

Expand All @@ -76,17 +76,17 @@ func publishEventsFromQueue(replaceable bool) (string, string) {
continue
}
}
mutex.Lock() // ロックして排他制御
uploadedMediaFilesCount++ // カウントアップ
mutex.Unlock() // ロック解除
wg.Done() // ゴルーチンの終了を通知
mutex.Lock() // ロックして排他制御
uploadedMediaFilePathToURLCount++ // カウントアップ
mutex.Unlock() // ロック解除
wg.Done() // ゴルーチンの終了を通知
}(ev)
}

wg.Wait()

if uploadedMediaFilesCount < allEventsCount {
fmt.Println("Failed to deploy", allEventsCount-uploadedMediaFilesCount, "files.")
if uploadedMediaFilePathToURLCount < allEventsCount {
fmt.Println("Failed to deploy", allEventsCount-uploadedMediaFilePathToURLCount, "files.")
}

indexEvent := nostrEventsQueue[len(nostrEventsQueue)-1]
Expand Down

0 comments on commit c931c29

Please sign in to comment.