diff --git a/config/config.go b/config/config.go index 95da7dc..d0c8975 100644 --- a/config/config.go +++ b/config/config.go @@ -166,7 +166,7 @@ func LoadConfig() { if os.Getenv("WEBP_QUALITY") != "" { quality, err := strconv.Atoi(os.Getenv("WEBP_QUALITY")) if err != nil { - log.Warnf("WEBP_QUALITY is not a valid integer, using value in config.json %d", Config.Quality) + log.Warnf("WEBP_QUALITY 不是有效的整数,使用 config.json 中的值 %d", Config.Quality) } else { Config.Quality = quality } @@ -199,7 +199,7 @@ func LoadConfig() { } else if enableExtraParams == "false" { Config.EnableExtraParams = false } else { - log.Warnf("WEBP_ENABLE_EXTRA_PARAMS is not a valid boolean, using value in config.json %t", Config.EnableExtraParams) + log.Warnf("WEBP_ENABLE_EXTRA_PARAMS 不是有效的布尔值,使用 config.json 中的值 %t", Config.EnableExtraParams) } } if os.Getenv("WEBP_EXTRA_PARAMS_CROP_INTERESTING") != "" { @@ -207,7 +207,7 @@ func LoadConfig() { if slices.Contains(availableInteresting, os.Getenv("WEBP_EXTRA_PARAMS_CROP_INTERESTING")) { Config.ExtraParamsCropInteresting = os.Getenv("WEBP_EXTRA_PARAMS_CROP_INTERESTING") } else { - log.Warnf("WEBP_EXTRA_PARAMS_CROP_INTERESTING is not a valid interesting, using value in config.json %s", Config.ExtraParamsCropInteresting) + log.Warnf("WEBP_EXTRA_PARAMS_CROP_INTERESTING 不是有效的兴趣,使用 config.json 中的值 %s", Config.ExtraParamsCropInteresting) } } @@ -218,7 +218,7 @@ func LoadConfig() { } else if stripMetadata == "false" { Config.StripMetadata = false } else { - log.Warnf("WEBP_STRIP_METADATA is not a valid boolean, using value in config.json %t", Config.StripMetadata) + log.Warnf("WEBP_STRIP_METADATA 不是有效的布尔值,使用 config.json 中的值 %t", Config.StripMetadata) } } if os.Getenv("WEBP_IMG_MAP") != "" { @@ -227,7 +227,7 @@ func LoadConfig() { if os.Getenv("WEBP_READ_BUFFER_SIZE") != "" { readBufferSize, err := strconv.Atoi(os.Getenv("WEBP_READ_BUFFER_SIZE")) if err != nil { - log.Warnf("WEBP_READ_BUFFER_SIZE is not a valid integer, using value in config.json %d", Config.ReadBufferSize) + log.Warnf("WEBP_READ_BUFFER_SIZE 不是有效的整数,使用 config.json 中的值 %d", Config.ReadBufferSize) } else { Config.ReadBufferSize = readBufferSize } @@ -235,7 +235,7 @@ func LoadConfig() { if os.Getenv("WEBP_CONCURRENCY") != "" { concurrency, err := strconv.Atoi(os.Getenv("WEBP_CONCURRENCY")) if err != nil { - log.Warnf("WEBP_CONCURRENCY is not a valid integer, using value in config.json %d", Config.Concurrency) + log.Warnf("WEBP_CONCURRENCY 不是有效的整数,使用 config.json 中的值 %d", Config.Concurrency) } else { Config.Concurrency = concurrency } diff --git a/handler/remote.go b/handler/remote.go index c4e1801..2c77225 100644 --- a/handler/remote.go +++ b/handler/remote.go @@ -36,13 +36,13 @@ func cleanProxyCache(cacheImagePath string) { func downloadFile(filepath string, url string) { resp, err := http.Get(url) if err != nil { - log.Errorln("Connection to remote error when downloadFile!") + log.Errorln("下载文件时连接到远程错误!") return } defer resp.Body.Close() if resp.StatusCode != fiber.StatusOK { - log.Errorf("remote returned %s when fetching remote image", resp.Status) + log.Errorf("获取远程图像时远程返回 %s", resp.Status) return } @@ -57,7 +57,7 @@ func downloadFile(filepath string, url string) { kind, _ := filetype.Match(bodyBytes.Bytes()) mime := kind.MIME.Value if !strings.Contains(mime, "image") { - log.Errorf("remote file %s is not image, remote content has MIME type of %s", url, mime) + log.Errorf("远程文件 %s 不是图像,远程内容的 MIME 类型为 %s", url, mime) return } @@ -88,9 +88,9 @@ func fetchRemoteImg(url string, subdir string) config.MetaFile { if cachedETag, found := config.RemoteCache.Get(cacheKey); found { etag = cachedETag.(string) - log.Infof("Using cached ETag for remote addr: %s", url) + log.Infof("使用缓存的 ETag 进行远程地址: %s", url) } else { - log.Infof("Remote Addr is %s, pinging for info...", url) + log.Infof("远程地址是 %s,正在 ping 获取信息...", url) etag, size, lastModified = pingURL(url) if etag != "" { config.RemoteCache.Set(cacheKey, etag, cache.DefaultExpiration) @@ -103,23 +103,23 @@ func fetchRemoteImg(url string, subdir string) config.MetaFile { needUpdate := false if !helper.ImageExists(localRawImagePath) { - log.Info("Remote file not found in remote-raw, fetching...") + log.Info("在远程原始文件中找不到远程文件,正在获取...") needUpdate = true } else { localFileInfo, err := os.Stat(localRawImagePath) if err == nil { if size > 0 && size != localFileInfo.Size() { - log.Info("File size changed, updating...") + log.Info("文件大小已更改,正在更新...") needUpdate = true } else if !lastModified.IsZero() && lastModified.After(localFileInfo.ModTime()) { - log.Info("Remote file is newer, updating...") + log.Info("远程文件较新,正在更新...") needUpdate = true } else if metadata.Checksum != helper.HashString(etag) { - log.Info("ETag changed, updating...") + log.Info("ETag 已更改,正在更新...") needUpdate = true } } else { - log.Warnf("Error checking local file: %v", err) + log.Warnf("检查本地文件时出错: %v", err) needUpdate = true } } @@ -143,7 +143,7 @@ func pingURL(url string) (string, int64, time.Time) { resp, err := http.Head(url) if err != nil { - log.Errorf("Connection to remote error when pingUrl: %v", err) + log.Errorf("pingUrl 时连接到远程错误: %v", err) return "", 0, time.Time{} } defer resp.Body.Close() @@ -156,16 +156,16 @@ func pingURL(url string) (string, int64, time.Time) { lastModified, _ = time.Parse(time.RFC1123, lastModifiedStr) if etag == "" { - log.Warn("Remote didn't return ETag in header, using Last-Modified if available") + log.Warn("远程未在标头中返回 ETag,使用 Last-Modified(如果可用)") etag = lastModifiedStr } if etag == "" && lastModified.IsZero() { - log.Warn("Neither ETag nor Last-Modified available, using Content-Length as fallback") + log.Warn("ETag 和 Last-Modified 都不可用,使用 Content-Length 作为后备") etag = sizeStr } } else { - log.Warnf("Unexpected status code: %d when pinging URL: %s", resp.StatusCode, url) + log.Warnf("意外的状态代码: %d 当 ping URL 时: %s", resp.StatusCode, url) } return etag, size, lastModified diff --git a/handler/router.go b/handler/router.go index 1509035..d546748 100644 --- a/handler/router.go +++ b/handler/router.go @@ -111,7 +111,7 @@ func Convert(c *fiber.Ctx) error { // 新增:检查是否为WebP格式 if strings.ToLower(path.Ext(filename)) == ".webp" { - log.Infof("Original image is already in WebP format: %s", reqURI) + log.Infof("原始图像已经是WebP格式: %s", reqURI) var webpImagePath string if proxyMode { // 对于代理模式,确保文件已经被下载 @@ -138,7 +138,7 @@ func Convert(c *fiber.Ctx) error { // Rewrite the target backend if a mapping rule matches the hostname if hostMap, hostMapFound := config.Config.ImageMap[reqHost]; hostMapFound { - log.Debugf("Found host mapping %s -> %s", reqHostname, hostMap) + log.Debugf("找到host映射 %s -> %s", reqHostname, hostMap) targetHostUrl, _ := url.Parse(hostMap) targetHostName = targetHostUrl.Host targetHost = targetHostUrl.Scheme + "://" + targetHostUrl.Host @@ -148,7 +148,7 @@ func Convert(c *fiber.Ctx) error { httpRegexpMatcher := regexp.MustCompile(config.HttpRegexp) for uriMap, uriMapTarget := range config.Config.ImageMap { if strings.HasPrefix(reqURI, uriMap) { - log.Debugf("Found URI mapping %s -> %s", uriMap, uriMapTarget) + log.Debugf("找到 URI 映射 %s -> %s", uriMap, uriMapTarget) mapMode = true // if uriMapTarget we use the proxy mode to fetch the remote diff --git a/helper/metadata.go b/helper/metadata.go index fcdfcc9..5608ef1 100644 --- a/helper/metadata.go +++ b/helper/metadata.go @@ -40,7 +40,7 @@ func ReadMetadata(p, etag string, subdir string) config.MetaFile { } else { err = json.Unmarshal(buf, &metadata) if err != nil { - log.Warnf("unmarshal metadata error, possible corrupt file, re-building...: %s", err) + log.Warnf("解组元数据错误、可能损坏的文件、重建...: %s", err) WriteMetadata(p, etag, subdir) return ReadMetadata(p, etag, subdir) } @@ -75,6 +75,6 @@ func DeleteMetadata(p string, subdir string) { metadataPath := path.Join(config.Config.MetadataPath, subdir, id+".json") err := os.Remove(metadataPath) if err != nil { - log.Warnln("failed to delete metadata", err) + log.Warnln("删除元数据失败", err) } }