2024-04-10 22:10:09 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-12-23 00:07:44 -08:00
|
|
|
|
2024-04-10 22:10:09 +08:00
|
|
|
"nf-repo/internal/handler"
|
|
|
|
"nf-repo/internal/interfaces"
|
|
|
|
"nf-repo/internal/opt"
|
2024-12-23 00:07:44 -08:00
|
|
|
|
|
|
|
"github.com/loveuer/nf"
|
2024-04-10 22:10:09 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewApi(
|
|
|
|
ctx context.Context,
|
|
|
|
bh interfaces.BlobHandler,
|
|
|
|
uh interfaces.UploadHandler,
|
|
|
|
mh interfaces.ManifestHandler,
|
|
|
|
) *nf.App {
|
|
|
|
app := nf.New(nf.Config{BodyLimit: opt.DefaultMaxSize})
|
|
|
|
|
|
|
|
{
|
|
|
|
api := app.Group("/v2")
|
|
|
|
api.Any("/*path", handler.Root(bh, uh, mh))
|
|
|
|
}
|
|
|
|
|
2024-04-15 18:02:54 +08:00
|
|
|
{
|
2024-12-23 00:07:44 -08:00
|
|
|
api := app.Group("/_api/repo")
|
2024-04-15 18:02:54 +08:00
|
|
|
api.Get("/settings", handler.RepoSettings)
|
|
|
|
api.Get("/list", handler.RepoList(mh))
|
|
|
|
api.Get("/tag/list", handler.TagList(mh))
|
|
|
|
api.Post("/proxy", handler.ProxyDownloadImage(mh, bh))
|
|
|
|
}
|
|
|
|
|
2024-12-23 00:07:44 -08:00
|
|
|
// app.Use(front.NewFront(&front.DefaultFront, "dist/front/browser"))
|
2024-05-05 19:11:57 +08:00
|
|
|
|
2024-04-10 22:10:09 +08:00
|
|
|
return app
|
|
|
|
}
|