パスの扱い方を呼び出し元でシンプルになるように変更

This commit is contained in:
studiokaiji
2023-11-09 06:26:32 +09:00
parent ea85ed4a60
commit 9baa230836
2 changed files with 2 additions and 4 deletions

View File

@@ -9,7 +9,6 @@ import (
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"os" "os"
"path/filepath"
"strings" "strings"
"sync" "sync"
@@ -114,7 +113,7 @@ func uploadMediaFiles(filePaths []string, requests []*http.Request) {
func filePathToUploadMediaRequest(basePath, filePath, priKey, pubKey string) (*http.Request, error) { func filePathToUploadMediaRequest(basePath, filePath, priKey, pubKey string) (*http.Request, error) {
// ファイルを開く // ファイルを開く
file, err := os.Open(filepath.Join(basePath, filePath)) file, err := os.Open(filePath)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to read %s: %w", filePath, err) return nil, fmt.Errorf("Failed to read %s: %w", filePath, err)
} }

View File

@@ -23,13 +23,12 @@ func FindFilesWithBasePathBySuffixes(basePath string, suffixes []string) ([]stri
// ファイル名とサフィックスがマッチした場合 // ファイル名とサフィックスがマッチした場合
if strings.HasSuffix(strings.ToLower(info.Name()), strings.ToLower(suffix)) { if strings.HasSuffix(strings.ToLower(info.Name()), strings.ToLower(suffix)) {
// フルパスからbasePathまでの相対パスを計算 // フルパスからbasePathまでの相対パスを計算
relPath, err := filepath.Rel(basePath, path)
if err != nil { if err != nil {
fmt.Println("❌ Error calculating relative path:", err) fmt.Println("❌ Error calculating relative path:", err)
continue continue
} }
// マッチするファイルの相対パスをスライスに追加 // マッチするファイルの相対パスをスライスに追加
filePaths = append(filePaths, "/"+relPath) filePaths = append(filePaths, path)
break break
} }
} }