commit 990963cd70582800712b994fee390eed116d1613 Author: Jack Date: Wed Dec 17 00:42:01 2025 +0800 ++ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf7c11e --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +.DS_Store +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +.idea/* +xml_files/ + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +other/split_clash_config/split_config +ai_news/save_data +daily/*.txt diff --git a/api/hd4k-downloader.api b/api/hd4k-downloader.api new file mode 100644 index 0000000..d37ba63 --- /dev/null +++ b/api/hd4k-downloader.api @@ -0,0 +1,48 @@ +syntax = "v1" + +info( + title: "HD4K漫画下载服务" + desc: "下载HD4K漫画图片的API服务" + author: "hd4k-downloader" + version: "v1.0.0" +) + +type ( + // 下载请求 + DownloadRequest { + Title string `json:"title"` + Imgs map[string]string `json:"imgs"` + } + + // 下载进度详情 + ProgressDetail { + Key string `json:"key"` + URL string `json:"url"` + Status string `json:"status"` + Message string `json:"message"` + SavedAs string `json:"saved_as,optional"` + } + + // 下载响应 + DownloadResponse { + Success bool `json:"success"` + Message string `json:"message"` + Title string `json:"title"` + Folder string `json:"folder"` + JsonPath string `json:"json_path"` + Total int `json:"total"` + Saved int `json:"saved"` + Skipped int `json:"skipped"` + Failed int `json:"failed"` + Details []ProgressDetail `json:"details"` + } +) + +@server( + middleware: Cors + timeout: 300000ms # 添加时间单位ms +) +service hd4k_downloader { + @handler SaveImages + post /api/save_imgs (DownloadRequest) returns (DownloadResponse) +} \ No newline at end of file diff --git a/etc/hd4kdownloader.yaml b/etc/hd4kdownloader.yaml new file mode 100644 index 0000000..dc3244e --- /dev/null +++ b/etc/hd4kdownloader.yaml @@ -0,0 +1,3 @@ +Name: hd4k_downloader +Host: 0.0.0.0 +Port: 8888 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a0cbb22 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module hd4k-downloader + +go 1.24.7 + +require github.com/zeromicro/go-zero v1.9.3 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fba81db --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/zeromicro/go-zero v1.9.3 h1:dJ568uUoRJY0RUxo4aH4htSglbEUF60WiM1MZVkTK9A= +github.com/zeromicro/go-zero v1.9.3/go.mod h1:JBAtfXQvErk+V7pxzcySR0mW6m2I4KPhNQZGASltDRQ= diff --git a/hd4kdownloader.go b/hd4kdownloader.go new file mode 100644 index 0000000..9c2830e --- /dev/null +++ b/hd4kdownloader.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package main + +import ( + "flag" + "fmt" + + "hd4k-downloader/internal/config" + "hd4k-downloader/internal/handler" + "hd4k-downloader/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/rest" +) + +var configFile = flag.String("f", "etc/hd4kdownloader.yaml", "the config file") + +func main() { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c) + + server := rest.MustNewServer(c.RestConf) + defer server.Stop() + + ctx := svc.NewServiceContext(c) + handler.RegisterHandlers(server, ctx) + + fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) + server.Start() +} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..9b36470 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,10 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package config + +import "github.com/zeromicro/go-zero/rest" + +type Config struct { + rest.RestConf +} diff --git a/internal/svc/servicecontext.go b/internal/svc/servicecontext.go new file mode 100644 index 0000000..4719384 --- /dev/null +++ b/internal/svc/servicecontext.go @@ -0,0 +1,22 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package svc + +import ( + "github.com/zeromicro/go-zero/rest" + "hd4k-downloader/internal/config" + "hd4k-downloader/internal/middleware" +) + +type ServiceContext struct { + Config config.Config + Cors rest.Middleware +} + +func NewServiceContext(c config.Config) *ServiceContext { + return &ServiceContext{ + Config: c, + Cors: middleware.NewCorsMiddleware().Handle, + } +} diff --git a/internal/types/types.go b/internal/types/types.go new file mode 100644 index 0000000..3851bb0 --- /dev/null +++ b/internal/types/types.go @@ -0,0 +1,30 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 + +package types + +type DownloadRequest struct { + Title string `json:"title"` + Imgs map[string]string `json:"imgs"` +} + +type DownloadResponse struct { + Success bool `json:"success"` + Message string `json:"message"` + Title string `json:"title"` + Folder string `json:"folder"` + JsonPath string `json:"json_path"` + Total int `json:"total"` + Saved int `json:"saved"` + Skipped int `json:"skipped"` + Failed int `json:"failed"` + Details []ProgressDetail `json:"details"` +} + +type ProgressDetail struct { + Key string `json:"key"` + URL string `json:"url"` + Status string `json:"status"` + Message string `json:"message"` + SavedAs string `json:"saved_as,optional"` +}